Skip to content

Quantization для LLM

Коротко:

Quantization — техника compression модели через замену FP16/FP32 weights на меньшие precision (INT8, INT4, INT2). 70B LLM: FP16 = 140 GB RAM → INT4 = 35 GB (fits в single H100 80GB). Accuracy loss минимальный (1-3% perplexity) для INT4. Popular formats: GGUF (llama.cpp), GPTQ, AWQ, bitsandbytes. Enables inference на consumer GPUs (3090, 4090).

Ниже: подробности, пример, смежные термины, FAQ.

Попробовать бесплатно →

Подробности

  • Precision levels: FP16 (baseline) → INT8 (2x compression) → INT4 (4x) → INT2 (8x, experimental)
  • GGUF: Universal format для llama.cpp, работает на CPU + GPU
  • GPTQ: quantization с calibration dataset, лучший compression-quality tradeoff
  • AWQ (Activation-aware Weight Quantization) — latest, best accuracy при INT4
  • Tools: llama.cpp, vLLM, TGI (Text Generation Inference), transformers с bitsandbytes

Пример

# Ollama — run Llama 3 70B INT4 quantized
$ ollama pull llama3:70b  # ~40 GB INT4 GGUF
$ ollama run llama3:70b "Explain TCP"

# Python with transformers + bitsandbytes
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type='nf4')
model = AutoModelForCausalLM.from_pretrained('meta-llama/Llama-3-70B', quantization_config=config)

Смежные термины

Больше по теме

Часто задаваемые вопросы

Какой потеря accuracy?

INT8 — <1% perplexity. INT4 — 1-3% (acceptable). INT2 — 5-10% (noticeable).

INT4 GGUF — как работает?

Llama.cpp packs weights 4-bit per channel с scale factor. Dequantized on-the-fly в kernel. Minimal speed penalty при compute-bound.

Fine-tune quantized model?

QLoRA — да. Training finetunes LoRA adapters (FP16), base model остаётся INT4. 1-stop setup, cheapest fine-tuning.