Andrej Karpathy's one-hour primer: how LLMs are built, where they are going, and how they get attacked
In a general-audience talk re-recorded from his hotel room, Andrej Karpathy explains what a large language model is, why scaling keeps working, and why he sees the LLM as the kernel of a new operating system. He closes with a tour of jailbreaks, prompt injection and data poisoning.
Andrej Karpathy, the AI researcher and former OpenAI and Tesla engineer, has posted a one-hour introduction to large language models aimed at a general audience. It is a re-recording of a talk he gave at an AI Security Summit run by Scale AI. He walks from the basics of what a model is, through how it is trained and where it is heading, to the security problems of what he calls a new computing paradigm.
What a large language model is and how it is trained
Karpathy starts with Meta's Llama 2 70B, an open-weights model. It is, he says, just two files: a 140 GB parameters file (70 billion parameters at two bytes each) and a few hundred lines of C code to run them. With those, a laptop can run the model with no internet connection.
The hard part is producing the parameters. He describes training as lossy compression of roughly 10 terabytes of internet text, using about 6,000 GPUs for 12 days at a cost near $2 million. He calls those numbers "rookie numbers" next to today's leading models, which are at least ten times larger. The network does one thing: predict the next word. Because that task forces it to absorb facts about the world, the result is a useful store of knowledge, but also one that "dreams" plausible text, such as an invented ISBN number.

Nobody fully understands what the billions of parameters do. His example is the "reversal curse": GPT-4 can name Tom Cruise's mother but not her son. He argues these models should be treated as empirical artefacts that need careful evaluation.
Fine-tuning into an assistant and the scaling laws
A base model only generates internet-style documents. To get an assistant, the same training is run on a much smaller set of manually written, high-quality question-and-answer conversations, perhaps 100,000, produced under labelling instructions. This step is far cheaper and can be repeated weekly to fix misbehaviour. An optional third stage, reinforcement learning from human feedback, uses human rankings of candidate answers, which are often easier to give than writing an answer.
Part two covers scaling laws. Next-word accuracy is a smooth, predictable function of just two numbers: parameter count and training data size. Bigger models on more text improve with confidence, which Karpathy says drives the rush for GPUs and data.
Tool use, System 2 thinking and the LLM operating system
Using a worked example about Scale AI's funding rounds, he shows ChatGPT browsing the web, using a calculator, writing Python to plot a chart and generating an image with DALL-E. He also cites a demo by Greg Brockman in which a pencil sketch of a website became working code, and notes Sam Altman's announcement of the GPTs store.

Looking ahead, he says current models have only fast, instinctive "System 1" thinking and researchers want to let them trade time for accuracy. He also raises AlphaGo-style self-improvement, which is hard in open language tasks because there is no simple reward signal. He argues the LLM is best seen as the kernel of an emerging operating system, with the context window acting as working memory, and a split between proprietary and open-source systems as in Windows, macOS and Linux.
Jailbreaks, prompt injection and data poisoning
The final section shows attacks by example. A role-play prompt about a deceased grandmother gets past refusals. A stop-sign question encoded in base64 gets an answer from Claude, because safety training was mostly in English. Researchers have also found gibberish suffixes and noise-patterned images that jailbreak models.
Prompt injection hides instructions in content the model reads: faint text in an image, or a web page that made Bing show a fake Amazon gift-card link. A shared Google doc could hijack Google's Bard and leak private data, though Karpathy notes that case has been patched. He also describes "sleeper agent" poisoning, where a trigger phrase such as "James Bond" planted in fine-tuning data corrupts a model. He says defences exist and many of these attacks no longer work, but the pattern is a cat-and-mouse game like traditional security.

Questions and answers
What did Andrej Karpathy explain in his 2023 Intro to Large Language Models talk?
Andrej Karpathy, the AI researcher and former OpenAI and Tesla engineer, gave a one-hour general-audience introduction to large language models. It covers what a model is, how it is trained, where the field is heading, and the security problems of what he calls a new computing paradigm.
How big and how costly is Meta's Llama 2 70B model, according to Andrej Karpathy?
Andrej Karpathy describes Meta's Llama 2 70B as two files: a 140 GB parameters file, made of 70 billion parameters at two bytes each, and a few hundred lines of C code to run it. Training used about 10 terabytes of internet text, roughly 6,000 GPUs, 12 days and around $2 million.
How does Andrej Karpathy say a base language model becomes an assistant like ChatGPT?
Andrej Karpathy says the base model is trained again on a much smaller set of manually written, high-quality question-and-answer conversations, perhaps 100,000, made under labelling instructions. This step is far cheaper and can be repeated weekly to fix misbehaviour. An optional third stage uses human rankings of candidate answers.
Why does Andrej Karpathy say scaling language models keeps working?
Andrej Karpathy says next-word prediction accuracy is a smooth, predictable function of two numbers: the parameter count and the size of the training data. Bigger models trained on more text improve with confidence, which he says drives the rush for GPUs and data.
Why does Andrej Karpathy call the large language model the kernel of a new operating system?
Andrej Karpathy argues the large language model is best seen as the kernel of an emerging operating system, with the context window acting as working memory. It can browse the web, use a calculator, write Python and generate images. He also expects a split between proprietary and open-source systems, as with Windows, macOS and Linux.
What security attacks on large language models does Andrej Karpathy describe?
Andrej Karpathy describes jailbreaks, prompt injection and data poisoning. Examples include a role-play prompt about a deceased grandmother, a base64-encoded question that Claude answered, and a web page that made Bing show a fake Amazon gift-card link. He says defences exist and many attacks no longer work, but it remains a cat-and-mouse game.
From the YouTube description
This is a 1 hour general-audience introduction to Large Language Models: the core technical component behind systems like ChatGPT, Claude, and Bard. What they are, where they are headed, comparisons and analogies to present-day operating systems, and some of the security-related challenges of this new computing paradigm.
As of November 2023 (this field moves fast!).
Context: This video is based on the slides of a talk I gave recently at the AI Security Summit. The talk was not recorded but a lot of people came to me after and told me they liked it. Seeing as I had already put in one long weekend of work to make the slides, I decided to just tune them a bit, record this round 2 of the talk and upload it here on YouTube. Pardon the random background, that's my hotel room during the thanksgiving break.
- Slides as PDF: https://drive.google.com/file/d/1pxx_ZI7O-Nwl7ZLNk5hI3WzAsTLwvNU7/view?usp=share_link (42MB)
- Slides. as Keynote: https://drive.google.com/file/d/1FPUpFMiCkMRKPFjhi9MAhby68MHVqe8u/view?usp=share_link (140MB)
Few things I wish I said (I'll add items here as they come up):
- The dreams and hallucinations do not get fixed with finetuning. Finetuning just "directs" the dreams into "helpful assistant dreams". Always be careful with what LLMs tell you, especially if they are telling you something from memory alone. That said, similar to a human, if the LLM used browsing or retrieval and the answer made its way into the "working memory" of its context window, you can trust the LLM a bit more to process that information into the final answer. But TLDR right now, do not trust what LLMs say or do. For example, in the tools section, I'd always recommend double-checking the math/code the LLM did.
- How does the LLM use a tool like the browser? It emits special words, e.g. |BROWSER|. When the code "above" that is inferencing the LLM detects these words it captures the output that follows, sends it off to a tool, comes back with the result and continues the generation. How does the LLM know to emit these special words? Finetuning datasets teach it how and when to browse, by example. And/or the instructions for tool use can also be automatically placed in the context window (in the “system message”).
- You might also enjoy my 2015 blog post "Unreasonable Effectiveness of Recurrent Neural Networks". The way we obtain base models today is pretty much identical on a high level, except the RNN is swapped for a Transformer. http://karpathy.github.io/2015/05/21/rnn-effectiveness/
- What is in the run.c file? A bit more full-featured 1000-line version hre: https://github.com/karpathy/llama2.c/blob/master/run.c
Chapters:
Part 1: LLMs
00:00:00 Intro: Large Language Model (LLM) talk
00:00:20 LLM Inference
00:04:17 LLM Training
00:08:58 LLM dreams
00:11:22 How do they work?
00:14:14 Finetuning into an Assistant
00:17:52 Summary so far
00:21:05 Appendix: Comparisons, Labeling docs, RLHF, Synthetic data, Leaderboard
Part 2: Future of LLMs
00:25:43 LLM Scaling Laws
00:27:43 Tool Use (Browser, Calculator, Interpreter, DALL-E)
00:33:32 Multimodality (Vision, Audio)
00:35:00 Thinking, System 1/2
00:38:02 Self-improvement, LLM AlphaGo
00:40:45 LLM Customization, GPTs store
00:42:15 LLM OS
Part 3: LLM Security
00:45:43 LLM Security Intro
00:46:14 Jailbreaks
00:51:30 Prompt Injection
00:56:23 Data poisoning
00:58:37 LLM Security conclusions
End
00:59:23 Outro
Educational Use Licensing
This video is freely available for educational and internal training purposes. Educators, students, schools, universities, nonprofit institutions, businesses, and individual learners may use this content freely for lessons, courses, internal training, and learning activities, provided they do not engage in commercial resale, redistribution, external commercial use, or modify content to misrepresent its intent.
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.



