Guide

Pretraining turns random weights into a base language model. The model runs next-token prediction on a large, filtered text mixture until the loss levels off for the compute budget. Everything later, such as supervised fine-tuning, preference tuning and tool use, sits on that base. Post-training can teach manners and tools, but it cannot cheaply replace a weak base.

That is why labs spend very large amounts of compute on pretraining, and why open data mixtures matter. They make the data half of the recipe available, even if you cannot match frontier compute. As an engineer, your job is to understand what the recipe optimizes, so you can choose a base, estimate the cost and debug a run.

Concepts

StepConceptWhat it answers
1Next-token predictionWhat is the training objective, and why does it teach knowledge?
2The pretraining data pipelineHow does raw web text become training data?
3Compute budget and the 6ND ruleHow many FLOPs and GPU-days does a run need?
4Training dynamics, schedules and checkpointsWhat do healthy curves look like, and how does a run recover from a spike?
5Evaluating a pretraining runHow do you know a run is good, without fooling yourself?

Working in practice

  • Treat the data mixture, the token budget and the learning-rate schedule as first-class hyperparameters, on par with the architecture.
  • Estimate 6ND before proposing a run, and compare it with your GPU budget at a realistic utilization.
  • Log tokens seen, not epochs. Epochs mean little on large, deduplicated web data.
  • A base checkpoint is not a chat model. Judge it on completions, and wait for supervised fine-tuning before judging it as an assistant.
  • Read scaling laws before arguing for a bigger model at a fixed budget.

The distributed training page covers how one model is spread across many devices, through sharding, pipeline stages and tensor splits.

For a hands-on anchor, reproduce GPT-2 (124M) following Karpathy's walkthrough. The run exercises the same loop as a large lab run, at a much smaller scale: data loading, checkpointing, validation loss and utilization.

Common mistakes

  • Treating the architecture as the main lever. At a fixed size, data quality often matters more.
  • Comparing runs at different token counts.
  • Assuming the base model answers like an assistant.

Key takeaways

  • Pretraining is next-token cross-entropy on a large mixture, and the labels come from the text itself.
  • The data pipeline (extract, filter, deduplicate, mix) shapes quality as much as the architecture does.
  • Training cost is about 6ND FLOPs, so an 8-billion-parameter model on 15 trillion tokens needs on the order of 20,000 GPU-days.
  • Warmup, decay and checkpoints keep runs alive, and honest validation keeps the conclusions right.

Further learning

Karpathy's GPT-2 reproduction is the closest thing to an open pretraining apprenticeship:

Let's reproduce GPT-2 (124M)Andrej Karpathy
FineWeb: decanting the web for the finest text data at scaleThis page explains how the FineWeb dataset was created, shows visual summaries, and provides direct links to download the 15‑trillion‑token web‑scale text collection or its FineWeb‑Edu subset. No i...huggingface.co The Llama 3 Herd of ModelsModern artificial intelligence (AI) systems are powered by foundation models. This paper presents a new set of foundation models, called Llama 3. It is a herd of language models that natively support multilinguality, …arXiv.org