WHAT problem is being solved: floats are wasteful. Weight distributions in trained nets are roughly bell-shaped and clustered near 0; we don't need 16 bits to say "roughly 0.03."
What are the scale s and zero-point z in affine quantization?
q=round(x/s)+z; s sets the step size (real units per integer step), z is the integer that real-value 0 maps to.
Derive the quantization scale s.
Force xmin→qmin and xmax→qmax; subtract to cancel z: s=(xmax−xmin)/(qmax−qmin).
Symmetric quantization scale for weights?
s=max∣x∣/qmax, with z=0.
Why is INT4 much harder than INT8?
Only 16 levels vs 256, so the step s is ~16× larger → big rounding error; needs compensation (GPTQ/AWQ).
What does GPTQ minimize?
Layer output error ∥WX−W^X∥22, not raw weight error.
What is the Hessian in GPTQ and why?
H=2XX⊤; its inverse tells how to redistribute each rounding error into remaining weights to keep output unchanged.
PTQ vs QAT?
PTQ quantizes a trained model without training (GPTQ, AWQ); QAT simulates quantization during training for robustness.
Per-tensor vs per-group granularity?
Per-tensor: one scale for whole matrix (cheap, worse). Per-group: one scale per block (e.g. 128 weights) — standard for INT4, handles outliers.
Memory of a 7B model in FP16 / INT8 / INT4?
14 GB / 7 GB / ~3.5–4 GB.
Why must you clamp during quantization?
Outliers push q past the integer range; clamping to [qmin,qmax] prevents overflow.
Recall Explain to a 12-year-old (Feynman)
Imagine describing everyone's height using a ruler. FP16 is a ruler with a thousand tiny marks — super precise but bulky to carry. Quantization swaps it for a ruler with only 16 marks (INT4): lighter, but if you just snap each height to the nearest mark, some people get badly rounded. GPTQ is the clever teacher who, after rounding one kid's height up a bit, whispers to the next kids "stand a hair shorter" so that when you add the group up, the total is still right. The class fits in a small notebook, but the important totals are preserved.
Dekho, ek LLM ke weights normally FP16 (16-bit float) me store hote hain, jo bahut precise hai par memory bahut khata hai — 7B model ka matlab 14 GB sirf weights ke liye. Quantization ka idea simple hai: in floats ko chhote integers me convert kar do — INT8 (256 levels) ya INT4 (sirf 16 levels). Formula ka core hai q=round(x/s), jahan s "scale" hai yaani ek integer step kitne real units ka hai. Scale nikalne ke liye hum bas range [xmin,xmax] ko integer range pe map karte hain, aur do endpoint equations subtract karke s=(xmax−xmin)/(qmax−qmin) nikal aata hai.
INT8 me itne levels hain ki error almost zero rehta hai — bas simple round kar do, kaam ho gaya. Par INT4 me sirf 16 levels hain, to har weight ka rounding error bada ho jata hai (roughly 16 guna). Isliye INT4 me naive rounding se accuracy giR jati hai, aur yahin GPTQ kaam aata hai.
GPTQ ki trick genius hai: weights ko ek-ek karke quantize karo, aur jab ek weight ko grid pe snap karo to jo error aaya usko baaki bache huye weights me compensate kar do. Ye compensation Hessian H=2XX⊤ ke inverse ke through hota hai — matlab input correlations ke hisaab se error ko smartly distribute karta hai. Isse layer ka output almost same rehta hai, chahe har weight ab 4-bit integer ban gaya ho. Aur haan — GPTQ retraining nahi hai, ye sirf ek chhote calibration set (~128 samples) se closed-form solve karta hai, isliye fast hai.
Kyu important hai? Kyunki quantization ki wajah se hi ek bada model tumhare laptop/consumer GPU pe chal pata hai, aur inference bhi tez hota hai (kyunki inference memory-bandwidth bound hai, kam bytes = kam wait). QLoRA jaise techniques bhi isi 4-bit base pe fine-tuning karte hain. Short me: quantization = badे model ko chhota + tez banao, bina brain khoye.