模型介绍
内容详情
替代品
模型简介
基于DeepSeek-R1-Distill-Qwen-32B的量化模型,采用INT8量化技术优化权重和激活值,显著降低显存需求和提升推理速度。
模型特点
INT8量化
权重和激活值均采用INT8量化,减少约50%的GPU显存占用,提升矩阵乘法计算吞吐量约2倍。
高效推理
通过vLLM后端支持高效部署,优化大规模语言模型的推理性能。
高精度保持
量化后模型在多项基准测试中保持原始模型99%以上的准确率。
模型能力
文本生成
对话系统
代码生成
数学推理
使用案例
对话系统
智能客服
用于构建高效的智能客服系统,处理用户查询。
支持多轮对话,响应速度快。
代码生成
编程辅助
帮助开发者生成代码片段或解决编程问题。
在HumanEval基准测试中pass@1达到85.8%。
开源协议: mit
标签:
- deepseek
- int8
- vllm
- llmcompressor
基础模型: deepseek-ai/DeepSeek-R1-Distill-Qwen-32B
库名称: transformers
DeepSeek-R1-Distill-Qwen-32B-量化版.w8a8
模型概览
- 模型架构: Qwen2ForCausalLM
- 输入: 文本
- 输出: 文本
- 模型优化:
- 权重量化: INT8
- 激活值量化: INT8
- 发布日期: 2025年2月5日
- 版本: 1.0
- 模型开发团队: Neural Magic
DeepSeek-R1-Distill-Qwen-32B的量化版本。
模型优化
本模型通过对DeepSeek-R1-Distill-Qwen-32B的权重和激活值进行INT8量化获得。
该优化将权重和激活值的比特数从16位降至8位,可减少约50%的GPU显存占用,并将矩阵乘法计算吞吐量提升约2倍。权重量化还能将磁盘存储需求降低约50%。
仅对transformer块内线性运算的权重和激活值进行量化。权重采用逐通道对称量化方案,激活值采用逐令牌对称量化方案。量化过程使用GPTQ算法,通过llm-compressor库实现。
使用vLLM部署
该模型可通过vLLM后端高效部署,示例如下:
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
number_gpus = 1
model_name = "neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8"
tokenizer = AutoTokenizer.from_pretrained(model_name)
sampling_params = SamplingParams(temperature=0.6, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
llm = LLM(model=model_name, tensor_parallel_size=number_gpus, trust_remote_code=True)
messages_list = [
[{"role": "user", "content": "你是谁?请用海盗口吻回答!"}],
]
prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
generated_text = [output.outputs[0].text for output in outputs]
print(generated_text)
vLLM还支持OpenAI兼容的服务接口,详见文档。
创建过程
该模型通过运行以下代码片段使用llm-compressor创建:
from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
from llmcompressor.transformers import oneshot
# 加载模型
model_stub = "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
model_name = model_stub.split("/")[-1]
num_samples = 1024
max_seq_len = 8192
tokenizer = AutoTokenizer.from_pretrained(model_stub)
model = AutoModelForCausalLM.from_pretrained(
model_stub,
device_map="auto",
torch_dtype="auto",
)
def preprocess_fn(example):
return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
ds = ds.map(preprocess_fn)
# 配置量化算法和方案
recipe = [
SmoothQuantModifier(smoothing_strength=0.8),
QuantizationModifier(
targets="Linear",
scheme="W8A8",
ignore=["lm_head"],
dampening_frac=0.01,
),
]
# 应用量化
oneshot(
model=model,
dataset=ds,
recipe=recipe,
max_seq_length=max_seq_len,
num_calibration_samples=num_samples,
)
# 以压缩张量格式保存到磁盘
save_path = model_name + "-quantized.w8a8
model.save_pretrained(save_path)
tokenizer.save_pretrained(save_path)
print(f"模型和分词器已保存至: {save_path}")
评估
该模型在OpenLLM排行榜V1和V2上进行了评估,使用以下命令:
OpenLLM排行榜V1:
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
--tasks openllm \
--write_out \
--batch_size auto \
--output_path output_dir \
--show_config
OpenLLM排行榜V2:
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--write_out \
--batch_size auto \
--output_path output_dir \
--show_config