4-bit bitsandbytes NF4 (double quant) quantization of Qwen/Qwen2.5-1.5B-Instruct, produced with the open notebook LLM Quantization: A Practical, Hands-On Reference.
| FP16 (original) | This model | |
|---|---|---|
| Size (MB) | 2944.4 | 1070.2 (0.36x) |
| Perplexity, Wikitext-2 (lower is better) | 11.931 | 13.066 (+9.5%) |
| Generation speed (tokens/s, T4, batch 1) | 5.9 | 8.6 |
Measured on a free Colab T4 using 40 windows of 512 tokens. Perplexity is only a proxy for quality, so please test on your own task.
Requires pip install -U bitsandbytes accelerate transformers and an NVIDIA GPU.
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("Youssefx64/Qwen2.5-1.5B-Instruct-bnb-NF4")
model = AutoModelForCausalLM.from_pretrained("Youssefx64/Qwen2.5-1.5B-Instruct-bnb-NF4", device_map="auto")
msgs = [{"role": "user", "content": "Explain quantization in one paragraph."}]
text = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
inputs = tok(text, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=200)
print(tok.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
Qwen/Qwen2.5-1.5B-Instruct