Appendix A. A Gemma-3 case study in SLM architectural refinements
The chapter introduces how modern small language models reuse the core Transformer ideas popularized by larger Llama-style models, but reshape them to better fit compact, fast inference settings. It uses Google’s Gemma-3-270M as a concrete example of this trend, showing that even very small models still rely on attention and MLP blocks, yet make architectural choices that emphasize memory efficiency and stable training. The main theme is that model design is now highly size-dependent: techniques that work well at hundreds of billions of parameters may need to be revised when the model shrinks to only a few hundred million.
A central focus is attention compression. By comparing projection sizes and configuration settings, the text shows how to identify whether a model uses multi-head attention, grouped-query attention, or multi-query attention. In Gemma-3-270M, the query projection is four times larger than the key and value projections, but the configuration reveals only four query heads and a single key/value head. That means the model uses multi-query attention, where all query heads share one set of key and value vectors, maximizing KV-cache savings and reducing memory use during generation.
The chapter also explains that Gemma refines this compact design with extra normalization layers inside attention and a GLU-based MLP. The added query and key normalization help prevent one head from dominating when many query heads share the same key/value state, keeping attention scores balanced across heads. Meanwhile, the MLP preserves the gated structure seen in larger families, showing that compact models do not simply remove sophistication; instead, they selectively simplify where memory matters most and add stabilization where training dynamics need it. Overall, Gemma-3-270M illustrates how SLMs compress the standard Transformer while preserving effectiveness.
A.2 Refinements in the MLP module: expansion and stability
Throughout this book you've worked with GLU structures across multiple chapters, so its function as an expansion-contraction mechanism should already be familiar, and Gemma doesn't change these fundamental premises. Its MLP module has the same foundations, but introduces some interesting modifications, designed to optimize performance in a model of such ”small” dimensions.
To start, let's recall the structure of Llama-3.2-1B's MLP Module:
We compare it with the relevant and equivalent blocks of Gemma-3-270M:
As you can see, we've included the normalization layers in the structure. Although they are defined outside the MLP Module, they work together with it inside the Transformer block.
The first difference is the expansion ratio, a parameter that defines the "width" of the processing in the MLP. Let's calculate it for both models using the structures we've just seen:
Llama-3.2-1B: 8192 (intermediate dimension) / 2048 (embedding dimension) = 4.0x
Gemma-3-270M: 2048 (intermediate dimension) / 640 (embedding dimension) = 3.2x
With 18 blocks and an expansion ratio of 3.2x, Gemma-3-270M has the deep and narrow shape described in section 3.1.4, while Llama-3.2-1B, with 16 blocks and 4.0x, is wider and shallower.
Along with the expansion ratio, the other variation we find is the activation function. While Llama uses SiLU(), Gemma opts for PytorchGELUTanh(), a variant of the GELU function. The GELU-Tanh function offers smoother gradients and more stable convergence, which is especially valuable in smaller models where each parameter has a greater impact.
Finally, we find the pre_feedforward_layernorm and post_feedforward_layernorm normalization layers. Although in the structure they appear listed at the Gemma3DecoderLayer level, their function is intimately linked to the MLP. These layers act like a "corset" that wraps around the MLP module, stabilizing the data that enters and exits it. In a "thin and deep" architecture like Gemma's, with a small embedding of 640 (you can see the embedding size in listing A.1), but 18 blocks, maintaining numerical stability throughout the entire stack of blocks is a challenge, and these additional layers are a safeguard to prevent problems during training and inference.
None of these refinements changes the attention-plus-MLP structure of the Transformer block or the GLU of the MLP module. The stack of blocks remains available for depth pruning, and the GLU, which expands and contracts the information, for the Width Pruning techniques of Chapter 5.
Rearchitecting LLMs ebook for free