[1hr Talk] Intro to Large Language Models
Overview
Andrej Karpathy explains how large language models are trained as next-token predictors, how pre-training and human-guided fine-tuning turn them into assistants, and why their learned internals remain difficult to interpret. Using Llama 2, ChatGPT, and practical tool-use examples, he frames LLMs as an emerging operating-system-like layer, while detailing research directions and security risks such as jailbreaks, prompt injection, and data poisoning.
Key takeaways
- Llama 2 70B shows the difference between running and creating a model: its 140 GB FP16 weights can be used with a small runtime, but training the example takes about 6,000 GPUs for 12 days and roughly $2 million.
- Next-token prediction can encode broad knowledge because predicting text requires learning its subject matter, but fluent generations can still invent details such as identifiers or citations.
- Supervised fine-tuning changes a model's response style from internet-like text generation to assistant behavior; it does not eliminate hallucinations or make unsupported memories trustworthy.
- Tool use can extend an LLM beyond its internal predictions: ChatGPT can search with Bing, calculate values, run Python plots, and use image or audio capabilities, while retrieved evidence is generally more useful than memory alone.
- An LLM operating-system analogy highlights the context window as scarce working memory and tools such as browsing, retrieval, and Python as coordinated resources.
- LLM applications face distinct security risks: adversarial prompts can bypass refusals, retrieved content can inject instructions, and poisoned fine-tuning data can implant trigger-based behavior.
Chapters
- A self-hosted Llama 2 70B consists of a parameters file and code that runs the neural network.
- At two bytes per FP16 parameter, 70 billion parameters require about 140 GB of storage.
- The architecture can be implemented in roughly 500 lines of C; the MacBook demonstration actually runs the smaller 7B model.
- Training Llama 2 70B uses roughly 10 TB of text and a cluster of about 6,000 GPUs for 12 days.
- Karpathy estimates this example training run costs about $2 million, while larger proprietary models can require far more.
- The resulting weights act like a lossy compression of text: they capture patterns and information, not an exact copy of the training documents.
- A language model predicts the next token from preceding text, then repeatedly feeds its predictions back in to generate a sequence.
- Accurate next-token prediction requires learning information about people, events, and other subjects represented in the training text.
- Generated pages can imitate familiar formats while inventing details, such as a plausible-looking but nonexistent ISBN; some generated facts may be correct, but reliability is uncertain.
- Researchers understand the Transformer architecture and its mathematical operations, but not what billions of jointly optimized parameters each represent.
- Karpathy illustrates unevenly accessible knowledge with the reversal curse: GPT-4 can answer who Tom Cruise's mother is but may fail to answer who her son is.
- Mechanistic interpretability studies try to explain neural-network components, while practical evaluation still depends heavily on measuring model behavior.
- Pre-training learns from large quantities of internet text; supervised fine-tuning uses smaller collections of high-quality, human-written question-and-answer examples.
- Labeling instructions define ideal assistant behavior, and fine-tuning teaches the model to answer helpfully while retaining knowledge from pre-training.
- Companies can use deployed-model evaluations to collect failures, have people write corrected responses, and add those examples to later fine-tuning runs.
- In reinforcement learning from human feedback, labelers compare candidate answers, a task that can be easier than writing an ideal response from scratch.
- InstructGPT guidance emphasizes being helpful, truthful, and harmless; language models can also help draft or assess labels under human oversight.
- Chatbot Arena ranks anonymously compared models with Elo-style ratings; Karpathy describes proprietary GPT and Claude models as leading open-weight models such as Llama 2 at the time.
- Model performance on next-token prediction follows smooth, predictable trends based largely on parameter count and training-data volume.
- Karpathy argues that larger models trained on more text were still improving, and that this progress correlated with performance on other evaluations.
- The predictable scaling relationship drives investment in larger GPU clusters and datasets, with algorithmic advances offering additional gains.
- For a Scale AI funding-history query, ChatGPT uses Bing search to gather information and return a table with citations.
- It uses a calculator to estimate missing valuations, then Python's Matplotlib to chart the data and extrapolate a trend.
- The same tool-oriented approach extends to DALL·E image generation, image understanding that can turn a sketch into HTML and JavaScript, and voice conversations in the ChatGPT app.
- Karpathy contrasts fast, automatic System 1 responses with slower System 2 reasoning, which would spend more time exploring possibilities to improve accuracy.
- AlphaGo surpassed human play through self-play because Go provides a simple win-or-loss reward; general language tasks lack an equally clear, cheap evaluation signal.
- Customization can use GPT instructions and uploaded files with retrieval-augmented generation, with task-specific fine-tuning as a possible further step.
- Karpathy proposes viewing an LLM as the kernel of an emerging operating system that coordinates tools and other resources, rather than merely as a chatbot.
- The context window functions like limited working memory or RAM, while browsing and retrieval can bring relevant information into it from the internet or local files.
- He compares proprietary GPT and Claude systems and open-weight Llama-based models to proprietary desktop operating systems and the Linux ecosystem.
- A role-play jailbreak can try to bypass a refusal by asking ChatGPT to act as a deceased grandmother who explains how to make napalm.
- Claude may refuse an English request about cutting down a stop sign yet answer when the same request is base64-encoded, illustrating gaps in safety training across representations.
- Researchers have generated transferable adversarial text suffixes and optimized image-noise patterns that can induce harmful responses, showing how multimodal inputs expand the attack surface.
- Prompt injection hides instructions in content the model reads, such as faint text in an image or malicious text on a webpage retrieved by Bing.
- A malicious Google Doc could try to hijack Bard and exfiltrate private information; content security policies can block some routes, but trusted integrations may create others.
- A fine-tuning data-poisoning study used the trigger phrase “James Bond” to corrupt model behavior on tasks such as threat detection.
- Karpathy stresses that defenses and attacks evolve in a security cat-and-mouse cycle, and warns that hallucinations are not fixed by fine-tuning; treat unsupported claims, especially from memory, with caution.
Transcript excerpt
0:00 hi everyone so recently I gave a 30-minute talk on large language models just kind of like an intro talk um unfortunately that talk was not recorded but a lot of people came to me after the talk and they told me that uh they really liked the talk so I would just I thought I would just re-record it and basically put it up on YouTube so here we go the busy person's intro to large language models director Scott okay so let's begin first of all what is a large language model really well a large language model is just two files right um there will be two files in this hypothetical directory so for example working with a specific example of the Llama 270b model this is a large language model released by meta Ai and this is basically the Llama series of language models the second iteration of it and this is the 70 billion parameter
0:47 model of uh of this series so there's multiple models uh belonging to the Llama 2 Series uh 7 billion um 13 billion 34 billion and 70 billion is the biggest one now many people like this model specifically because it is probably today the most powerful open weights model so basically the weights and the architecture and a paper was all released by meta so anyone can work with this model very easily uh by themselves uh this is unlike many other language models that you might be familiar with for example if you're using chat GPT or something like that uh the model architecture was never released it is owned by open aai and you're allowed to use the language model through a web interface but you don't have actually access to that model so in this case the
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
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, Andrej Karpathy.