0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09A 47B model that runs like a 13B one
Here's a model with nearly forty-seven billion parameters. Yet for each token it processes, only about thirteen billion of them do any work. It has the knowledge capacity of a large model with roughly the per-token cost of a much smaller one. And here's a second challenge: feeding a model a three-hundred-page supplier contract. The attention grid from last season explodes in size, and memory runs out. These are two frontiers in modern language models: growing capacity without growing the bill, and reading longer inputs without exhausting memory.
Today, the ideas that push the basic transformer further: mixture of experts, long-context techniques, and alternative architectures that might one day rival attention.
1:02Where we are: beyond the transformer
Season Three, Module Eleven, final stop: beyond the basic transformer.
1:08Mixture of experts: routers and experts
Remember from the end of Season Two that the feed-forward layers hold about two thirds of each transformer layer's parameters. Mixture of experts, or M-o-E, replaces each big feed-forward network with several smaller ones, called experts, plus a small router. For every token, the router scores the experts and sends the token to just the top few, often two out of eight. Their outputs are blended, weighted by the router's scores. Different tokens can go to different experts: a token about kettles might go to experts two and five, a token about refunds to one and seven.
The router learns these assignments during training, by backpropagation like everything else.
1:56Total vs active parameters
This creates a useful split between two numbers: total parameters and active parameters. With eight experts of a billion parameters each and top-two routing, the model holds eight billion expert parameters, but each token only uses two billion. A well-known open model, Mixtral eight-by-seven-B, has about forty-seven billion parameters in total, but uses about thirteen billion for each token. So it has the capacity of a large model, while each generated token costs roughly what a thirteen-billion-parameter model would.
There are catches. All the experts still have to sit in memory, so you need room for the full forty-seven billion. The router has to be encouraged, with an extra term in the loss, to spread work evenly, or it might send everything to a few favourite experts. And training and serving get more complex. Even so, mixture-of-experts designs have become a popular way to build large, efficient models.
3:02Why long context is hard
Now the second frontier: long inputs. Self-attention compares every token with every other token. A thousand tokens means a million comparisons; ten thousand means a hundred million; a hundred thousand means ten billion. Memory is often the tighter limit. When a model generates text, it stores the keys and values of every previous token in every layer, so it doesn't have to recompute them for each new word. That store is called the K-V cache. For a typical seven-billion-parameter design, it takes about half a mebibyte per token: two gibibytes for four thousand tokens, and sixty-four gibibytes for about a hundred and thirty thousand tokens, more than many graphics cards can hold, just for one conversation.
3:54Making long context cheaper
Engineers attack this from several angles. Grouped-query attention lets several attention heads share the same keys and values. With eight shared key-value heads instead of thirty-two, the K-V cache shrinks by four: sixteen gibibytes instead of sixty-four for that hundred-and-thirty-thousand-token conversation. FlashAttention computes exactly the same attention, but in small tiles that fit in the chip's fastest memory, so the full grid never has to be stored. Same answer, much faster. Sliding-window attention lets each token look only at a nearby window of tokens, plus a few special ones.
Because layers stack, information can still travel across long distances, step by step. And techniques for stretching position encodings let models trained on shorter texts work on longer ones, usually with some extra fine-tuning.
4:52State-space models and Mamba
There's also a line of research that revisits recurrence. State-space models, such as Mamba, keep a fixed-size running state, like an RNN, but with a mathematical design that lets them train in parallel and run in time proportional to the length of the input, rather than its square. Their updates are selective: the input decides what to keep and what to forget, a bit like the LSTM's gates. Their weakness mirrors the RNN's: a fixed-size state can't hold every detail, so recalling exact information from far back is harder than with attention.
That's why many designs combine both, mixing attention layers with state-space layers. Whether attention will stay dominant is an open question, and a very active area of research. Keep in mind that details like these change fast. They were correct when this video was published, so treat them as a snapshot, not a permanent fact.
5:53Lost in the middle
Even when a model accepts a very long input, that doesn't mean it uses all of it equally well. Researchers found that some models are better at using information near the beginning or the end of a long context than information buried in the middle. It was nicknamed "lost in the middle". Newer models have improved, but the lesson stands. In practice: put the most important instructions and material near the start or end, test whether the model really finds what it needs, and often, rather than pasting in an entire three-hundred-page contract, retrieve just the relevant pages.
That's the retrieval approach of Season Five.
6:37Other directions
The basic transformer keeps evolving in other directions too: smaller, efficient models that run on laptops and phones, using techniques like distillation and quantisation from Season Five; models that take images and sound as well as text, coming in the next modules; and models that reason longer and use tools.
6:59Try it yourself: route one token
Let's route a token by hand. The word "refund" reaches a layer with four experts. The router gives them scores of two, a half, one and a half, and minus one. After softmax, that's fifty-three, twelve, thirty-two and three percent. With top-two routing, which experts run? Pause.
Experts one and three. Their weights are renormalised to sum to one: about sixty-two and thirty-eight percent. The layer's output is that weighted blend of their two outputs, and experts two and four don't compute anything for this token. The next token might go somewhere completely different.
7:46Pause & Predict: total vs active
Another one. Sixteen experts, each with two billion parameters, and each token uses two. How many expert parameters must be stored, and how many are used per token? Pause. Thirty-two billion stored, but only four billion used for each token, plus the shared attention layers. That's the deal mixture of experts offers: the knowledge capacity of a big model, with the compute cost per token of a much smaller one. The catch, as we saw, is memory: all thirty-two billion must be loaded and ready.
8:26Keeping the experts busy
Mixture of experts has a balancing problem. With a thousand tokens, eight experts and top-two routing, there are two thousand assignments, ideally about two hundred and fifty per expert. But if the router starts favouring one expert, that expert gets better, so the router favours it even more, while the others sit idle and never learn. Training adds an extra loss that rewards spreading the work evenly, and often caps how much each expert can take. And interestingly, experts rarely specialise in neat human topics like "cooking"; their patterns tend to be subtler.
9:06Try it yourself: 20 customers at once
Brightcart's server handles twenty conversations at once, each with four thousand and ninety-six tokens of context. Using our seven-billion-parameter example, how much memory does the KV cache need? Pause. At half a mebibyte per token, it's forty gibibytes, far more than the model's own weights. With grouped-query attention, it's a quarter of that: ten. That's why these techniques matter so much in practice: the KV cache, not the model itself, often decides how many customers a server can handle at once.
9:50Sliding windows, by the numbers
Sliding-window attention is one way to tame the cost. With a hundred thousand tokens, full causal attention, where every token looks at all the tokens before it, compares about five billion pairs. If each token only looks at the previous four thousand and ninety-six, it's about four hundred million pairs, around twelve times fewer. Information can still travel further, passed from layer to layer like a message down a line: with thirty-two layers, in theory, over a hundred and thirty thousand tokens. But a message passed through many hands is weaker than one delivered directly.
10:31A state-space step, by hand
Here's the core of a state-space model, in one line. The new state is a times the old state, plus b times the input. With a at zero point nine, an input of one followed by zeros gives states of one, zero point nine, zero point eight one: a smoothly fading memory. Selective state-space models make a and b depend on the current input, so the model can decide when to hold on and when to let go, rather like the LSTM's gates. And the state stays the same size, however long the text gets.
11:09Working around lost in the middle
What can Brightcart do about "lost in the middle"? Put the most relevant documents at the start or end of the prompt. Retrieve fewer, better documents instead of stuffing in twenty. Ask the model to quote the passage it relied on, so you can check it. And test with your own long prompts. Be careful with "needle in a haystack" tests, where a model finds one planted sentence: they're useful, but real tasks, which need several facts combined, are usually harder.
11:42Pause & Predict: which technique, which problem?
Let's match problems to techniques. The model needs more knowledge, but each token must stay cheap. The KV cache is too big. Attention is too slow on very long inputs. And we want a fixed-size memory for endless streams. Pause and match them.
More knowledge at low cost per token: mixture of experts. A huge KV cache: grouped-query attention. Slow attention on long inputs: memory-efficient attention, or sliding windows. A fixed-size memory: state-space models, or hybrids that combine them with attention. Every technique in this episode is an answer to a specific bottleneck.
12:29Myth vs Fact
Myth: a forty-seven-billion-parameter mixture-of-experts model costs as much to run, per token, as a forty-seven-billion-parameter ordinary model. Fact: the computation per token follows the active parameters, about thirteen billion for Mixtral. But the memory has to hold all forty-seven. Both numbers matter when choosing a model.
12:55Recap
Let's recap. Mixture of experts replaces each feed-forward layer with several experts and a router that picks the top few for each token, so per-token compute follows the active parameters while memory holds them all. Long contexts are expensive because attention grows with the square of the length and the K-V cache grows with every token. Grouped-query attention, FlashAttention and sliding windows make them cheaper. State-space models offer linear-time alternatives, often combined with attention. And long contexts aren't used perfectly, so structure your inputs carefully.
One sentence to remember: use only the experts you need, and remember only what you must.
13:42Next: autoencoders and latent space
Mission complete. Dev now understands how a huge model can run like a smaller one, and how to handle long conversations without running out of memory. And that completes Module Eleven, large language models. Next, we move from writing to drawing. How do machines generate brand-new images? It starts with a beautiful idea: squeezing a picture into a handful of numbers, and rebuilding it. Autoencoders, and the latent space. See you on the map.