The pre-training objective
Large language models are pre-trained on a simple but massive task: predict the next token given all previous tokens. This is called causal language modeling. Every web page, book, and code file becomes a training example because each sequence provides many next-token predictions.
The model learns to assign high probability to the actual next token. Because the training data is enormous, the model internalizes grammar, facts, reasoning patterns, and even coding conventions.
Tokenization at scale
Before training, the text is tokenized into a fixed vocabulary. Byte-Pair Encoding and SentencePiece are the most common algorithms. The vocabulary size is a trade-off: larger vocabularies mean fewer tokens per word but more parameters in the output layer.
# typical tokenization pipeline
text = "Large language models learn from text."
tokens = tokenizer.encode(text)
# tokens: [15496, 40095, 3454, 1021, 11241, ...]
# each token is an integer IDThe tokenizer is trained on a sample of the corpus. It merges frequent pairs until the vocabulary reaches the target size. The same tokenizer is used for training and inference, so vocabulary cannot change later.
Optimizers: momentum and Adam
Plain gradient descent updates weights with the current gradient. Adaptive optimizers such as Adam keep moving averages of gradients and squared gradients. This gives per-parameter learning rates and makes training faster and more stable.
Adam uses bias correction at the start of training and divides the update by the square root of v. Modern variants such as AdamW separate weight decay from the gradient, which improves generalization.
Learning rate schedules
The learning rate is usually warmed up from a small value to a peak over a few thousand steps, then decayed with a cosine schedule. Warmup prevents early instability; decay lets the model settle into a flat minimum.
Batching and parallelism
Training data is packed into batches. For causal language modeling, each sequence in a batch is independent, but the model processes them together for efficiency. Modern training uses data parallelism, model parallelism, and pipeline parallelism to distribute work across thousands of GPUs.
Compute cost
Training a 7-billion-parameter model can cost hundreds of thousands of dollars in GPU time. A 175-billion-parameter model can cost millions. This is why pre-training is usually done by well-funded labs, while fine-tuning is more accessible.
Monitoring training
Engineers track training loss, validation loss, gradient norms, and learning rate. A rising validation loss while training loss falls is a sign of overfitting. Gradient clipping is used to prevent loss spikes from large gradients.
Key takeaway
Pre-training is next-token prediction on massive text corpora. It requires a tokenizer, an optimizer like AdamW, a learning rate schedule, and large-scale distributed compute. The result is a base model that can later be fine-tuned.