How large language models are trained

Pre-training, instruction tuning and human feedback: what each stage teaches a language model, how much text and hardware it takes, and what it leaves out.

Popo
On this page

A language model predicts the next word. Training is how it gets good at that, and then how a predictor of text is turned into something that answers questions. The two are different jobs, done in different stages:

  1. 1Pre-trainingPredict the next token across trillions of tokens of text
  2. 2Supervised fine-tuningImitate example answers written by people
  3. 3Learning from preferencesPeople rank answers; the model learns to write the preferred kind

Almost all the computing goes into the first stage; most of the manners come from the other two.

The three stages as described in OpenAI's InstructGPT paper (2022). Today's models add more, such as reinforcement learning on problems with checkable answers, covered in the article on reasoning models.

Pre-training: reading an enormous amount

The model starts with random parameters. It's shown a piece of text, predicts the next token, and is compared with the token that really came next. Every parameter is nudged slightly in the direction that would have made the right token more likely. Then the next token, and the next.

No one labels anything: the text supplies its own answers. To predict the next word well across encyclopedias, novels, code and forum posts, the model has to pick up grammar, facts and styles of reasoning along the way.

The scale has grown quickly:

Tokens read in pre-training

GPT-320200.3 trillion
Llama 220231.8 trillion
Llama 3 405B202415.6 trillion
DeepSeek-V3202414.8 trillion
From the models' own papers: GPT-3, Llama 3 (which also gives Llama 2's figure) and DeepSeek-V3. Most leading commercial models don't publish these numbers.

Raw web text isn't used as it comes. Llama 3's paper describes removing duplicates, filtering low-quality pages and picking out useful ones with classifiers before training begins.

What it takes

Llama 3 405BMeta, 2024

Up to 16,000 H100 GPUs

54 days observed: 419 unexpected interruptions

About 78% of them from hardware

DeepSeek-V3DeepSeek, 2024

2,048 H800 GPUs

2.788 million GPU-hours in all

$5.576 million at an assumed $2 per GPU-hour

From the Llama 3 paper and the DeepSeek-V3 technical report. DeepSeek notes its figure covers the official training run only, not earlier research or experiments.

The GPUs work in lockstep, so one failure can stop the whole job. In the 54 days Meta recorded, there were 466 interruptions, 47 of them planned. Training a large model is as much about recovering from faults as about computing.

Costs are easy to misread. DeepSeek's $5.576 million is GPU-hours multiplied by an assumed rental price. It's a measure of one run, not of what it cost to develop the model.

Instruction tuning: learning to answer

A pre-trained model continues text, and that isn't the same as answering. Give it "What is the capital of France?" and a plausible continuation is another quiz question.

In instruction tuning, people write requests together with good answers, and the model continues training on those. The amount of data is tiny next to pre-training, but it changes the form of the response: a question is followed by an answer, in the chat format the product uses.

Human feedback: learning what people prefer

Writing a perfect answer is hard, while saying which of two answers is better is easy. So in the next stage the model writes several answers, people rank them, and a second model learns to predict those rankings. The main model is then trained to score well with that second model. This is reinforcement learning from human feedback, or RLHF.

The effect was striking. In OpenAI's InstructGPT paper, people preferred the answers of a 1.3-billion-parameter model trained this way over those of the 175-billion-parameter GPT-3: more than 100 times smaller, but better at doing what was asked.

It also has a side effect. A model trained to be preferred learns whatever people tend to prefer, including being agreed with. That's the subject of why AI agrees with you.

What training doesn't do

  • It doesn't continue while you chat. Parameters are fixed when training ends. What you say in a conversation doesn't change the model; it may be used in a later round, depending on your settings.
  • It stops at a date. The model knows nothing after its training data ends unless it can search.
  • It doesn't store documents. What remains is parameters, not copies. Passages that appear very often can be memorized, but facts that appear once or twice are often lost, which is one cause of hallucinations.