8-bit bitsandbytes INT8 (LLM.int8) 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 | 1694.9 (0.58x) |
| Perplexity, Wikitext-2 (lower is better) | 11.931 | 12.015 (+0.7%) |
| Generation speed (tokens/s, T4, batch 1) | 5.9 | 3.1 |
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-INT8")
model = AutoModelForCausalLM.from_pretrained("Youssefx64/Qwen2.5-1.5B-Instruct-bnb-INT8", 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