Beginner’s interactive guide

Why AI Models Feel Heavy—and How Engineers Make Them Fast

Every word an AI chatbot writes triggers billions of numbers moving across microscopic wires. Explore how quantization, caching, and smart batching shrink giant models onto everyday hardware.

70B model in FP16
140 GB
Just to hold the model’s weights—before a single user types a prompt.
Naive GPU utilization
20–30%
Compute cores sit idle waiting for weights to travel from memory.
Continuous batching
2–10×
More requests served per second on the exact same GPU hardware.
Part 1 · The real slowdown

AI inference isn’t a math problem—it’s a traffic jam

Modern GPUs can multiply billions of numbers in a blink. The catch is getting those numbers out of memory fast enough.

When you ask an AI model a question, the model doesn’t look up an answer in a database. Instead, its knowledge lives inside billions of stored decimal numbers called parameters (or weights). A “70B” model stores 70 billion of them.

Generating a reply happens in two very different phases. First, during the prompt phase, the GPU reads your entire question at once in parallel—that part is fast and keeps the math engines busy. Next, during the generation phase, the model writes its reply one word-piece (token) at a time. To pick each new token, the GPU has to haul all 70 billion weights from its main memory bank (High-Bandwidth Memory, or HBM) into its tiny arithmetic cores, use each weight once, and repeat the whole trip for the next token.

Think of a lightning-fast chef standing at a tiny prep counter while the recipe encyclopedia sits in a warehouse down the hall. The chef isn’t slow at chopping—the runner carrying giant binders back and forth down the hallway is the bottleneck. Because GPUs spend most of token generation waiting on memory transfers rather than doing arithmetic, adding faster math chips barely helps, and naive deployments often leave 70–80% of the GPU’s compute sitting idle.

Interactive Explorer: Will It Fit on One GPU?

Adjust the model size, number precision, and simultaneous users to see how GPU memory fills up—and how much of each token’s generation time is spent waiting on the memory highway.

Model size (parameters)
Weight precision
Target GPU card
Total GPU memory required
38.4 GB
Fits on 1× 40 GB GPU
1 GPU: 40 GB
Model weights: 26.0 GB Conversation KV cache: 10.4 GB Scratchpad activations: 2.0 GB
Time spent per generated token: Memory transfer vs. Math Baseline FP16 trip
Waiting for weights over memory highway: 92% Actual GPU arithmetic: 8%
Bytes moved per token
26.0 GB
Estimated GPUs needed
1 GPU
Relative token speed
1.0×
Real-world benchmark reference: A100 40GB serving a 13B model
In production measurements on an NVIDIA A100 (40 GB), a 13B model in FP16 uses about 26 GB (65%) permanently for model weights, roughly 12 GB (over 30%) for the dynamic KV cache across active requests, and a small sliver for ephemeral activations. At 175B parameters (GPT-3 scale), weights alone consume 346 GB across eight 80 GB GPUs.
Part 2 · Shrinking the numbers

Quantization: trading unneeded decimal places for speed

Instead of storing every weight with 32-bit scientific precision, quantization rounds numbers into compact integers—cutting memory and highway traffic by 2× to 8×.

Normally, neural networks are trained using FP32 (32-bit floating-point) or FP16 (16-bit) numbers—formats capable of expressing tiny fractions like 0.00048193. That extra precision helps during training when weights nudge by microscopic amounts. During everyday chat, however, all that decimal detail is largely overkill.

Quantization translates those sprawling decimals onto a short integer ruler—like INT8 (256 discrete steps from −128 to 127) or INT4 (just 16 steps). Fewer bits per weight means two huge wins at once: the model takes far less VRAM to store, and the memory runner hauls half or a quarter as many bytes per token.

Analogy 1 · Everyday math

Rounding dollar receipts

Suppose your grocery receipt lists $19.94, $4.07, and $11.98. Rounding to $20, $4, and $12 drops exact cents, yet the total is $36.00 instead of $35.99—fast mental math, virtually zero error.

Exact: $35.99 → Rounded: $36.00 (0.03% diff)
Analogy 2 · Visual media

JPEG image compression

A raw camera file records millions of ultra-subtle color differences your eyes barely notice. Compressing it replaces similar shades with a smaller palette—shrinking file size 4× while keeping the photo sharp.

Raw 32-bit → Compressed 8-bit palette
Analogy 3 · Travel packing

Vacuum-sealing suitcases

Fluffy winter coats take four giant trunks. Vacuum-sealing squeezes out empty air so the same wardrobe fits inside one carry-on—and takes one trip from baggage claim instead of four.

FP32 (4 trunks) → INT8 (1 carry-on)

Visual Analogy: Watch Color Precision Shrink Live

A pixel’s brightness works just like a model weight. Step down from smooth full precision to 4-bit (16 levels) or 2-bit (4 levels) to see where compression stays invisible—and where stair-step banding appears.

Original high precision (smooth)
100% file size · Continuous shades
Quantized to INT4 (16 levels per channel)
25% memory footprint · Subtle gradient banding

Inside the Math: Snap Real Weights onto an Integer Ruler

Quantization maps a range of floating-point weights onto whole integers using a step size called Scale (S) and an offset called Zero-Point (Z). Try dragging the outlier spike to see how one unusually large number stretches the ruler for every other weight.

Integer ruler
Mapping scheme
Step size — Scale (S)
0.233
Integer for 0.0 — Zero-Point (Z)
−2
Average rounding error
0.056
6 sample model weights snapped to integer buckets and restored
Weight role Original float (x) Stored integer (xq) Restored value Rounding gap

How engineers apply quantization safely

You can quantize an already-trained model in minutes without retraining—a method called Post-Training Quantization (PTQ) using tools such as GPTQ or AWQ. To calibrate the step size S, engineers either measure activation ranges on the fly (dynamic quantization) or pass about 200 sample prompts through first (static quantization). When accuracy is critical, Quantization-Aware Training (QAT) simulates rounding errors during fine-tuning so the model adapts around them.

One important nuance from hardware benchmarks: smaller isn’t always lower-energy. On large models (5B+ parameters), 4-bit quantization saves massive memory with near-FP16 energy use. On tiny models under 3B, however, unpacking 4-bit integers back into floats can raise energy use by 25–56%—whereas simply grouping 8–64 requests into a batch reduces energy per token by 84–96%.

Part 3 · Smarter short-term memory

KV caching & PagedAttention: stop re-reading the whole chat

Caching past tokens avoids repeating billions of calculations—if you don’t waste 70% of your memory reserving empty space.

Remember that LLMs generate one token at a time. To pick word #201, the attention mechanism checks how word #200 relates to every single earlier word in the conversation. Without caching, the GPU would have to recompute the internal summary vectors—called Keys (K) and Values (V)—for words #1 through #200 all over again on every single step.

KV caching fixes that by keeping sticky-note summaries in GPU memory. You compute Keys and Values once per word, file them away, and only compute the brand-new word at each step. Problem solved? Almost. As chats grow longer and dozens of users connect at once, the KV cache balloons.

Older serving systems stored each user’s KV cache as one unbroken, contiguous strip of memory—and because nobody knows ahead of time whether a reply will be 20 words or 2,000 words, they pre-reserved giant chunks for the worst-case maximum length. That left huge reserved gaps unused, wasting 60–80% of KV memory. PagedAttention (introduced by vLLM, inspired by how your laptop’s operating system manages RAM) breaks each conversation into small fixed-size KV blocks (typically 16 tokens each) and tracks them with a Block Table—letting scattered memory slots hold one continuous chat with 96.3% efficiency.

Interactive Simulator: Contiguous Memory vs. PagedAttention

Watch 24 physical GPU memory slots (4 tokens per slot) as two users generate answers—and see what happens when a third user arrives.

GPU physical KV memory (24 slots · 96 tokens max) 100% active block efficiency
User A User B User C Reserved / wasted
Block Table (Logical → Physical map)
Allocation status
User A and User B fit neatly in scattered blocks. Plenty of room for User C.
Bonus: Sharing prompts & shrinking KV heads (Copy-on-Write, MQA, GQA)
When many requests share the same system prompt—or when a model explores multiple candidate answers with beam search—PagedAttention maps multiple logical conversations to the exact same physical prompt blocks, only copying a block when answers diverge (copy-on-write), cutting KV memory by up to 55.2% in beam search. Modern model designs like Multi-Query Attention (MQA) and Grouped-Query Attention (GQA) also shrink the cache directly by letting multiple query heads share one set of Keys and Values.
Part 4 · Serving everyone at once

Continuous batching: don’t make seven diners wait for dessert

Moving 140 GB of weights to serve one user costs almost the same memory traffic as serving sixteen. The secret is swapping finished requests out after every single token.

Because loading weights from GPU memory dominates token generation, engineers group multiple users into a batch so one trip down the memory highway produces a new token for everybody at once. But standard static batching acts like a tour bus: you wait for all seats to fill, pad shorter prompts with dummy tokens so everyone lines up, and hold the entire bus until the user asking for a 500-word essay finishes—leaving seven users who only needed 30 words staring at a blinking cursor.

Continuous batching (also called iteration-level scheduling) turns the bus into a high-speed revolving door. At every single token step, the scheduler checks which requests hit an end-of-sequence marker (<eos>), sends them home immediately, and slots waiting requests from the queue straight into the freed GPU lanes on the very next iteration. In production, this single change delivers 2× to 10× higher throughput on identical GPUs.

Live Race: Static Batching vs. Continuous Batching

Four GPU lanes process 6 user requests of mixed lengths (A: 3 tokens, B: 10, C: 4, D: 6, plus queued E: 4 and F: 3). Step through or play the race to watch idle padding disappear.

Iteration: 0 / 12
Static batching 0% active work
Completed: 0 / 6 · Queue waiting until Step 10
Continuous batching 0% active work
Completed: 0 / 6 · Freed lanes refill immediately
Part 5 · Choosing your stack

How real serving engines put all four pieces together

You rarely build quantization, PagedAttention, and continuous batching from scratch. Production teams rely on specialized serving engines tailored to their hardware.

Three leading open-source & production serving frameworks

All three implement continuous batching and quantization—their strengths differ by hardware lock-in and ecosystem.

Framework Key optimizations Strengths Tradeoffs
vLLM PagedAttention, continuous batching, FlashAttention-2, GPTQ/AWQ quantization Broad model support, OpenAI-compatible API, industry-standard throughput without complex tuning Slightly lower peak single-card tuning than custom-compiled NVIDIA engines
TensorRT-LLM Deep NVIDIA kernel fusion, FP8/INT8/INT4 quantization, in-flight batching Maximum speed and hardware squeeze on dedicated NVIDIA GPUs Requires more setup and compilation; tightly coupled to NVIDIA hardware
Text Generation Inference (TGI) Continuous batching, optimized attention (SDPA/Flash), quantization Seamless Hugging Face Hub integration and straightforward deployment Tied closely to the Hugging Face model ecosystem

Optimization Recipe Builder: Pick Your Scenario

Select a real-world goal to see which combination of optimization techniques makes the biggest difference first.