DeepSeek-R1-Distill-Llama-8B-quantized.w4a16

Model Overview

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

Quantized version of DeepSeek-R1-Distill-Llama-8B.

Model Optimizations

This model was obtained by quantizing the weights of DeepSeek-R1-Distill-Llama-8B 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-Llama-8B-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-Llama-8B"
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 = QuantizationModifier(
    targets="Linear",
    scheme="W4A16",
    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.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-Llama-8B-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-Llama-8B-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-Llama-8B neuralmagic/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16 Recovery
OpenLLM V1 ARC-Challenge (Acc-Norm, 25-shot) 45.05 42.92 95.3%
GSM8K (Strict-Match, 5-shot) 62.77 63.08 100.5%
HellaSwag (Acc-Norm, 10-shot) 76.78 74.62 97.2%
MMLU (Acc, 5-shot) 55.65 52.11 93.6%
TruthfulQA (MC2, 0-shot) 50.55 48.57 96.1%
Winogrande (Acc, 5-shot) 68.51 68.43 99.9%
Average Score 59.88 58.29 97.3%
OpenLLM V2 IFEval (Inst Level Strict Acc, 0-shot) 38.34 37.85 98.7%
BBH (Acc-Norm, 3-shot) 38.19 38.19 100.0%
Math-Hard (Exact-Match, 4-shot) 0.00 0.00 ---
GPQA (Acc-Norm, 0-shot) 28.87 24.15 83.7%
MUSR (Acc-Norm, 0-shot) 33.31 34.63 104.0%
MMLU-Pro (Acc, 5-shot) 20.10 19.78 98.4%
Average Score 26.47 25.77 97.4%
Coding HumanEval (pass@1) 49.90 49.40 99.0%
HumanEval (pass@10) 68.90 69.30 100.6%
HumanEval+ (pass@10) 44.10 45.00 102.0%
HumanEval+ (pass@10) 62.90 63.40 100.8%
Downloads last month
393
Safetensors
Model size
1.98B 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-Llama-8B-quantized.w4a16

Quantized
(113)
this model

Collection including neuralmagic/DeepSeek-R1-Distill-Llama-8B-quantized.w4a16