模型简介
模型特点
模型能力
使用案例
🚀 DeepSeek-R1-Distill-Qwen-32B量化模型(w8a8)
本项目是 DeepSeek-R1-Distill-Qwen-32B 的量化版本,通过将权重和激活值量化为INT8数据类型,显著降低了GPU内存需求,提升了计算吞吐量。
🚀 快速开始
使用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": "Who are you? Please respond in pirate speak!"}],
]
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兼容的服务,更多详情请参阅 文档。
✨ 主要特性
- 模型架构:采用Qwen2ForCausalLM架构,输入和输出均为文本。
- 模型优化:将权重和激活值量化为INT8数据类型,减少GPU内存需求约50%,提高矩阵乘法计算吞吐量约2倍,同时磁盘空间需求也减少约50%。
- 推理性能:单流部署时最高可达1.8倍加速,多流异步部署时最高可达2.2倍加速。
📦 安装指南
文档未提及具体安装步骤,可参考相关依赖库(如 transformers
、vLLM
、llm-compressor
等)的官方文档进行安装。
💻 使用示例
基础用法
使用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": "Who are you? Please respond in pirate speak!"}],
]
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)
高级用法
使用 llm-compressor
创建模型的代码示例:
from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
from llmcompressor.transformers import oneshot
# Load model
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)
# Configure the quantization algorithm and scheme
recipe = [
SmoothQuantModifier(smoothing_strength=0.8),
QuantizationModifier(
targets="Linear",
scheme="W8A8",
ignore=["lm_head"],
dampening_frac=0.01,
),
]
# Apply quantization
oneshot(
model=model,
dataset=ds,
recipe=recipe,
max_seq_length=max_seq_len,
num_calibration_samples=num_samples,
)
# Save to disk in compressed-tensors format
save_path = model_name + "-quantized.w8a8"
model.save_pretrained(save_path)
tokenizer.save_pretrained(save_path)
print(f"Model and tokenizer saved to: {save_path}")
📚 详细文档
模型评估
本模型在OpenLLM排行榜 V1 和 V2 上进行了评估,评估命令如下:
OpenLLM Leaderboard 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 Leaderboard 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
评估结果
类别 | 指标 | deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8 | 恢复率 |
---|---|---|---|---|
推理能力 | AIME 2024 (pass@1) | 69.75 | 68.17 | 97.73% |
MATH-500 (pass@1) | 95.09 | 94.98 | 99.88% | |
GPQA Diamond (pass@1) | 64.05 | 64.75 | 101.09% | |
平均得分 | 76.3 | 75.97 | 99.57% | |
OpenLLM V1 | ARC-Challenge (Acc-Norm, 25-shot) | 64.59 | 64.08 | 99.2% |
GSM8K (Strict-Match, 5-shot) | 82.71 | 83.85 | 101.4% | |
HellaSwag (Acc-Norm, 10-shot) | 83.80 | 83.66 | 99.8% | |
MMLU (Acc, 5-shot) | 81.12 | 80.94 | 99.8% | |
TruthfulQA (MC2, 0-shot) | 58.41 | 58.47 | 100.1% | |
Winogrande (Acc, 5-shot) | 76.40 | 76.01 | 99.5% | |
平均得分 | 74.51 | 74.50 | 100.0% | |
OpenLLM V2 | IFEval (Inst Level Strict Acc, 0-shot) | 42.87 | 41.92 | 97.8% |
BBH (Acc-Norm, 3-shot) | 57.96 | 58.20 | 100.4% | |
Math-Hard (Exact-Match, 4-shot) | 0.00 | 0.00 | --- | |
GPQA (Acc-Norm, 0-shot) | 26.95 | 28.80 | 106.9% | |
MUSR (Acc-Norm, 0-shot) | 43.95 | 43.95 | 100.0% | |
MMLU-Pro (Acc, 5-shot) | 49.82 | 49.14 | 98.6% | |
平均得分 | 36.92 | 37.00 | 100.2% | |
编码能力 | HumanEval (pass@1) | 86.00 | 85.80 | 99.8% |
HumanEval (pass@10) | 92.50 | 93.00 | 100.5% | |
HumanEval+ (pass@10) | 82.00 | 81.80 | 99.8% | |
HumanEval+ (pass@10) | 88.70 | 89.40 | 100.8% |
推理性能
本模型在不同硬件和使用场景下的推理性能如下:
单流性能(使用vLLM版本0.7.2测量)
| GPU类型 | GPU数量 | 模型 | 平均成本降低 | 指令跟随
256 / 128
延迟 (s) | 指令跟随
256 / 128
QPD | 多轮对话
512 / 256
延迟 (s) | 多轮对话
512 / 256
QPD | 文档字符串生成
768 / 128
延迟 (s) | 文档字符串生成
768 / 128
QPD | RAG
1024 / 128
延迟 (s) | RAG
1024 / 128
QPD | 代码补全
256 / 1024
延迟 (s) | 代码补全
256 / 1024
QPD | 代码修复
1024 / 1024
延迟 (s) | 代码修复
1024 / 1024
QPD | 大摘要
4096 / 512
延迟 (s) | 大摘要
4096 / 512
QPD | 大RAG
10240 / 1536
延迟 (s) | 大RAG
10240 / 1536
QPD |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| A6000 | 2 | deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | --- | 6.3 | 359 | 12.8 | 176 | 6.5 | 347 | 6.6 | 342 | 49.9 | 45 | 50.8 | 44 | 26.6 | 85 | 83.4 | 27 |
| | 1 | neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8 | 1.81 | 6.9 | 648 | 13.8 | 325 | 7.2 | 629 | 7.2 | 622 | 54.8 | 82 | 55.6 | 81 | 30.0 | 150 | 94.8 | 47 |
| | 1 | neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w4a16 | 3.07 | 3.9 | 1168 | 7.8 | 580 | 4.3 | 1041 | 4.6 | 975 | 29.7 | 151 | 30.9 | 146 | 19.3 | 233 | 61.4 | 73 |
| A100 | 1 | deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | --- | 5.6 | 361 | 11.1 | 180 | 5.7 | 350 | 5.8 | 347 | 44.0 | 46 | 44.7 | 45 | 23.6 | 85 | 73.7 | 27 |
| | 1 | neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8 | 1.50 | 3.7 | 547 | 7.3 | 275 | 3.8 | 536 | 3.8 | 528 | 29.0 | 69 | 29.5 | 68 | 15.7 | 128 | 53.1 | 38 |
| | 1 | neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w4a16 | 2.30 | 2.2 | 894 | 4.5 | 449 | 2.4 | 831 | 2.5 | 798 | 17.4 | 116 | 18.0 | 112 | 10.5 | 191 | 49.5 | 41 |
| H100 | 1 | deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | --- | 3.3 | 327 | 6.7 | 163 | 3.4 | 320 | 3.4 | 317 | 26.6 | 41 | 26.9 | 41 | 14.3 | 77 | 47.8 | 23 |
| | 1 | neuralmagic/DeepSeek-R1-Distill-Qwen-32B-FP8-dynamic | 1.52 | 2.2 | 503 | 4.3 | 252 | 2.2 | 490 | 2.3 | 485 | 17.3 | 63 | 17.5 | 63 | 9.5 | 116 | 33.4 | 33 |
| | 1 | neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w4a16 | 1.61 | 2.1 | 532 | 4.1 | 268 | 2.1 | 516 | 2.1 | 513 | 16.1 | 68 | 16.5 | 66 | 9.1 | 120 | 31.9 | 34 |
多流异步性能(使用vLLM版本0.7.2测量)
硬件 | 模型 | 平均成本降低 | 指令跟随 256 / 128 最大吞吐量 (QPS) |
指令跟随 256 / 128 QPD |
多轮对话 512 / 256 最大吞吐量 (QPS) |
多轮对话 512 / 256 QPD |
文档字符串生成 768 / 128 最大吞吐量 (QPS) |
文档字符串生成 768 / 128 QPD |
RAG 1024 / 128 最大吞吐量 (QPS) |
RAG 1024 / 128 QPD |
代码补全 256 / 1024 最大吞吐量 (QPS) |
代码补全 256 / 1024 QPD |
代码修复 1024 / 1024 最大吞吐量 (QPS) |
代码修复 1024 / 1024 QPD |
大摘要 4096 / 512 最大吞吐量 (QPS) |
大摘要 4096 / 512 QPD |
大RAG 10240 / 1536 最大吞吐量 (QPS) |
大RAG 10240 / 1536 QPD |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A6000x2 | deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | --- | 6.2 | 13940 | 1.9 | 4348 | 2.7 | 6153 | 2.1 | 4778 | 0.6 | 1382 | 0.4 | 930 | 0.3 | 685 | 0.1 | 124 |
neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8 | 1.80 | 8.7 | 19492 | 4.2 | 9474 | 4.1 | 9290 | 3.0 | 6802 | 1.2 | 2734 | 0.9 | 1962 | 0.5 | 1177 | 0.1 | 254 | |
neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w4a16 | 1.30 | 5.9 | 13366 | 2.5 | 5733 | 2.4 | 5409 | 1.6 | 3525 | 1.2 | 2757 | 0.7 | 1663 | 0.3 | 676 | 0.1 | 214 | |
A100x2 | deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | --- | 12.9 | 13016 | 5.8 | 5848 | 6.3 | 6348 | 5.1 | 5146 | 2.0 | 1988 | 1.5 | 1463 | 0.9 | 869 | 0.2 | 192 |
neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8 | 1.52 | 21.4 | 21479 | 8.9 | 8948 | 10.6 | 10611 | 8.2 | 8197 | 3.0 | 3018 | 2.0 | 2054 | 1.2 | 1241 | 0.3 | 264 | |
neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w4a16 | 1.09 | 13.5 | 13568 | 6.5 | 6509 | 6.0 | 6075 | 4.7 | 4754 | 2.8 | 2790 | 1.6 | 1651 | 0.9 | 862 | 0.2 | 225 | |
H100x2 | deepseek-ai/DeepSeek-R1-Distill-Qwen-32B | --- | 25.5 | 14392 | 12.5 | 7035 | 14.0 | 7877 | 11.3 | 6364 | 3.6 | 2041 | 2.7 | 1549 | 1.9 | 1057 | 0.4 | 200 |
neuralmagic/DeepSeek-R1-Distill-Qwen-32B-FP8-dynamic | 1.46 | 46.7 | 25538 | 20.3 | 11082 | 23.3 | 12728 | 18.4 | 10049 | 5.3 | 2881 | 3.7 | 2097 | 2.6 | 1445 | 0.5 | 256 | |
neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w4a16 | 1.23 | 36.9 | 20172 | 17.4 | 9500 | 18.0 | 9822 | 14.2 | 7755 | 5.3 | 2900 | 3.3 | 1867 | 2.3 | 1265 | 0.4 | 241 |
使用场景配置文件:提示词令牌 / 生成令牌
QPS:每秒查询次数
QPD:每美元查询次数,基于 Lambda Labs 的按需成本(2025年2月18日观测)
🔧 技术细节
量化方案
仅对Transformer块内线性算子的权重和激活值进行量化。权重采用对称的逐通道量化方案,激活值采用对称的逐令牌量化方案。量化算法使用 GPTQ 算法,具体实现基于 llm-compressor 库。
基准测试命令
guidellm --model neuralmagic/DeepSeek-R1-Distill-Qwen-32B-quantized.w8a8 --target "http://localhost:8000/v1" --data-type emulated --data "prompt_tokens=<prompt_tokens>,generated_tokens=<generated_tokens>" --max seconds 360 --backend aiohttp_server
📄 许可证
本项目采用MIT许可证。



