0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Draft with a small model, check with a big one
Last episode, we learned that generating text drips out one token at a time, limited by how fast the model's weights can be read from memory. Today we make the model itself faster. Here's one of the cleverest tricks. Let a small, fast model write a quick draft of the next few tokens. Then the big model checks all of them in a single pass. Most draft tokens are accepted; the first wrong one is replaced. If the drafter is right eighty percent of the time, the big model produces over three tokens per step instead of one, and the output follows exactly the same probabilities as the big model working alone.
Today: compressing models, speculative decoding, and the memory tricks that keep long conversations fast. Season Five, Module Twenty-One, stop two: faster models.
1:07Compression: quantisation, distillation and pruning
The first family of speed-ups compresses the model. Quantisation, from episode seventy, stores weights in fewer bits. Since decoding must read every weight for every token, fewer bytes means faster tokens: shrinking from fourteen gigabytes to three and a half raised our theoretical ceiling from about a hundred and forty tokens a second to about five hundred and seventy. It also frees memory for more users. Distillation, from episode seventy-five, trains a smaller student to match a larger teacher on your task. And pruning removes the parts of a network that matter least, such as whole attention heads or layers, which can give real speed-ups when done in a structured way.
Every compression can cost some quality, sometimes more on reasoning, other languages or safety than on everyday chat. Re-run the full scorecard after each one.
2:06Speculative decoding, explained
Now speculative decoding, in detail. A small draft model, much faster than the main one, writes a guess of the next few tokens, say four: "your return label is". The large model then processes all four in a single parallel pass, which, as we saw, is efficient, because parallel work uses the hardware well. Moving left to right, the draft tokens are accepted while they agree with what the large model would produce. At the first disagreement, the large model's own token is used instead, and drafting starts again. With the proper acceptance rule, the final output follows exactly the same probabilities as the large model alone.
It's faster, but not different. How much faster? If each draft token is accepted with a probability we'll call the acceptance rate, and we draft four at a time, the expected number of tokens per large-model pass is one minus the acceptance rate to the fifth power, all divided by one minus the acceptance rate. At sixty percent acceptance, about two point three tokens per pass. At eighty percent, about three point four. At ninety percent, about four point one. Predictable text, like support replies and code, tends to get high acceptance; creative writing, lower.
3:31Copying drafts from the context
There's an even cheaper source of drafts: the prompt itself. Support replies often quote the retrieved policy almost word for word. So when the model starts writing "report damage within", the system can look up the matching sentence in the context and propose its next several tokens as the draft, then verify them all in one pass, just like speculative decoding, but without a second model. Other approaches add extra prediction heads that guess several tokens ahead at once, again verified by the main model.
4:06The KV cache: don't recompute the past
At the heart of fast decoding is the K-V cache, which we met in episode forty-four. Without it, to produce the three-hundred-and-first token, the model would recompute the keys and values for all three hundred previous tokens, again and again. With the cache, each layer stores those keys and values once, and every new token computes only its own and attends to the stored ones, like adding a line to a notebook instead of rewriting it. The price is memory: in our example design, about half a megabyte per token, about two gigabytes for a four-thousand-token conversation, per user.
4:47Grouped-query attention, cache quantisation and FlashAttention
Several techniques make attention and its cache cheaper. Grouped-query attention, chosen when a model is designed, lets several heads share keys and values, shrinking the cache by four in our example, from half a megabyte per token to an eighth. The cache itself can be quantised to eight or four bits, fitting more users or longer conversations on each graphics card. FlashAttention computes exactly the same attention in small tiles in the chip's fastest memory, never writing the giant attention grid out. And for very long conversations, some systems keep only recent tokens in the cache, plus a few important ones, trading a little quality for memory.
5:34Kernel fusion, compilers and shorter answers
Two more levers. Under the hood, a transformer layer is a series of small operations, multiply, add a bias, apply an activation, and each one normally reads from and writes to memory. Fusing them into a single combined operation reads and writes once, which saves a lot of memory traffic. Modern inference engines and compilers do this automatically. And the simplest speed-up of all: write less. Decoding time grows with every output token, so a concise style, answering first and offering details on request, plus sensible stop sequences, cut both latency and cost.
Brightcart's eighty-word limit isn't just about style. One caveat: this corner of AI moves quickly. These examples were current when we made this video, and they may look different on the day you watch it.
6:29Try it yourself: speculative decoding at 70%
Suppose the small draft model's guesses are accepted seventy percent of the time, and it drafts four tokens at a time. How many tokens does each big-model pass produce on average? Pause. About two point seven seven. But drafting has a cost. If each draft token costs a tenth of a big-model pass, four drafts add four tenths, so each cycle costs one point four passes. The real speed-up is about two times: still excellent. Speculative decoding pays off when the draft model is both fast and good at guessing what the big model would say.
7:15Pause & Predict: draft more tokens?
At sixty percent acceptance, drafting four tokens gives about two point three tokens per pass. What if we draft eight instead? Pause. Only about two point four seven. Doubling the draft length barely helps, while doubling the drafting work. Each extra draft token only counts if every earlier one was accepted, and the chance of five acceptances in a row at sixty percent is under one in ten. The best draft length depends on the acceptance rate, so it's tuned, not guessed.
7:53Try it yourself: life without a KV cache
Why is the KV cache so important? Generate three hundred tokens after a three-thousand-four-hundred-token prompt. With a cache, the prompt is processed once, then each new token once: about three thousand seven hundred token-passes. Without a cache, every step reprocesses everything so far. How much more work is that? Pause.
Over a million token-passes, nearly three hundred times more. The cache trades memory for an enormous saving in computation, which is why managing its memory well is the subject of the next episode.
8:36Shorter answers are faster answers
Here's what writing less saves, in numbers. Before Brightcart's eighty-word rule, a typical reply ran to about three hundred tokens. At a fortieth of a second per token, trimming it to two hundred saves two and a half seconds for every customer, and a third of the output cost. Set a length target, cut filler phrases, and don't repeat the customer's question back to them. Then check the evaluation scores, to make sure nothing important was cut along with the padding.
9:11Pruning, briefly
Pruning removes parts of a model. Zeroing out individual small weights makes the model sparser, but ordinary hardware still does the same amount of work, zeros included, so the real speed-up is often small. Removing whole structures, like neurons, attention heads or even layers, or using sparsity patterns that some GPUs support directly, gives real speed-ups, usually followed by a little retraining to recover quality. Speed comes from structure the hardware can actually exploit.
9:48Prompt-lookup decoding
Brightcart's replies often repeat text from the prompt: order numbers, product names, whole policy sentences. Prompt-lookup decoding takes advantage of this. When the last few generated tokens match something in the prompt, the system proposes the words that followed in the prompt as a draft, and the model checks them all in a single pass. It's like speculative decoding without a draft model, and it works best when the answer quotes its sources, which is exactly what a grounded assistant does.
10:21Pause & Predict: which speed-up for which problem?
Match each problem to a speed-up. The model doesn't fit on the card. Each token is slow, even for a single user. Replies quote long policy passages. Long conversations run out of memory. Answers are simply too long. Pause.
Doesn't fit: quantise. Slow tokens: quantise, so fewer bytes are read per token, and add speculative decoding. Quoted passages: prompt-lookup decoding. Memory running out on long chats: grouped-query attention and smarter cache management. And long answers: write shorter ones. Every technique answers a specific bottleneck, so measure first, then choose.
11:12Always re-evaluate after speeding up
Every speed-up goes through the same release checklist: the golden set and its gates, the safety and red-team sets, latency percentiles and goodput, and cost per thousand requests. Some techniques, like properly implemented speculative decoding, leave the big model's outputs statistically unchanged. Others, like quantisation, pruning and distillation, genuinely change the model, so they must be re-evaluated before a single customer sees the result.
11:42Distillation: a smaller, faster student
Distillation is also a speed technique. Train a one-billion-parameter student on the seven-billion-parameter assistant's best replies. Its weights shrink from fourteen gigabytes to two, so the speed limit set by memory bandwidth rises from about a hundred and forty-three tokens a second to around a thousand. The catch, as always, is quality: the student must pass the same gates. A common pattern is to let the student handle routine tickets and route harder ones to the bigger model.
12:18Predicting several tokens at once
Another idea attacks the one-token-at-a-time bottleneck directly. Some models are trained with extra output heads that predict not just the next token, but the second, third and fourth tokens after it. At generation time, those extra guesses act as built-in drafts, which the model verifies on its next pass, rather like speculative decoding without a separate draft model. It costs extra training effort and a little more work per pass, in return for fewer passes per reply.
12:51Myth vs Fact
Myth: speculative decoding makes answers worse, because a smaller model is doing the writing. Fact: the large model checks every token, and with the proper acceptance rule, the output follows exactly the same probabilities. Only the speed changes.
13:10Recap
Let's recap. Compressing a model, through quantisation, distillation or pruning, makes every token cheaper, as long as quality holds up. Speculative decoding lets a fast drafter propose several tokens that the large model verifies in one pass, with no change to the output's probabilities. Drafts can even be copied from the context. The K-V cache avoids recomputing the past, and grouped-query attention, cache quantisation and FlashAttention keep it lean. Fused operations and shorter answers do the rest. One sentence to remember: read fewer bytes, verify many tokens at once, and never recompute the past.
13:53Next: faster serving
Mission complete. Brightcart's self-hosted model now runs in four-bit precision, after re-passing the scorecard, uses speculative decoding with drafts copied from the policies, keeps a compact cache, and writes concise replies. But at lunchtime, five hundred customers chat at once. Serving them all quickly is a different problem: batching, separating prefill from decoding, caching prompts, and splitting work across many chips. Faster serving, next. See you on the map.