Sparse Models and Mixture of Experts
Data quantity, quality, and diversity work together. A model learns from what the data contains, so a huge but indiscriminate collection can carry less useful signal than a smaller, cleaner, and more varied one.
Why Two Models From One Family Differ
Suppose two language models come from the same family, and one is noticeably stronger on every task you try. What made the difference? A tempting answer is that the stronger one is simply bigger. That answer is partly right, but it hides several other forces that shape how well a model turns its design into useful behavior. This article walks through the main factors: how many parameters a model has, how those parameters are used, how much data it was trained on, what that data looked like, and how recently the model was built.
What do you think happens?
On the MMLU benchmark, which scores higher: Llama 3-8B, or Llama 2-70B, which has far more parameters?
Reveal answer
Llama 3-8B outperforms Llama 2-70B on MMLU.
Llama 3-8B was released in 2024 and Llama 2-70B in 2023. The newer, much smaller model beats the older, much larger one, which shows that generation and training method matter alongside size.
What a Parameter Count Tells You
A model's parameters are the adjustable numbers that training shapes. When people compare models, the parameter count is often the first figure they look at, and it is common practice to write that count at the end of the model's name. Llama-13B, for example, identifies the Llama model family, developed by Meta, in its version with 13 billion parameters.
Parameter count sets a model's capacity to learn. Within one model family, a larger model generally performs better. That is the main reason size is a useful first comparison. But capacity is only the potential to learn. Whether that potential is realized depends on what the model is trained on and how training was done, which the rest of this article covers.
Estimating Memory From Parameter Count
The parameter count also tells you roughly how much hardware is needed. Each parameter is stored as a number that takes a fixed number of bytes. If you know that number and the count, you can estimate the minimum memory required to hold the model while it runs inference, which means producing outputs rather than learning.
- 1M is the minimum memory needed to hold the model's parameters.
- 2N is the number of parameters.
- 3b is the number of bytes used to store each parameter, which depends on the numeric precision.
- 4When N is written in billions and b in bytes, the product comes out directly in gigabytes. For example, 13 billion parameters at 2 bytes each is about 26 GB.
The byte size per parameter depends on the numeric precision used to store the values. Full precision (FP32) uses 4 bytes per parameter, half precision (FP16) uses 2 bytes, and 8-bit integers (INT8) use 1 byte. The table below applies the same 13 billion parameter count to each precision. These figures cover the stored weights only; the actual memory a running system needs can be higher.
| Precision | Bytes per parameter | Approximate weight memory for 13 billion parameters |
|---|---|---|
| FP32 | 4 | about 52 GB |
| FP16 | 2 | about 26 GB |
| INT8 | 1 | about 13 GB |
The same parameter count needs different memory depending on the storage size per parameter.
Estimating memory for a 7 billion parameter model
A model has 7 billion parameters and is stored in FP16. What is the minimum memory needed to hold its weights for inference?
- 1Identify N
N is 7 billion parameters.
- 2Identify b
FP16 stores each parameter in 2 bytes, so b is 2.
- 3Apply the estimate
Multiply 7 by 2 to get 14, which is 14 GB when N is in billions and b is in bytes.
About 14 GB of memory is the minimum needed to hold the weights. Real systems need additional room for other data, so this is a lower bound.
Tracing One Token Through a Mixture-of-Experts Layer
One popular sparse design is the mixture-of-experts model, usually abbreviated MoE. An MoE model divides its parameters into separate groups, and each group is called an expert. The model does not run every expert on every token. Only a subset of the experts is active for processing any given token. Follow a single token through the layer in the diagram below to see which expert groups do the work and which stay idle for that token.
Read the diagram from left to right. The token arrives, and the routing step decides which experts should process it. In this illustration, two of the eight expert groups are active for the token, and the other six are left idle. Those idle expert weights still exist in the model, but they do no work for this particular token. A different token may be routed to a different subset, so the active experts can change from token to token.
What do you think happens?
Suppose a layer has eight experts and the routing step sends each token to two of them. For one token, how many expert groups run, and how many stay idle?
Reveal answer
Two run and six are idle.
Only the selected subset processes the token. The other experts' weights are not used for that token, even though they are part of the model.
Total Parameters Versus Per-Token Compute
A raw parameter count can be misleading when the model is sparse. A sparse model is one in which a large share of the parameters hold the value zero. Those zeros do not contribute to the model's computation in the same way that nonzero values do, so counting them as full parameters overstates the model's working size. The source states the consequence directly: a sparse model can require less compute than a dense one, even when the sparse model is larger on paper.
Mixture-of-experts designs work on a related principle. They decouple total parameters from per-token compute. The total parameter count describes what is stored. The per-token compute describes what runs for each token. The diagram below sets these two quantities side by side for a dense model and an MoE model.
The source's example is Mixtral 8x7B, which is built from eight experts, each with seven billion parameters. A naive calculation that multiplies those figures does not give the reported total, because some parameters are shared between experts, so the real count is lower. The important point is the division of labor. The parameters are split into experts, and only some of those experts are engaged for any token. The total and the per-token workload therefore differ.
Counting Data in Tokens
Data quantity is the second major lever. Early on, researchers measured a dataset's size by counting training samples. That stops working for language models, because a training sample might be a sentence, a Wikipedia page, a chat conversation, or a whole book, and a book carries far more material than a sentence. The better yardstick is the number of tokens, since a token is the unit a language model actually operates on. Counting tokens tells you roughly how much the model has the opportunity to learn from its data.
Token counts depend on the tokenizer, because different models split text differently, and the same dataset can produce different token totals. Even so, token counts give a far more useful comparison than sample counts. Meta's Llama models show the trend the source describes, as the table below shows.
| Model | Training tokens |
|---|---|
| Llama 1 | 1 trillion |
| Llama 2 | 2 trillion |
| Llama 3 | 15 trillion |
Training token budgets across successive Llama generations.
Modern language models are trained on datasets measured in trillions of tokens. The jump from one generation to the next shows how quickly the token budget has grown.
Dataset Tokens Versus Training Tokens
Two numbers are easy to confuse here, and the difference matters when you compare models. The first is the dataset's token count, which is how many tokens the collection contains. The second is the model's training token count, which is the total number of tokens the model processes during training. The source notes that training tokens count every pass over the data. A dataset is read once or several times, and each pass adds to the training total. The diagram below separates the two.
Dataset tokens and training tokens
A dataset contains 1 million unique tokens. A model is trained on this dataset for 3 passes. What is the dataset token count, and what is the training token count?
- 1Dataset token count
The dataset contains 1 million unique tokens, so the dataset token count is 1 million.
- 2Count each pass
Each pass reads the full dataset once, so one pass processes 1 million tokens.
- 3Total over passes
Three passes process 3 times 1 million tokens, which gives 3 million tokens.
The dataset has 1 million tokens, but the model processes 3 million tokens during training. Quoting only the dataset size would understate the training token count.
The two counts do not move together in a simple way. The source notes that training token counts do not scale neatly with parameter counts. A bigger parameter count does not automatically come with a bigger token budget. Chinchilla, with far fewer parameters than several of the other models in the source's comparison, was trained on a much larger number of tokens.
When Capacity Outruns the Data
Capacity needs material to fill it. A large model that is trained on too little data can underperform a much smaller model that saw more. The source gives a deliberately extreme case. Imagine a 13-billion-parameter model whose entire training set is the single sentence 'I like pineapples.' Such a model has enormous capacity and almost nothing to learn from, so it will perform far worse than a much smaller model trained on a substantial body of text.
The lesson is that model size and data size have to be read together. Judging a model by its parameters while ignoring its training data gives an incomplete picture. Parameter count sets the capacity, and the training data decides how much of that capacity has anything to work with.
Quality and Diversity Beyond Raw Volume
Quantity is not the only thing that matters. The source names three goals for training data, which it calls the three golden goals: quantity, quality, and diversity. Quantity has been the focus of this article so far, but a large dataset can still be a poor teacher if its contents are weak.
The source illustrates this with RedPajama-v2, an open dataset from Together that contains 30 trillion tokens. That is an enormous volume, but because it is made of indiscriminate content, the portion that counts as high quality is much smaller. Raw size and useful signal are different things. A dataset with many tokens and low quality may teach a model less than a smaller, cleaner, more varied one. The source points to a later chapter for a fuller treatment of quality and diversity.
Data quantity, quality, and diversity work together. A model learns from what the data contains, so a huge but indiscriminate collection can carry less useful signal than a smaller, cleaner, and more varied one.
Mistakes When Comparing Model Size
Common mistake Assuming the bigger model from the same family is always stronger
What it looks likeLlama 3-8B outperforms Llama 2-70B on MMLU despite having far fewer parameters.
Why it failsA newer generation trained with better methods can beat an older, larger model.
Do this insteadCompare generation and training approach alongside the parameter count.
Common mistake Treating the total parameter count of an MoE model as its per-token cost
What it looks likeReading eight experts of seven billion parameters each as if all of them run for every token.
Why it failsOnly a subset of experts is active for any given token, and the naive total is not the reported total.
Do this insteadAsk how many parameters are active for one token, and use the reported total rather than multiplying figures.
Common mistake Using the dataset token count as the training token count
What it looks likeReporting a 1 million token dataset as if the model processed only 1 million tokens after 3 passes.
Why it failsTraining tokens count every pass over the data.
Do this insteadMultiply the unique token count by the number of passes to get the training total.
Common mistake Estimating memory from the parameter count alone
What it looks likeIgnoring that FP32 uses 4 bytes per parameter while INT8 uses 1 byte.
Why it failsThe storage size per parameter changes the memory needed by a factor of four between FP32 and INT8.
Do this insteadMultiply the parameter count by the bytes per parameter for the precision in use.
Common mistake Equating a large token count with high quality data
Checking Your Understanding
A model has 7 billion parameters. Estimate the minimum memory needed to hold its weights at FP32 precision, then explain why an MoE model with the same stored total might still need less compute per token than a dense model with 7 billion parameters.
Hints
- FP32 uses 4 bytes per parameter, so multiply 7 by 4 when the count is in billions.
- Think about which parameters run for each token, not only which parameters are stored.
Key Takeaways
- Parameter count sets a model's capacity to learn, and within one family a larger model generally performs better, but generation, training approach, and data determine whether that capacity pays off.
- Minimum memory for weights is roughly the parameter count times the bytes per parameter, so the same model needs about 52 GB at FP32, 26 GB at FP16, and 13 GB at INT8 when it has 13 billion parameters.
- In sparse and mixture-of-experts designs, total parameters and per-token compute are decoupled, because only a subset of experts processes any given token.
- Dataset token count measures unique material, while training token count measures every pass over the data, so the two numbers must not be confused.
- Data quality and diversity matter alongside quantity, since a huge but indiscriminate dataset can teach less than a smaller, cleaner, and more varied one.