Views
No views yet
1from transformers import AutoTokenizer
2from vllm import LLM, SamplingParams
3
4number_gpus = 1
5model_name = "neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16"
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
5from llmcompressor.transformers.compression.helpers import calculate_offload_device_map
6
7# Load model
8model_stub = "deepseek-ai/DeepSeek-R1-Distill-Llama-70B"
9model_name = model_stub.split("/")[-1]
10
11num_samples = 3072
12max_seq_len = 8192
13
14tokenizer = AutoTokenizer.from_pretrained(model_stub)
15
16device_map = calculate_offload_device_map(
17 model_stub,
18 reserve_for_hessians=True,
19 num_gpus=2,
20 torch_dtype="auto",
21)
22
23model = AutoModelForCausalLM.from_pretrained(
24 model_stub,
25 device_map=device_map,
26 torch_dtype="auto",
27)
28
29def preprocess_fn(example):
30 return {"text": tokenizer.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}
31
32ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
33ds = ds.map(preprocess_fn)
34
35# Configure the quantization algorithm and scheme
36recipe = QuantizationModifier(
37 targets="Linear",
38 scheme="W4A16",
39 ignore=["lm_head"],
40 dampening_frac=0.1,
41)
42
43# Apply quantization
44oneshot(
45 model=model,
46 dataset=ds,
47 recipe=recipe,
48 max_seq_length=max_seq_len,
49 num_calibration_samples=num_samples,
50)
51
52# Save to disk in compressed-tensors format
53save_path = model_name + "-quantized.w4a16
54model.save_pretrained(save_path)
55tokenizer.save_pretrained(save_path)
56print(f"Model and tokenizer saved to: {save_path}")lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Llama-70B-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_configlm_eval \
--model vllm \
--model_args pretrained="neuralmagic/DeepSeek-R1-Distill-Llama-70B-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| Category | Metric | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16 | Recovery |
|---|---|---|---|---|
| Reasoning | AIME 2024 (pass@1) | 67.83 | 65.61 | 96.73% |
| MATH-500 (pass@1) | 95.29 | 95.19 | 99.9% | |
| GPQA Diamond (pass@1) | 65.57 | 64.04 | 97.67% | |
| Average Score | 76.23 | 74.95 | 98.23% | |
| OpenLLM V1 | ARC-Challenge (Acc-Norm, 25-shot) | 63.65 | 63.31 | 99.5% |
| GSM8K (Strict-Match, 5-shot) | 93.03 | 93.03 | 100.0% | |
| HellaSwag (Acc-Norm, 10-shot) | 84.85 | 84.43 | 99.5% | |
| MMLU (Acc, 5-shot) | 78.04 | 77.15 | 98.9% | |
| TruthfulQA (MC2, 0-shot) | 56.67 | 57.79 | 102.0% | |
| Winogrande (Acc, 5-shot) | 78.22 | 79.48 | 101.6% | |
| Average Score | 75.74 | 75.86 | 100.2% | |
| OpenLLM V2 | IFEval (Inst Level Strict Acc, 0-shot) | 42.45 | 42.41 | 99.9% |
| BBH (Acc-Norm, 3-shot) | 21.26 | 16.96 | 79.8% | |
| Math-Hard (Exact-Match, 4-shot) | 0.00 | 0.00 | --- | |
| GPQA (Acc-Norm, 0-shot) | 9.51 | 6.68 | --- | |
| MUSR (Acc-Norm, 0-shot) | 14.87 | 12.91 | --- | |
| MMLU-Pro (Acc, 5-shot) | 4.27 | 2.38 | --- | |
| Average Score | 15.39 | 13.56 | 88.1% | |
| Coding | HumanEval (pass@1) | 81.10 | 80.20 | 98.9% |
| HumanEval (pass@10) | 87.60 | 89.30 | 101.9% | |
| HumanEval+ (pass@10) | 75.20 | 73.00 | 97.1% | |
| HumanEval+ (pass@10) | 83.10 | 83.70 | 100.7% |
guidellm --model neuralmagic/DeepSeek-R1-Distill-Llama-70B-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| 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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GPU class | Number of GPUs | 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 |
| A6000 | 4 | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | --- | 7.4 | 152 | 14.9 | 76 | 7.5 | 149 | 7.7 | 146 | 57.2 | 20 | 58.9 | 19 | 31.9 | 35 | 98.4 | 11 |
| 2 | neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w8a8 | 1.93 | 7.7 | 292 | 15.2 | 148 | 7.8 | 287 | 8.0 | 282 | 60.7 | 37 | 60.2 | 37 | 32.3 | 70 | 104.0 | 22 | |
| 2 | neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16 | 2.83 | 4.9 | 457 | 10.0 | 225 | 5.5 | 411 | 5.8 | 389 | 38.9 | 58 | 39.2 | 57 | 23.7 | 95 | 76.6 | 29 | |
| A100 | 2 | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | --- | 6.4 | 157 | 12.8 | 79 | 6.6 | 153 | 6.7 | 151 | 50.4 | 20 | 50.8 | 20 | 27.0 | 37 | 85.4 | 12 |
| 2 | neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w8a8 | 1.48 | 4.1 | 245 | 8.2 | 123 | 4.2 | 238 | 4.3 | 235 | 32.4 | 31 | 32.8 | 31 | 17.6 | 57 | 90.8 | 11 | |
| 1 | neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16 | 2.69 | 4.6 | 440 | 9.2 | 220 | 4.9 | 407 | 5.2 | 389 | 35.3 | 57 | 36.3 | 55 | 21.2 | 95 | 68.1 | 30 | |
| H100 | 2 | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | --- | 3.8 | 149 | 7.6 | 74 | 3.9 | 146 | 3.9 | 144 | 30.0 | 19 | 30.4 | 19 | 16.1 | 35 | 56.5 | 10 |
| 2 | neuralmagic/DeepSeek-R1-Distill-Llama-70B-FP8-dynamic | 1.39 | 2.7 | 210 | 5.3 | 106 | 2.7 | 207 | 2.8 | 203 | 21.1 | 27 | 21.4 | 26 | 11.5 | 49 | 47.2 | 12 | |
| 1 | neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16 | 1.83 | 4.0 | 277 | 7.9 | 138 | 4.1 | 266 | 4.2 | 262 | 31.2 | 35 | 31.8 | 34 | 17.8 | 61 | 61.4 | 18 |
| 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 |
| A6000x4 | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | --- | 3.65 | 4102 | 1.56 | 1757 | 1.90 | 2143 | 1.48 | 1665 | 0.44 | 493 | 0.34 | 380 | 0.22 | 245 | 0.05 | 55 |
| neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w8a8 | 1.76 | 5.89 | 6625 | 2.94 | 3307 | 3.36 | 3775 | 2.59 | 2916 | 0.74 | 828 | 0.53 | 601 | 0.35 | 398 | 0.11 | 120 | |
| neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16 | 1.48 | 4.91 | 5528 | 2.01 | 2259 | 2.03 | 2280 | 1.12 | 1255 | 1.11 | 1251 | 0.76 | 852 | 0.24 | 267 | 0.07 | 81 | |
| A100x4 | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | --- | 10.41 | 5235 | 5.10 | 2565 | 5.50 | 2766 | 4.36 | 2193 | 1.49 | 751 | 1.21 | 607 | 0.89 | 447 | 0.19 | 98 |
| neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w8a8 | 1.63 | 18.11 | 9103 | 8.90 | 4477 | 9.41 | 4730 | 7.42 | 3731 | 2.44 | 1229 | 1.89 | 948 | 1.26 | 631 | 0.30 | 149 | |
| neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16 | 1.12 | 12.63 | 6353 | 5.32 | 2673 | 5.58 | 2804 | 4.27 | 2144 | 2.30 | 1158 | 1.45 | 729 | 0.76 | 381 | 0.22 | 110 | |
| H100x4 | deepseek-ai/DeepSeek-R1-Distill-Llama-70B | --- | 14.04 | 2113 | 10.85 | 1634 | 12.25 | 1844 | 9.93 | 1494 | 3.68 | 554 | 2.82 | 425 | 1.81 | 273 | 0.35 | 52 |
| neuralmagic/DeepSeek-R1-Distill-Llama-70B-FP8-dynamic | 1.78 | 41.44 | 6236 | 19.64 | 2956 | 21.03 | 3166 | 16.72 | 2516 | 6.01 | 904 | 4.46 | 672 | 2.55 | 383 | 0.49 | 74 | |
| neuralmagic/DeepSeek-R1-Distill-Llama-70B-quantized.w4a16 | 1.45 | 36.61 | 5509 | 15.12 | 2275 | 16.24 | 2443 | 13.22 | 1990 | 5.48 | 825 | 3.01 | 453 | 2.07 | 312 | 0.43 | 64 |