Built by
Mixture of Experts
- IG Igor Lima @igor17400 6 page
Every merged contribution is typed and scored at review. Chips next to a heading show who touched that section. Scores feed the contributor share of project support.
01 · Mixture of Experts
The Layer That Reads Everything
A feed-forward layer spends all of itself on every token.
A transformer layer is split into two fundamentally different halves. The attention mechanism routes information across positions, deciding how tokens relate to one another and mixing their context. The feed-forward block (FFN) that follows, however, is entirely localized. It takes a single token's representation in isolation, expands its dimensionality, applies a non-linear transformation, and compresses it back down.
This section focuses on that second half. While attention captures contextual relationships, the FFN contains the vast majority of the model's parameters. And Mixture of Experts architectures are a promising direction to resolve that computational constraint.
Where the parameters are
Let's start with the attention half, which learns four projections, each of them a square matrix
The famous part of attention, the
Now the feed-forward block. It learns two rectangular matrices,
Twice the attention block, from two matrices against four. Put the two halves side by side and two thirds of every layer's parameters sit in the FFN half.
The imbalance alone is not a problem. Parameters are what a model knows, and a layer that keeps two thirds of its knowledge in one place is not obviously worse than one that spreads it. The problem is what happens to those parameters at run time.
Two matrices and a nonlinearity
Write
is the model width, the dimension every token carries between layers. is the inner width, how far the block expands before it comes back. Conventionally . is the expansion, and the projection back down. and are the biases, and is the nonlinearity.
Two limitations of this formulation are fundamental to understanding Mixture of Experts.
- The computation is entirely independent per token. As shown in the diagram's
input block, a single token is just one -dimensional vector sliced from the sequence, so a sequence of tokens results in isolated forward passes. - Every single token is forced through the identical matrices
and . The standard layer possesses no mechanism to tailor its weights for specific tokens or to leave any part of the network unactivated.
The gated variants, which have three matrices
Recent models usually replace this block with a gated variant, in which a third matrix produces a gate that multiplies the expansion elementwise before the projection. Mixtral, for instance, is built from SwiGLU blocks, and picks
Nothing on this page changes. The parameter count picks up a factor of three over two, the cost per token picks up the same factor, and every sentence below about the two counts moving together survives untouched. We use the two matrix form because the arithmetic is cleaner and the conclusion is identical.
The same number twice
First, let's count the parameters. The matrix
Now, let's count the computational work. Multiplying an
Put the two side by side and an interesting relation shows up:
The factor of two accounts for one multiplication and one addition per weight. It does not depend on
The diagram below illustrates this computation for a single
It helps to see it with real numbers. At
| Quantity | One block | 32 layers |
|---|---|---|
| Parameters | 134,217,728 | 4.29 billion |
| FLOPs per token | 268,435,456 | 8.59 billion |
Turning the only knob
If we want to increase the capacity of the feed-forward block, the most direct approach is to increase
If we analyze this on the graph below, we can see that every possible dense feed-forward configuration is trapped on a single linear trajectory. There is no architectural knob in a dense layer that allows to step off this line and reach the empty region of higher capacity without a proportionally higher compute cost.
What we would want instead
So the thing to attack is not the size of the block. It is the ratio. We want a layer that holds a great deal of parameters and uses only a few of them on any given token, so that the parameter count and the cost per token can be raised and left alone independently.