--- license: mit tags: - deepseek - int8 - vllm - llmcompressor base_model: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B library_name: transformers --- # DeepSeek-R1-Distill-Qwen-7B-quantized.w8a8 ## Model Overview - **Model Architecture:** Qwen2ForCausalLM - **Input:** Text - **Output:** Text - **Model Optimizations:** - **Weight quantization:** INT8 - **Activation quantization:** INT8 - **Release Date:** 2/5/2025 - **Version:** 1.0 - **Model Developers:** Neural Magic Quantized version of [DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B). ### Model Optimizations This model was obtained by quantizing the weights and activations of [DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B) to INT8 data type. This optimization reduces the number of bits used to represent weights and activations from 16 to 8, reducing GPU memory requirements (by approximately 50%) and increasing matrix-multiply compute throughput (by approximately 2x). Weight quantization also reduces disk size requirements by approximately 50%. Only the weights and activations of the linear operators within transformers blocks are quantized. Weights are quantized using a symmetric per-channel scheme, whereas quantizations are quantized using a symmetric per-token scheme. The [GPTQ](https://arxiv.org/abs/2210.17323) algorithm is applied for quantization, as implemented in the [llm-compressor](https://github.com/vllm-project/llm-compressor) library. ## Use with vLLM This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below. ```python from transformers import AutoTokenizer from vllm import LLM, SamplingParams number_gpus = 1 model_name = "neuralmagic/DeepSeek-R1-Distill-Qwen-7B-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 also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details. ## Creation This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below. ```python 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 = 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.7), QuantizationModifier( targets="Linear", scheme="W8A8", ignore=["lm_head"], dampening_frac=0.1, ), ] # 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}") ``` ## Evaluation The model was evaluated on OpenLLM Leaderboard [V1](https://huggingface.co/spaces/open-llm-leaderboard-old/open_llm_leaderboard) and [V2](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard#/), using the following commands: OpenLLM Leaderboard V1: ``` 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_config ``` OpenLLM Leaderboard V2: ``` 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 \ --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.w8a8 Recovery
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.67 39.07 98.5%
BBH (Acc-Norm, 3-shot) 39.60 39.57 99.9%
Math-Hard (Exact-Match, 4-shot) 0.00 0.00 ---
GPQA (Acc-Norm, 0-shot) 25.24 27.28 108.1%
MUSR (Acc-Norm, 0-shot) 38.09 34.50 90.6%
MMLU-Pro (Acc, 5-shot) 19.53 20.60 105.5%
Average Score 27.02 26.84 99.3%
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%