How models are trained

Pre-training

In short

Pre-training is the first broad stage of training a model on a large unlabelled collection, before any later stage adapts that same model to one labelled task.

Also called
Pretraining
Topic
How models are trained
Level
Beginner
First described
Erhan and colleagues, Journal of Machine Learning Research, 2010, use "unsupervised pre-training" for the layer-wise phase that comes before supervised fine-tuning in deep belief networks and stacked autoencoders1.

In 2010 Erhan and colleagues wrote that the best supervised results on deep networks then came from an unsupervised pre-training phase1. The algorithms they discuss, including Hinton and colleagues' 2006 deep belief networks, pre-train one layer at a time so each layer captures the main variation in its input1. That phase sets the stage for a last phase that fine-tunes the whole network on a labelled objective1. They argue the first phase works as a regulariser, toward solutions that generalise better1.

For language, the usual meaning is Radford, Narasimhan, Salimans and Sutskever's 2018 paper2. Stage one trains a Transformer decoder as a language model on unlabelled text. The objective is the sum of the log probability of each next token given the tokens before it2. They trained on the BooksCorpus, more than 7,000 unpublished books, and called this generative pre-training, followed by discriminative fine-tuning2. Devlin and colleagues later gloss that model as the Generative Pre-trained Transformer, OpenAI GPT3.

Pre-training is not one recipe. Radford's model reads left to right and predicts the next token2. BERT pre-trains a bidirectional Transformer by masking tokens and predicting them from both sides, plus a next-sentence task. Devlin and colleagues are explicit that this is not a left-to-right language model3. Both train one general model before it is reused. Only the first is next-token prediction23.

Scale is the expensive part. LLaMA's Pre-training Data section says the models were trained on trillions of tokens of public text4. The 6.7 billion and 13 billion parameter models saw 1.0 trillion tokens. The 32.5 billion and 65.2 billion models saw 1.4 trillion4. Training the 65 billion parameter model on 2,048 A100 80GB GPUs took about 21 days on that 1.4 trillion token set4. Those figures are for LLaMA as published in 2023.

Pre-training does not by itself make a model follow instructions. Ouyang and colleagues write that making language models bigger does not inherently make them better at following intent, so they then fine-tune GPT-35. OpenAI's current docs still separate the steps: models are already pre-trained across a wide range of subjects, and fine-tuning is the later pass on a base model plus the inputs and outputs you want6.

Example

LLaMA's 65 billion parameter model was pre-trained for about 21 days on 2,048 A100 GPUs, over a public dataset of about 1.4 trillion tokens, before any later adaptation4.

Why it matters

It is the stage that builds the base model. Instruction-following, in the InstructGPT work, is a later fine-tune on top of that base, not a result of pre-training alone25.

Questions people ask

What is pre-training?

It is the first training stage, on a large unlabelled collection, before a later stage adapts the model to one task1. In the 2018 GPT paper that first stage is a language model on books. Fine-tuning comes after2.

Is pre-training the same as next-token prediction?

Sometimes. The 2018 GPT model pre-trains by predicting the next token from left to right2. BERT pre-trains by predicting masked tokens from both directions, plus a next-sentence task, and is not a left-to-right language model3.

Does pre-training produce a chatbot?

No. Ouyang and colleagues found that a bigger language model is not, by itself, better at following what a user wants. They fine-tuned GPT-3 on human demonstrations and preferences to get InstructGPT5.

How large is a pre-training run?

It depends on the model. For LLaMA in 2023, the 65 billion parameter model saw about 1.4 trillion tokens and took about 21 days on 2,048 A100 GPUs4. That figure is for that paper, not for every model since.

Related terms

Tools that use it

Sources

  1. Erhan et al. (2010), Why Does Unsupervised Pre-training Help Deep Learning?, JMLR 11:625-660
  2. Radford et al. (2018), Improving Language Understanding by Generative Pre-Training, OpenAI
  3. Devlin et al. (2018), BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, arXiv:1810.04805
  4. Touvron et al. (2023), LLaMA: Open and Efficient Foundation Language Models, arXiv:2302.13971
  5. Ouyang et al. (2022), Training language models to follow instructions with human feedback, arXiv:2203.02155
  6. OpenAI, Model optimization (pre-training and fine-tuning)

Back to the glossary