Views
No views yet
1from transformers import AutoTokenizer
2from vllm import LLM, SamplingParams
3
4number_gpus = 1
5model_name = "neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w8a8"
6
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8sampling_params = SamplingParams(temperature=0.6, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
9llm = LLM(model=model_name, tensor_parallel_size=number_gpus, trust_remote_code=True)
10
11messages_list = [
12 [{"role": "user", "content": "Who are you? Please respond in pirate speak!"}],
13]
14
15prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
16
17outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
18
19generated_text = [output.outputs[0].text for output in outputs]
20print(generated_text)1from transformers import AutoModelForCausalLM, AutoTokenizer
2from llmcompressor.modifiers.quantization import QuantizationModifier
3from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
4from llmcompressor.transformers import oneshot
5
6# Load model
7model_stub = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
8model_name = model_stub.split("/")[-1]
9
10num_samples = 1024
11max_seq_len = 8192
12
13tokenizer = AutoTokenizer.from_pretrained(model_stub)
14
15model = AutoModelForCausalLM.from_pretrained(
16 model_stub,
17 device_map="auto",
18 torch_dtype="auto",
19)
20
21def preprocess_fn(example):
22 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
23
24ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
25ds = ds.map(preprocess_fn)
26
27# Configure the quantization algorithm and scheme
28recipe = [
29 SmoothQuantModifier(smoothing_strength=0.7),
30 QuantizationModifier(
31 targets="Linear",
32 scheme="W8A8",
33 ignore=["lm_head"],
34 dampening_frac=0.1,
35 ),
36]
37
38# Apply quantization
39oneshot(
40 model=model,
41 dataset=ds,
42 recipe=recipe,
43 max_seq_length=max_seq_len,
44 num_calibration_samples=num_samples,
45)
46
47# Save to disk in compressed-tensors format
48save_path = model_name + "-quantized.w8a8
49model.save_pretrained(save_path)
50tokenizer.save_pretrained(save_path)
51print(f"Model and tokenizer saved to: {save_path}")lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-7B-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_configlm_eval \
--model vllm \
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Qwen-7B-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| Category | Metric | deepseek-ai/DeepSeek-R1-Distill-Qwen-7B | neuralmagic/DeepSeek-R1-Distill-Qwen-7B-quantized.w8a8 | Recovery |
|---|---|---|---|---|
| Reasoning | AIME 2024 (pass@1) | 53.17 | 55.19 | 103.8% |
| MATH-500 (pass@1) | 93.66 | 93 | 99.3% | |
| GPQA Diamond (pass@1) | 50.53 | 50.65 | 100.24% | |
| Average Score | 65.79 | 66.28 | 100.74% | |
| OpenLLM V1 | ARC-Challenge (Acc-Norm, 25-shot) | 50.51 | 50.51 | 100.0% |
| GSM8K (Strict-Match, 5-shot) | 78.62 | 79.83 | 101.5% | |
| HellaSwag (Acc-Norm, 10-shot) | 61.90 | 61.62 | 99.6% | |
| MMLU (Acc, 5-shot) | 54.19 | 53.76 | 99.2% | |
| TruthfulQA (MC2, 0-shot) | 45.55 | 46.14 | 101.3% | |
| Winogrande (Acc, 5-shot) | 61.56 | 60.54 | 98.33% | |
| Average Score | 58.72 | 58.73 | 100.0% | |
| OpenLLM V2 | IFEval (Inst Level Strict Acc, 0-shot) | 39.38 | 40.20 | 102.1% |
| BBH (Acc-Norm, 3-shot) | 6.97 | 6.10 | --- | |
| Math-Hard (Exact-Match, 4-shot) | 0.00 | 0.00 | --- | |
| GPQA (Acc-Norm, 0-shot) | 1.81 | 0.90 | --- | |
| MUSR (Acc-Norm, 0-shot) | 4.68 | 4.04 | --- | |
| MMLU-Pro (Acc, 5-shot) | 1.66 | 1.73 | --- | |
| Average Score | 9.08 | 8.83 | --- | |
| Coding | HumanEval (pass@1) | 40.80 | 39.50 | 96.8% |
| HumanEval (pass@10) | 64.40 | 62.10 | 96.4% | |
| HumanEval+ (pass@10) | 38.50 | 37.20 | 96.6% | |
| HumanEval+ (pass@10) | 60.40 | 59.30 | 98.2% |
guidellm --model neuralmagic/DeepSeek-R1-Distill-Qwen-7B-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| 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 |
| 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 |