Sari la conținut
aiqbenchInformații despre AI & calcul cuantic
ȘtiriAnalizeBenchmark-uriSkill-uriÎntreabă AIÎnvațăDespre
...Se încarcă sesiunea
ȘtiriAnalizeBenchmark-uriSkill-uriÎntreabă AIÎnvațăDespre

Română · beta. Traducerea a fost făcută automat și este încă în curs de revizuire. Citește pagina în engleză

  1. Joburile viitorului
  2. ›
  3. AI Inference & Efficiency Engineer
  4. ›
  5. Lecția 2 din 8

Lecțiile acestui traseu sunt publicate deocamdată doar în engleză, așa că lecția de mai jos apare în engleză. Restul — module, quiz și materiale — funcționează la fel.

Quantization: int8, int4 and When Quality Drops

Avansat¶ Citire · 5 min⚑ Misiune · 35 min◆ Test · 5 întrebări✓ Verificată la 23 nov. 2026

Vei putea să:

You can explain what a quantization scheme actually stores (scales, zero-points, group sizes), say why weight-only 4-bit helps decode but not prefill, compare round-to-nearest, GPTQ and AWQ in terms of what they calibrate, and describe how you would detect that a quantized model has lost quality before users do.

What quantization actually stores

A 16-bit model keeps every weight as a floating-point number with roughly three significant digits. Quantization replaces each weight with a small integer plus a shared scale (and sometimes a zero-point) that tells the kernel how to turn the integer back into a real value: w ≈ scale × (q − zero). The integers are what you store and stream; the scale is stored once per group of weights. An int4 weight with a 16-bit scale shared across a group of 128 therefore costs 4 + 16/128 ≈ 4.125 bits per weight, about one quarter of the original.

Everything else in the subject is about one question: how do you pick the integers and the scales so the model's outputs change as little as possible?

Why 4-bit weights speed up decode but not prefill

From module 1, decode time is set by bytes streamed per step. Weight-only quantization cuts those bytes by two to four times, so decode gets proportionally faster, with the kernel dequantizing on the fly inside the multiply. Prefill is compute-bound; the arithmetic is still done in 16-bit after dequantization, so weight-only schemes save memory there but little time. If you want prefill or large-batch speed-ups you need activations quantized too (W8A8 and similar), which is harder because activations have outliers that change from token to token. The LLM.int8() work from Dettmers and colleagues documented those outlier channels in models above a few billion parameters and handled them with mixed precision; it is the reason naïve 8-bit activation quantization was unreliable at scale.

Round-to-nearest, groups and outliers

The simplest scheme — round-to-nearest (RTN) with one absmax scale per row — breaks the moment a row contains an outlier. A single weight of 12 among values near ±1 forces the scale to 12/7 ≈ 1.7 at 4-bit, so every small weight collapses to 0 or ±1.7 and most of the information is gone. Two fixes are standard:

  • Group-wise scales: one scale per 32, 64 or 128 weights instead of per row. The outlier only damages its own group. Smaller groups mean better accuracy and slightly more bits per weight.
  • Keep outliers in higher precision or scale them away before quantizing.

Maarten Grootendorst's "A Visual Guide to Quantization" walks through symmetric versus asymmetric mappings and group sizes with pictures that make the error visible; read it before the two papers.

GPTQ and AWQ: calibrating against the real distribution

Both methods are post-training: no gradient updates to the model, only a few hundred calibration samples.

GPTQ quantizes a weight matrix one column at a time and, after rounding each column, adjusts the remaining unquantized columns to compensate for the error, using second-order (Hessian) information from the calibration activations. It is a direct descendant of Optimal Brain Surgeon. The result is a 3- or 4-bit model whose layer outputs stay close to the original's on data that resembles the calibration set.

AWQ starts from an observation: a small fraction of weight channels matter far more because they multiply large activations. Rather than keeping them in 16-bit, AWQ scales those channels up before quantizing (and scales the matching activations down) so rounding error on them shrinks. It needs only activation statistics, not a Hessian, and the resulting weights work with plain integer kernels, which is why AWQ models are easy to deploy.

Neither method is strictly better; results vary by model family and bit width (in the AWQ paper's own comparison AWQ matched or beat GPTQ on perplexity at 3 and 4 bits). AWQ is simpler, calibrates faster and generalises more robustly to text unlike the calibration set. Formats such as the llama.cpp "K-quants" (Q4_K_M, Q5_K_M) use their own mixed-precision layouts optimised for CPU and Apple-silicon kernels.

A numbered procedure for quantizing without regret

  1. Decide the target: memory fit, decode speed, or both. If prefill latency is the problem, weight-only int4 will disappoint you.
  2. Pick the scheme and group size. Start at 4-bit with 128-group or Q4_K_M; drop to 8-bit if quality is paramount and memory allows.
  3. Calibrate on data that looks like production traffic. Calibration on English Wikipedia and deployment on code or another language is a classic quiet failure.
  4. Measure quality on your own tasks, not only perplexity. Perplexity on a generic corpus can be flat while instruction following, long-context recall or maths degrade.
  5. Compare outputs side by side with the 16-bit model on a fixed prompt set. Look for repetition, broken formatting and refusals that were not there before.
  6. Record the exact recipe (scheme, group size, calibration set, library version) next to the artefact. Quantized checkpoints are not reproducible from memory.

What is still unsettled

Below 4 bits the picture is noisy: 2- and 3-bit methods exist and keep improving, but quality loss varies by model family and task, and small models suffer more than large ones at the same bit width. Whether quantizing the KV cache to 8 or 4 bits is safe for long-context reasoning is also model-dependent. Trained quantization-aware models (released natively in low precision) may make post-training schemes less important, but the evaluation discipline above does not change.

What to remember

  • Quantization stores integers plus scales; group size trades accuracy against bits per weight.
  • Weight-only int4 speeds decode (fewer bytes) but not prefill (still 16-bit compute); W8A8 helps compute-bound phases and is harder because of activation outliers.
  • GPTQ compensates rounding error column by column using calibration Hessians; AWQ rescales the channels that multiply large activations. Both need representative calibration data.
  • Judge a quantized model on your own tasks and a side-by-side prompt set, never on perplexity alone.

Materiale selectate

1.9h

Munca de profunzime se întâmplă aici — lecția este briefingul tău.

  • A Visual Guide to Quantization (Maarten Grootendorst)Tutorial· 35 min
  • GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers (Frantar et al.)Lucrare· 40 min
  • AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration (Lin et al., MIT)Lucrare· 40 min

În direct pe aiqbench

Subiectul acestei lecții în restul site-ului, astăzi.

În știri, ultimele 30 de zile

  • GPU decoder keeps pace with a superconducting qubit clock on a continuous stream, with NVIDIA NVQLink interconnectAlice & Bob · 1 dec.
  • DeepSeek Opens Source Production-Level Ascend Inference Code36Kr · 1 dec.
  • NVIDIA and Cerebras Partner to Accelerate AI Agent Inference with Two-Stage Compute Architecture36Kr · 1 dec.
Mai multe știri pe acest subiect →

Mergi mai departe

  • Care model merită?Preț, viteză și hardware alături de capabilitate.
  • Întreabă AI despre această lecțieDeschide Întreabă AI cu o întrebare despre această lecție, cu răspuns din arhiva de știri, cu surse.
  • Skill-uri de agent pentru această muncăSkill-uri gata făcute pentru agenți AI de programare, verificate și evaluate.

Testează-ți cunoștințele

5 întrebări în 100 de secunde, pe o pagină separată. Citește mai întâi tot ce este mai sus.

Testează-ți cunoștințele →

Misiunea modulului

30–40 min

Take sixteen made-up weights (write them yourself, including one outlier such as 12.0 among values between -1 and 1). Quantize them to 4-bit integers with a single absmax scale, then again with two groups of eight. Dequantize both and compute the mean absolute error for each. Write three sentences on why the outlier hurt the ungrouped version and what that implies for choosing group size in a real model.

Se încarcă lucrarea ta…

← Lecția anterioară1. Where the Cost Comes From: Prefill, Decode and the KV CacheLecția următoare →3. Serving at Scale: Continuous Batching and Paged Attention
aiqbench
Informații despre AI & calcul cuantic© aiqbench. Toate drepturile rezervate.

Fluxuri:RSS·JSON Feed

LimbăEnglish·Românăbeta
ȘtiriAI & tehnologieCuanticAnalize
ExploreazăBenchmark-uriÎnvață
CompanieDespreÎncredereInformații legaleTermeni și condițiiPolitica de confidențialitateNotificări privind drepturile de autorȘtergerea datelorRaportează conținut

Perspectiva aiqbench, analizele, rezumatul zilnic și răspunsurile din Întreabă sunt scrise de modele AI din sursele afișate, fără revizuire editorială înainte de publicare. Pot conține erori — verifică sursa. Cum este folosit modelul →

  • Știri
  • Analize
  • Întreabă
  • Topuri
  • Cont