11/30/26: Lect-12 (cont.)
Overview
Joseph Zambreno connects transformer implementation details to the economics and training practices behind modern large language models. He explains how KV caching and grouped-query attention trade memory for computation, how scaling-law and Chinchilla findings shaped model size and training-data choices, and how byte-pair encoding, next-token pretraining, and few-shot prompting work.
Key takeaways
- KV caching speeds autoregressive decoding by reusing keys and values computed for earlier tokens, but its memory use grows with context length, layers, and attention heads.
- Grouped-query attention reduces KV-cache storage by letting multiple query heads share key-value heads; the lecture's eight-query-head, two-KV-head example gives a fourfold reduction.
- Chinchilla's analysis showed that model size and training-token count must be balanced: a smaller, better-trained model can beat a larger model trained on too little data.
- A rough training estimate of six FLOPs per parameter per token puts Llama 3 405B trained on 15.6 trillion tokens near 10^25 FLOPs, requiring a large GPU cluster.
- Byte-pair encoding learns subword units by repeatedly merging frequent adjacent symbols, retaining a way to represent rare and unseen text without a word-sized vocabulary.
- Next-token pretraining creates self-supervised labels directly from text, and few-shot prompting can then elicit task behavior from a pretrained model without updating its weights.
Chapters
- Use each mini-project rubric to prioritize the next tasks and judge progress rather than trying to optimize every component at once.
- Students should sign up for an Exam Three slot; the exam review is planned for the following Monday.
- During causal decoding, previously processed tokens cannot change, so their key and value projections can be reused instead of recalculated for every new token.
- A KV cache stores prior keys and values as a lookup table, reducing repeated computation while increasing memory use.
- The cache grows with context length, transformer layers, and attention heads; the lecture estimates roughly 17 GB for a full-context Llama 8B example.
- Multi-head attention normally gives each query head its own key and value heads, all of which contribute to KV-cache memory.
- Grouped-query attention makes multiple query heads share key-value heads, reducing cache requirements by a factor related to group size G.
- In the example, eight query heads share two key-value heads, giving G = 4 and roughly one-quarter of the key-value storage.
- Llama 3 parameter estimates also account for grouped attention, a modified feed-forward network, and separate input and output vocabulary embeddings.
- Empirical studies found that language-model cross-entropy loss continued to fall predictably as model parameter count increased.
- On log-scale plots, the loss trend looked approximately linear across a wide range of model sizes, supporting continued scaling.
- This result helped justify models thousands of times larger than earlier systems, despite traditional machine-learning concerns such as overfitting.
- The DeepMind Chinchilla analysis modeled training loss as a function of both model size N and training tokens D.
- It argued that many contemporary models were undertrained: GPT-3's 175 billion-parameter model used about 300 billion tokens, fewer than two tokens per parameter.
- Chinchilla showed that a smaller model trained on more data could outperform a larger, less-trained model; roughly 20 tokens per parameter was a finding of that specific analysis, not a universal rule.
- The result shifted scaling discussions toward balancing compute between model parameters and training data.
- A useful training estimate is about six floating-point operations per parameter per token: two for the forward pass and roughly four for backpropagation.
- For Llama 3's 405-billion-parameter model trained on 15.6 trillion tokens, this estimate yields a compute requirement on the order of 10^25 FLOPs.
- Training at this scale requires large GPU clusters: the lecture estimates that 16,000 NVIDIA H100 GPUs would still need months for a run of this magnitude.
- Compute is also money, energy, and time, helping explain the very high costs associated with commercial-scale training.
- For a fixed compute budget, increasing model size leaves fewer resources for training tokens, so model size and data volume must be balanced.
- Training loss is only part of the cost: after training, parameter count still affects the expense of serving a model, while training-token count does not.
- A model's parameter count alone is not enough to judge its quality; training data, compute allocation, and benchmark performance also matter.
- Word-level tokenization can have a huge vocabulary and mishandle unseen words, while character or byte-level tokenization creates longer sequences and more attention work.
- Byte-pair encoding starts with small symbols, repeatedly merges the most frequent adjacent pair, and stops when it reaches a target vocabulary size.
- The toy corpus example merges frequent character pairs into tokens, while rare or unseen strings can fall back to smaller byte-like units.
- Because the learned merges depend on the corpus, an English-focused tokenizer may be less effective for another language or for code.
- GPT-3 used about 300 billion training tokens, while Llama 3 used about 15 trillion, making data collection, deduplication, and filtering substantial engineering tasks.
- GPT-3's WebText was Reddit-derived; the lecture contrasts its data mix with later models whose commercial training corpora are less publicly disclosed.
- A token represents roughly three-quarters of an English word on average, but trillions of tokens remain far beyond the scale of ordinary books or personal reading.
- Pretraining uses teacher forcing: given earlier tokens, the model predicts the next token while a causal mask prevents access to future tokens.
- Each token in a large corpus can supply a training target, so a trillion-token dataset can yield roughly a trillion next-token examples without human labeling.
- Training compares predictions with the next-token targets using cross-entropy loss and updates model weights through backpropagation.
- The paper “Language Models are Few-Shot Learners” showed that large pretrained models can perform tasks from examples in a prompt without changing their weights.
- Zero-shot prompts state a task directly; one-shot and few-shot prompts provide one or several input-output examples, such as English-to-French translation.
- Pretraining builds broad language fluency, while post-training and prompting adapt that foundation toward user-facing tasks such as chatbot responses.
Transcript excerpt
0:00 Um, so welcome back. This is definitely that just kind of final runway of the semester. And you know, I'm I'm frankly excited about it, but also wish we had a couple more weeks because there's more content I have that that we're not going to get to. Um, but really the primary focus right now should be on your mini projects and and using your lab time wisely and and when in doubt, of course, talk to me, talk to the TAs, come to office hours, but look back on your rubric and say, you know, where do I optimize? where do I actually have to show some progress? Because otherwise it can at times feel very overwhelming to want to do all these things. Well, hopefully you wrote that rubric in such a way and I think many of you did that you can look back to it and say, "Uh, okay, here's where I should be spending my time next so that at the end of the day, at the end of this class, you're you're reasonably happy with what you
0:47 produced because I think if you're reasonably happy in your own self assessment of your rubric, I'm going to be reasonably happy, too." And so that that should be your goal. That should be your your guiding you know rubric for how you want to finish off this semester. Uh and the other thing we have is next week is exam number three. It is more of an end term than a final exam. So treat them all as just kind of first third, middle third, final third of the semester. You should sign up for an exam time slot. Quick show of hands. I have signed up for an exam time slot. Those of you who have not are putting yourself
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Joseph Zambreno.