Skip to content

TransformersLesson 9 of 10

Scale and computation

Scaling, cached attention, and low-rank updates

Increasing model size can improve prediction, but also increases the resources required. This chapter looks at measured scaling trends, what they tell us about capabilities, and ways to reduce computation or training costs.

Scaling laws are empirical relationships between language-model loss, often measured on held-out text, and resources such as parameters, data, and compute. Over studied ranges, these relationships can often be approximated with power laws. They help estimate tradeoffs; they do not guarantee that a larger model performs better on every task.

An illustrative power-law curve, not measured results from a trained model. Change the model size to see what this assumed relationship predicts.
Go deeper: it's a budget you split (Chinchilla)

Params aren’t the only dial. For a fixed compute budget you split it between model size and training data — and there’s a sweet spot. That’s compute-optimal scaling.

A simplified loss formula illustrates the tradeoff between model size and training data under a fixed compute budget.

Did few-shot learning appear at one model size?

Section titled “Did few-shot learning appear at one model size?”

Few-shot prompting supplies a few examples in the input, then asks for another answer. For example, show two reviews with their sentiment labels, then provide an unlabeled review. The examples change the model’s input; they do not update its weights. Those weights were learned during earlier training.

The GPT-3 study tested eight model sizes, from 125 million to 175 billion parameters. Larger models often benefited more from examples, but most tested tasks showed relatively smooth improvement. The paper did not establish one parameter count at which few-shot learning universally switches on. Brown et al., 2020

Some tasks do show a sharper-looking change: smaller models score near chance, then larger ones do substantially better. Researchers called these emergent abilities. That observation concerns a particular task, model family, and scoring method. Training data and training choices also matter; parameter count is not a universal boundary. Wei et al., 2022

The scoring method can make a gradual improvement look sudden. Imagine four hypothetical models choosing between two labels. They always pick the label with the higher probability:

Model AModel BModel CModel D
Probability assigned to the correct label40%49%51%60%
Chose the correct label?NoNoYesYes

The probabilities improve gradually. A right-or-wrong score jumps when the correct label becomes more likely than the other one. These are invented numbers for one question, not measured model results. Schaeffer and colleagues demonstrated that metric choices can produce apparent emergence in studied benchmarks. That cautions against reading every sharp graph as a sudden internal transformation; it does not prove that every capability change is an illusion. Schaeffer et al., 2023

Using examples to handle new cases is an ability worth understanding. The next question is how far it carries: does the model still succeed when the wording changes, labels are unfamiliar, or the problem needs a different combination of steps? Those tests help distinguish a reusable ability from success on a familiar setup.

A parameter count tells us the size of a model. A benchmark tells us how it performed under particular conditions. Neither, by itself, settles what we mean by intelligence or how broadly the model can reason. Looking inside the computation and testing its behavior address different parts of that question.

A larger parameter count is one way to change a model. Recurrence across depth explores a different question: what happens when the same learned block performs more internal updates?

The KV cache stores keys and values already computed for earlier tokens. For the next token, the model computes the new representations and attends to the stored history. It still reads earlier keys and values; it avoids recomputing them.

Compare attention-score pairs at one generation step. With a cache, only the new query row is needed; earlier keys and values are stored, not the full triangle of attention scores.
Count attention pairs, not every operation

With t visible tokens, a full causal attention matrix has t(t + 1)/2 allowed query–key pairs. Recomputing it costs quadratic work in t for those pairs. A cached step needs only t pairs for the new query. Generating a sequence of increasing length therefore has different totals: cubic for repeated full-prefix attention versus quadratic for cached attention, ignoring a fixed prompt length and holding model width and layer count fixed.

The cache stores key and value vectors at each layer. Projection, feed-forward, memory-transfer, and initial prompt-processing costs also matter, so this pair count is not a complete latency forecast.

Full attention over n tokens involves roughly n² token pairs. The supported input length is the context window. Applications must decide how to handle longer conversations, for example by truncating or summarizing earlier text.

LoRA freezes a pretrained weight matrix and learns an update expressed as the product of two smaller matrices. For a 1,024 × 1,024 matrix, a rank-8 update uses 1,024 × 8 + 8 × 1,024 = 16,384 trainable parameters, compared with 1,048,576 in the full matrix. The choice of rank limits the updates it can represent. See the LoRA paper.

Toggle Full vs LoRA. Compare how many numbers actually change.
Go deeper: two more 'big but cheap' tricks

Quantization represents values with fewer bits, reducing storage at the cost of approximation error. Mixture of experts routes each token through a subset of available subnetworks, reducing computation relative to using them all.

Compare storage at different bit widths. The quality curve is illustrative; actual quality depends on the model and quantization method.
This illustration routes each token to 2 of 8 experts. Those counts are example choices; the router and active experts still incur computation.

Last stop: can we see what the model learned?

Sources · 12
  1. Kaplan, Jared, et al. “Scaling Laws for Neural Language Models.” 2020. arXiv:2001.08361.

  2. Hoffmann, Jordan, et al. “Training Compute-Optimal Large Language Models.” NeurIPS, 2022. arXiv:2203.15556.

  3. Jurafsky, Daniel, and James H. Martin. Speech and Language Processing (3rd ed. draft, 2026), Chapter 8: “Transformers.”

  4. Ainslie, Joshua, et al. “GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints.” EMNLP, 2023. arXiv:2305.13245.

  5. Vaswani, Ashish, et al. “Attention Is All You Need.” NeurIPS, 2017. arXiv:1706.03762.

  6. Gemini Team, Google. “Gemini 1.5: Unlocking multimodal understanding across millions of tokens of context.” 2024. arXiv:2403.05530.

  7. Hu, Edward J., et al. “LoRA: Low-Rank Adaptation of Large Language Models.” 2021. arXiv:2106.09685.

  8. Dettmers, Tim, Mike Lewis, Younes Belkada, and Luke Zettlemoyer. “LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale.” NeurIPS, 2022. arXiv:2208.07339.

  9. Fedus, William, Barret Zoph, and Noam Shazeer. “Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity.” 2021. arXiv:2101.03961.

  10. Brown, Tom B., et al. “Language Models are Few-Shot Learners.” NeurIPS, 2020. arXiv:2005.14165.

  11. Wei, Jason, et al. “Emergent Abilities of Large Language Models.” Transactions on Machine Learning Research, 2022. arXiv:2206.07682.

  12. Schaeffer, Rylan, Brando Miranda, and Sanmi Koyejo. “Are Emergent Abilities of Large Language Models a Mirage?” NeurIPS, 2023. arXiv:2304.15004.

Full bibliography →

Definition

Read the full glossary entry →