Efficiency

Quantization: Compressing Models to Integers

Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.

status: publishedimportance: importantdifficulty 3/5math: undergraduateread: 16mlive demo
Editorial efficiency illustration of smooth weights snapped to discrete integer levels with quantization error cues.

Concept Structure

Quantization: Compressing Models to Integers

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
1next concepts
1related links

Learning map

Quantization: Compressing Models to Integers
BeforeEfficiency: Quantization, Distillation, LoRA & Sparse MoENow4/4 sections readyTryManipulate one control and predict the visible change.NextLong Context Engineering: RoPE Scaling, KV Compression & Memory Optimization

Object flow

4/4 sections readyAsk about thisResearch room
ConceptQuantization: Compressing Models to IntegersEfficiency
2 sources attachedLocal snapshot ready
concept:efficiency/quantization

Conceptual Bridge

What should feel connected as you move through this page.

Carry inEfficiency: Quantization, Distillation, LoRA & Sparse MoE

Bring the mental model from Efficiency: Quantization, Distillation, LoRA & Sparse MoE; this page will reuse it instead of restarting from zero.

Work hereQuantization: Compressing Models to Integers

Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.

Carry outLong Context Engineering: RoPE Scaling, KV Compression & Memory Optimization

The next edge should feel earned: use the demo prediction here before following Long Context Engineering: RoPE Scaling, KV Compression & Memory Optimization.

Test the linkManipulate one control and predict the visible change.Then continue to Long Context Engineering: RoPE Scaling, KV Compression & Memory Optimization
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Large models are often bottlenecked by memory bandwidth, not raw FLOPs. If memory bandwidth is the bottleneck, moving less data can improve throughput, though the actual speedup depends on kernels, hardware, batch size, and which tensors are quantized.

Quantization is the core trick: store weights (and sometimes activations) in low-bit integers like INT8 or INT4, with a scale factor that maps those integers back to approximate floating-point values.

A major enemy, especially in large LLM quantization, is outliers: a small number of large weights/activations can force a scale that wastes resolution for everything else.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Uniform quantization (per-tensor)

Given a tensor of weights with min/max values, choose one step size for the whole tensor and round onto integer levels:

Δ=wmaxwmin2b1,wq=clip ⁣(round ⁣(wwminΔ),0,2b1),w^=wqΔ+wmin.\Delta = \frac{w_{\max}-w_{\min}}{2^b-1},\qquad w_q=\mathrm{clip}\!\left(\mathrm{round}\!\left(\frac{w-w_{\min}}{\Delta}\right),0,2^b-1\right),\qquad \hat w=w_q\Delta+w_{\min}.

Here bb is the number of bits (8 for INT8, 4 for INT4).

Finer-grained scaling: per-channel / row-wise

Instead of one scale for the whole matrix, use one scale per output channel/row. For signed symmetric quantization:

qmax=2b11,si=maxjWi,jqmax,Qi,j=clip ⁣(round ⁣(Wi,jsi),qmax,qmax),W^i,j=siQi,j.q_{\max}=2^{b-1}-1,\qquad s_i=\frac{\max_j |W_{i,j}|}{q_{\max}},\qquad Q_{i,j}=\mathrm{clip}\!\left(\mathrm{round}\!\left(\frac{W_{i,j}}{s_i}\right),-q_{\max},q_{\max}\right),\qquad \hat W_{i,j}=s_iQ_{i,j}.

This usually improves quality because different channels have different dynamic ranges.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

rng = np.random.default_rng(0)
w = rng.normal(size=10000).astype(np.float32)

def quantize_uniform(w, bits=8):
    qmin, qmax = 0, 2**bits - 1
    wmin, wmax = float(w.min()), float(w.max())
    delta = (wmax - wmin) / (qmax - qmin)
    wq = np.clip(np.round((w - wmin) / delta), qmin, qmax).astype(np.int32)
    what = (wq * delta + wmin).astype(np.float32)
    return what, float(delta)

what8, d8 = quantize_uniform(w, bits=8)
what4, d4 = quantize_uniform(w, bits=4)

print("RMSE INT8:", round(float(np.sqrt(((w - what8) ** 2).mean())), 6), "delta:", round(d8, 6))
print("RMSE INT4:", round(float(np.sqrt(((w - what4) ** 2).mean())), 6), "delta:", round(d4, 6))
print("memory reduction: fp16->int8 ~2x, fp16->int4 ~4x (weight storage)")
04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

The demo below asks you to predict which scaling strategy survives an outlier before revealing the quantization error. The key invariant is that a single shared scale can waste most integer levels on one large value, while per-channel scales recover resolution for ordinary rows.

Live Concept Demo

Explore Quantization: Compressing Models to Integers

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Quantization: Compressing Models to Integers should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.

Prediction open01 / Intuition
Editorial efficiency illustration of smooth weights snapped to discrete integer levels with quantization error cues.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Quantization: Compressing Models to Integers should make visible.

Visual Inquiry

Make the image answer a mathematical question

Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Quantization: Compressing Models to Integers easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

paper · 2022LLM.int8(): 8-bit Matrix Multiplication for Transformers at ScaleDettmers et al.

Grounds transformer-scale INT8 inference, vector-wise normalization, and mixed-precision handling of emergent outlier feature dimensions.

Open source
paper · 2022GPTQ: Accurate Post-Training Quantization for Generative Pre-trained TransformersFrantar et al.

Grounds GPT-style post-training weight quantization using approximate second-order information and error-compensating updates.

Open source

Claim Review

Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources2 references

dettmers-2022-llm-int8, frantar-2022-gptq

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedQuantization maps floating tensors to low-bit integer levels with scales/dequantization rules, reducing storage/bandwidth but adding reconstruction error; if an outlier sets one shared scale, ordinary values lose resolution, so finer-grained scales or outlier-aware handling can preserve accuracy.Claim metadata: source checked

Dettmers et al. show transformer-scale 8-bit inference needs separate normalization constants and mixed-precision handling for emergent outlier features. Frantar et al. ground GPT-style post-training weight quantization with approximate second-order/error compensation. The page math, code, and demo instantiate scale quantize/dequantize, memory savings, and outlier-driven per-tensor vs per-channel RMSE.

Sources: LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale, GPTQ: Accurate Post-Training Quantization for Generative Pre-trained TransformersChecks the page's finite uniform-quantization and scale/outlier lesson only; it does not claim a full GPTQ solver, exact LLM.int8 routing, calibrated model accuracy, hardware speedups, activation quantization coverage, or all low-bit methods.A bounded review summary is present; still check caveats and exact source scope.

Oracle PASS: Dettmers supports Int8 scaling/dequantization, single-scale outlier precision loss, vector-wise constants, and mixed-precision outlier handling; Frantar supports low-bit GPT weight quantization as compression with reconstruction-error control and reduced memory movement. Scope excludes full GPTQ, exact LLM.int8 routing, calibrated accuracy, speedup, activation coverage, and all low-bit methods.

Reviewer: codex+oracle; reviewed 2026-05-07

Practice Loop

Try the idea before it explains itself

Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Quantization: Compressing Models to Integers.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptQuantization: Compressing Models to IntegersEfficiency

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptEfficiency

Quantization: Compressing Models to Integers

Anchored question

What is the smallest example that makes Quantization: Compressing Models to Integers click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:efficiency/quantization.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: dettmers-2022-llm-int8, frantar-2022-gptq
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Quantization: Compressing Models to Integers Object key: concept:efficiency/quantization Context: Efficiency Anchor id: concept/concept-notebook/efficiency/quantization Open question: What is the smallest example that makes Quantization: Compressing Models to Integers click without losing the math? Evidence to inspect: - Source ids to inspect: dettmers-2022-llm-int8, frantar-2022-gptq - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/efficiency/quantization concept:efficiency/quantization