Mixture of experts, latent attention and trained reasoning: Mixtral, DeepSeek and GRPO
Mixtral routes each token to two of eight experts; DeepSeek compresses keys and values into a small latent; DeepSeek-R1 learned long reasoning from rewards with GRPO. See what each saves, what it costs and what it doesn't prove.
What runs in CodeSplash
- LNG037Mixtral sparse mixture-of-experts language model Explained here
- LNG039DeepSeek-V2 / V3 language-model family Explained here
- LNG040DeepSeek-R1 reasoning-model family Explained here
- LNG079Group Relative Policy Optimization (GRPO) Explained here
You will be able to
- Tell active from total parameters in a mixture-of-experts model, and say which one sets memory
- Explain how multi-head latent attention shrinks the KV cache
- Compute GRPO's group-relative advantages and describe its clipped objective
- Say what a model's written reasoning does and doesn't show
Many experts, few at a time
ReadA mixture-of-expertsMixture of expertsLayers with many expert sub-networks and a router that sends each token to a few. Compute follows active parameters, memory follows total. layer replaces one feed-forward block with several, the experts, and a router that picks a few of them for each token. Mixtral has eight experts per layer and sends each token to two. In the reference program, the router's two highest-scoring experts are numbers 0 and 3 (counting from zero), and their outputs mix into 1.80.
Compute follows the active parameters, about 13 billion per token for Mixtral. Memory follows the total, about 47 billion, because every expert must be loaded: any token might need any of them.
DExplorable · How much memory does a model need?
Where does a language model's memory go — weights, KV cache, optimizer state — and does it fit on this Mac?
Model
Hypothetical decoders; the first is the reference workflow's own.
Tokens held in the KV cache (and the length of the attention scores).
Sequences processed at once; the KV cache grows with it.
Weight format
Bits per stored weight; the llama.cpp types include their block scales.
KV cache format
Bytes per stored key or value.
Use
Training adds gradients and optimizer state; LoRA adds them only for the adapters.
LoRA only: rank of each adapter.
LoRA targets
LoRA only: which matrices get adapters.
Under half is “fits”, under 85% “tight”, as the app's own estimate says.
- Weights: 0.31 GiB
- KV cache: 0.02 GiB
- Runtime overhead (10%): 0.03 GiB
- Verdict: fits (2%)
- This model's KV heads (grouped-query)
- One KV head per query head
- Parameters
- 168059904
- Weight bytes
- 336119808
- KV cache bytes
- 25165824
- Trainable parameters
- 0
- Total bytes
- 397414195
- Share of this Mac's memory
- 0.023
- Puzzle: Make the larger decoder fit (under half) a 16 GB Mac for inference with a 4,096-token context.
- Puzzle: With LoRA training less than 1% of the parameters, find a case where the total is still more than half of full fine-tuning's.
Reference decoder (168M parameters): 168,059,904 parameters, 0.31 GiB of weights in fp16 and a 0.02 GiB KV cache for 2,048 tokens. Total 0.37 GiB: 2% of 16 GB, so it fits. These are logical tensor sizes, not measured memory.
Fewer active parameters, less memory?
PredictPredict first
Mixtral uses about 13 billion parameters per token out of about 47 billion. How much memory does it need for its weights?
Reveal
About as much as a 47-billion dense model. All experts must sit in memory, even though each token uses two. It runs faster than a 47-billion dense model, but it doesn't fit where a 13-billion one would.
Cache a latent, not the keys
ReadDeepSeek-V2 and V3 attack the KV cache from another side. Multi-head latent attentionMulti-head latent attentionDeepSeek's attention that caches one small latent vector per token and rebuilds keys and values from it, shrinking the KV cache. projects each token's hidden state down to one small latent vector, caches only that, and expands it back to per-head keys and values when needed. In the reference program a three-number state becomes a two-number latent, 0.04 and 0.30, from which a three-number key is rebuilt.
These models also use many small experts plus always-on shared experts. With 671 billion total parameters, they are far beyond a Mac; their small distilled versions are what people run locally.
Learning to reason from rewards
ReadDeepSeek-R1 was trained with reinforcement learning on tasks whose answers can be checked automatically, such as math with known results and code with tests. The model writes a long reasoning passage, then an answer; only the answer is rewarded.
The algorithm, GRPOGroup relative policy optimization (GRPO)Reinforcement learning for language models: sample a group of answers per prompt, score each against the group's mean, clip the update. (group relative policy optimization), samples a group of answers for each prompt and scores each against the others:
With rewards 0, 1, 2 and 1 in a group, the reference program gets advantages −1.41, 0, 1.41 and 0. No separate value network is needed: the group is the baseline.
Clipping the update
ReadEach answer's tokens are pushed up or down by its advantage, weighted by the ratio of their new to old probability. As in PPO, the ratio is clipped to a band around 1, so one batch can't move the model too far:
With ε = 0.2 and four ratios, the reference program's objective is 0.0354. R1's own example: a group with two right and two wrong answers gives advantages of about 1 and −1.
What the reasoning text is
ReadReasoning passages often help accuracy, and they make a model's errors easier to spot. They are not a trace of the computation: the answer comes from the network's activations, and the written steps can be incomplete, rationalized after the fact, or wrong while the answer is right. Judge the answer by checking it, not by how convincing the reasoning reads.
Where it stands in CodeSplash
Read| Entry | In CodeSplash |
|---|---|
| Mixtral (LNG037) | Explained here; usable through the AI layer, not a method |
| DeepSeek-V2/V3 (LNG039) | Explained here; too large for a Mac |
| DeepSeek-R1 (LNG040) | Explained here; distilled versions are usable through the AI layer, not a method |
| GRPO (LNG079) | Explained here |
Distilled R1 models inherit the licenses of their Qwen or Llama bases.
Check: experts, latents and GRPO
CheckpointCheck yourself
What do "active parameters" measure in a mixture-of-experts model?
Show the answer
Answer: b
Active parameters set compute per token. Total parameters, all experts included, set memory.
Check yourself
How does Mixtral's router combine the two experts it picks?
Show the answer
Answer: a
Top-2 routing keeps the two highest softmax scores, renormalizes them to sum to one, and mixes the two experts' outputs.
Check yourself
What does multi-head latent attention store in the cache for each token?
Show the answer
Answer: b
Caching a compressed latent instead of per-head keys and values cuts KV-cache memory sharply for long contexts.
Check yourself
Why can't a DeepSeek-V3 model with 671 billion total parameters run on a typical Mac, even though few are active per token?
Show the answer
Answer: b
Sparse activation saves compute, not storage. Small distilled versions are what run locally.
Check yourself
What was DeepSeek-R1's reinforcement learning rewarded on?
Show the answer
Answer: b
Verifiable rewards, such as matching a known math answer or passing code tests, need no human rater per sample.
Check yourself
A reasoning model writes a careful, convincing derivation and a final answer. What does the derivation prove?
Show the answer
Answer: c
Written reasoning is generated text. Verify the answer independently.
Check yourself
A group of four answers gets rewards 0, 1, 2 and 1. Using the population standard deviation, what is the advantage of the answer with reward 2, to two decimals?
Show the answer
Answer: 1.414213542373095
The mean is 1 and the standard deviation is about 0.707, so (2 − 1)/0.707 ≈ 1.41.
Check yourself
What does GRPO drop that PPO normally needs?
Show the answer
Answer: b
Comparing each answer with others for the same prompt replaces the critic, saving memory and a source of training error.
Check yourself
Every answer in a GRPO group gets the same reward. What happens to their update?
Show the answer
Answer: a
Group-relative advantages need differences within the group. Prompts that are always solved, or never, teach nothing.
Recap
Recap- Mixture of experts: compute follows active parameters, memory follows total parameters.
- Multi-head latent attention caches a small latent per token instead of full keys and values.
- GRPO normalizes rewards within a group of sampled answers and clips the update; R1 used it with checkable rewards.
- Reasoning text is output to check, not a trace of the computation. These models run only through the AI layer.
Concepts in this lesson