DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16

Model Overview

  • Model Architecture: Qwen2ForCausalLM
    • Input: Text
    • Output: Text
  • Model Optimizations:
    • Weight quantization: INT4
  • Release Date: 2/4/2025
  • Version: 1.0
  • Model Developers: Neural Magic

Quantized version of DeepSeek-R1-Distill-Qwen-7B.

Model Optimizations

This model was obtained by quantizing the weights of DeepSeek-R1-Distill-Qwen-7B to INT4 data type. This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%.

Only the weights of the linear operators within transformers blocks are quantized. Weights are quantized using a symmetric per-group scheme, with group size 128. The GPTQ algorithm is applied for quantization, as implemented in the llm-compressor library.

Use with vLLM

This model can be deployed efficiently using the vLLM backend, as shown in the example below.

from transformers import AutoTokenizer
from vllm import LLM, SamplingParams

number_gpus = 1
model_name = "neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16"

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 also supports OpenAI-compatible serving. See the documentation for more details.

Creation

This model was created with llm-compressor by running the code snippet below.

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-7B"
model_name = model_stub.split("/")[-1]

num_samples = 2048
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 = QuantizationModifier(
    targets="Linear",
    scheme="W4A16",
    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.w4a16
model.save_pretrained(save_path)
tokenizer.save_pretrained(save_path)
print(f"Model and tokenizer saved to: {save_path}")

Evaluation

The model was evaluated on OpenLLM Leaderboard V1 and V2, using the following commands:

OpenLLM Leaderboard V1:

lm_eval \
  --model vllm \
  --model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16",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-7B-quantized.w4a16",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

Accuracy

Category Metric deepseek-ai/DeepSeek-R1-Distill-Qwen-7B neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 Recovery
OpenLLM V1 ARC-Challenge (Acc-Norm, 25-shot) 50.51 %
GSM8K (Strict-Match, 5-shot) 78.62 %
HellaSwag (Acc-Norm, 10-shot) 61.90 %
MMLU (Acc, 5-shot) 54.19 %
TruthfulQA (MC2, 0-shot) 45.55 %
Winogrande (Acc, 5-shot) 61.56 %
Average Score 58.72 %
OpenLLM V2 IFEval (Inst Level Strict Acc, 0-shot) 39.67 %
BBH (Acc-Norm, 3-shot) 39.60 %
Math-Hard (Exact-Match, 4-shot) 0.00 0.00 ---
GPQA (Acc-Norm, 0-shot) 25.24 %
MUSR (Acc-Norm, 0-shot) 38.09 %
MMLU-Pro (Acc, 5-shot) 19.53 %
Average Score 27.02 %
Coding HumanEval (pass@1) 40.80 48.50 118.9%
HumanEval (pass@10) 64.40 67.10 104.2%
HumanEval+ (pass@10) 38.50 45.00 116.9%
HumanEval+ (pass@10) 60.40 64.10 106.1%

Inference Performance

This model achieves up to 2.6x speedup in single-stream deployment and up to 1.5x speedup in multi-stream asynchronous deployment, depending on hardware and use-case scenario. The following performance benchmarks were conducted with vLLM version 0.7.2, and GuideLLM.

Benchmarking Command
guidellm --model neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 --target "http://localhost:8000/v1" --data-type emulated --data "prompt_tokens=<prompt_tokens>,generated_tokens=<generated_tokens>" --max seconds 360 --backend aiohttp_server

Single-stream performance (measured with vLLM version 0.7.2)

Instruction Following
256 / 128
Multi-turn Chat
512 / 256
Docstring Generation
768 / 128
RAG
1024 / 128
Code Completion
256 / 1024
Code Fixing
1024 / 1024
Large Summarization
4096 / 512
Large RAG
10240 / 1536
Hardware Model Average cost reduction Latency (s) QPD Latency (s) QPD Latency (s) QPD Latency (s) QPD Latency (s) QPD Latency (s) QPD Latency (s) QPD Latency (s) QPD
A6000x1 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --- 2.9 1576 5.7 788 2.9 1535 3.0 1496 22.6 199 23.2 194 12.1 370 38.5 117
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w8a8 1.56 1.8 2495 3.7 1223 1.9 2384 1.9 2393 14.3 315 14.8 304 7.9 572 25.3 178
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 2.41 1.1 4086 2.3 1998 1.2 3783 1.3 3527 8.6 526 8.8 512 5.2 860 22.7 198
A100x1 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --- 1.4 1389 2.9 691 1.5 1358 1.5 1329 11.5 175 11.6 174 6.2 326 21.5 93
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w8a8 1.28 1.1 1850 2.2 905 1.1 1807 1.1 1750 8.6 233 8.7 230 4.7 431 23.1 87
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 1.72 0.8 2575 1.5 1298 0.8 2461 0.8 2382 6.1 331 6.2 323 3.6 566 22.7 89
H100x1 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --- 0.9 1161 1.9 579 1.0 1138 1.0 1121 7.5 146 7.6 145 3.9 279 15.4 71
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-FP8-dynamic 1.34 0.7 1585 1.4 786 0.7 1577 0.7 1524 5.3 207 5.5 197 2.9 382 14.3 77
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 1.33 0.7 1590 1.4 793 0.7 1549 0.7 1509 5.4 201 5.5 198 2.9 381 14.0 78

**Use case profiles: prompt tokens / generation tokens

**QPD: Queries per dollar, based on on-demand cost at Lambda Labs (observed on 2/18/2025).

Multi-stream asynchronous performance (measured with vLLM version 0.7.2)

Instruction Following
256 / 128
Multi-turn Chat
512 / 256
Docstring Generation
768 / 128
RAG
1024 / 128
Code Completion
256 / 1024
Code Fixing
1024 / 1024
Large Summarization
4096 / 512
Large RAG
10240 / 1536
Hardware Model Average cost reduction Maximum throughput (QPS) QPD Maximum throughput (QPS) QPD Maximum throughput (QPS) QPD Maximum throughput (QPS) QPD Maximum throughput (QPS) QPD Maximum throughput (QPS) QPD Maximum throughput (QPS) QPD Maximum throughput (QPS) QPD
A6000x1 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --- 14.9 67138 7.1 32094 7.4 33096 5.9 26480 2.0 9004 1.5 6639 1.1 4938 0.3 1151
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w8a8 1.36 20.2 90956 8.8 39786 10.2 45963 8.1 36596 3.1 13968 2.1 9629 1.4 6374 0.3 1429
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 1.00 13.3 59681 6.1 27633 5.9 26689 4.7 20944 2.9 13108 1.9 8355 1.0 4362 0.3 1170
A100x1 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --- 26.4 53073 13.0 26213 14.5 29110 11.4 22936 4.4 8749 3.3 6680 2.3 4634 0.5 1105
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w8a8 1.27 34.3 69009 14.8 29791 19.0 38214 15.7 31598 5.6 11186 4.2 8350 3.0 6020 0.7 1328
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 0.93 23.9 47993 12.0 24194 12.5 25239 10.0 20029 4.5 9055 3.3 6681 2.1 4156 0.5 1043
H100x1 deepseek-ai/DeepSeek-R1-Distill-Qwen-7B --- 54.3 59410 26.0 28440 32.1 35154 26.7 29190 8.0 8700 6.6 7275 5.2 5669 1.2 1266
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-FP8-dynamic 1.16 62.9 68818 30.3 33196 39.4 43132 31.1 34073 9.2 10058 7.1 7748 6.1 6714 1.3 1415
neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16 1.02 56.2 61483 26.7 29243 32.5 35592 26.9 29461 8.3 9072 6.4 7027 5.2 5731 1.2 1291

**Use case profiles: prompt tokens / generation tokens

**QPS: Queries per second.

**QPD: Queries per dollar, based on on-demand cost at Lambda Labs (observed on 2/18/2025).

Downloads last month
834
Safetensors
Model size
1.96B params
Tensor type
BF16
·
I64
·
I32
·
Inference Providers NEW
This model is not currently available via any of the supported Inference Providers.

Model tree for neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16

Quantized
(111)
this model

Collection including neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w4a16