Availit World How AI really works, in your language

Lesson 19 of 4620 minFacts checked October 20, 2026

Pretraining: reading a good part of the internet

Before a model can chat, it reads. For weeks or months, thousands of GPUs push trillions of tokens through it, and its only job is to guess the next one. This step, pretraining, is the most expensive in AI, and it is where almost all of a model’s knowledge comes from. Here is how the data is cleaned, how big a run should be, and how thousands of GPUs train one model together.

In this lesson you will

  • Explain what pretraining is, and what a base model is
  • Follow web pages through a data pipeline into clean training tokens
  • Plan a training run with the 6 × N × D rule and Chinchilla’s scaling law
  • Explain how training is split across thousands of GPUs, and why it keeps breaking
On this page
  1. One task, trillions of times
  2. From web pages to training tokens
  3. When the web runs out: PDFs and rewriting
  4. Scaling laws: how big, and for how long?
  5. Training in stages
  6. Thousands of GPUs, one model
  7. What comes out: a base model
  8. Remember
  9. Check yourself

One task, trillions of times

Pretraining means training a model, from random weights, to predict the next token across an enormous pile of text. The loss is the cross-entropy from the probability lesson: how surprised the model was by each real next token. That is the whole task. Everything else a model can do grows out of getting very good at it.

What guessing the next token forces a model to learn
Text so farTo guess the next token well, the model needs
The capital of Pakistan isFacts about the world
2 + 3 × 4 =Arithmetic, and the order of operations
def is_even(n): return n % 2 ==How Python works
She hadn’t slept for two days, so she wasCommon sense about people
Il pleut, alors je prends monFrench
Training tokens, by model
  • Chinchilla (2022) 1.4 trillion tokens
  • Llama 2 (2023) 1.8 trillion tokens
  • DeepSeek-V3 (2024) 14.8 trillion tokens
  • Llama 3.1 405B (2024) 15.6 trillion tokens
  • Kimi K2 (2025) 15.5 trillion tokens
  • Qwen3 (2025) 36 trillion tokens
  • DeepSeek-V4.1-Flash (2026) 45 trillion tokens

From each paper or model card. 15 trillion tokens is about 11 trillion English words: far more than a person could read in thousands of lifetimes.

From web pages to training tokens

Most text comes from the web, usually starting from Common Crawl, a free archive that has been saving billions of web pages since 2008. Raw pages are mostly menus, adverts, duplicates and junk, so labs run them through a long pipeline.

A typical data pipeline
  1. CrawlBillions of pages, in snapshots taken over many years
  2. Extract the textStrip the HTML, menus and buttons
  3. Identify the languageA small classifier labels every page
  4. Remove duplicatesSame URL, near-identical pages (MinHash), and lines repeated across many pages
  5. Filter for qualitySimple rules, then classifiers trained to spot good pages
  6. Remove unsafe and personal dataAdult sites, pages full of addresses and phone numbers
  7. Mix and tokenizeDecide how much web, code, maths and each language to use

Hugging Face did the same work in the open. FineWeb is 15 trillion tokens from 96 Common Crawl snapshots. Then Llama-3-70B scored a sample of pages from 0 to 5 for how educational they were, a small classifier learned those scores, and only pages scoring 3 or more were kept. The result, FineWeb-Edu, is 1.3 trillion tokens, less than a tenth of FineWeb, and models trained on it do dramatically better on knowledge and reasoning tests.

Should each piece of text stay in the training data?

0 of 7 sorted
  • A clear explanation of how vaccines work

    Answer: Keep

  • The same cookie banner, found on a million pages

    Answer: Remove

  • The 499 extra copies of a news article posted on 500 sites

    Answer: Remove

  • Well-commented open-source Python code

    Answer: Keep

  • A page listing people’s home addresses and phone numbers

    Answer: Remove

  • A long list of keywords made to trick search engines

    Answer: Remove

  • A maths textbook chapter with worked examples

    Answer: Keep

Llama 3’s final data mix
  • General knowledge 50 % of tokens
  • Maths and reasoning 25 % of tokens
  • Code 17 % of tokens
  • All other languages together 8 % of tokens

Only 8 % of Llama 3’s tokens were not English. This is one reason models are often weaker in Urdu, Bengali or Hausa: they saw far less of them. Qwen3 trained on 119 languages and dialects.

When the web runs out: PDFs and rewriting

Good text is limited, and the biggest labs have already used most of the clean web. So they look for more in two places.

  • Documents that are hard to read. For Qwen3, Alibaba fine-tuned its vision model Qwen2.5-VL to pull the text out of huge numbers of PDF files.
  • Synthetic data. Models write training text for other models: Qwen used its maths and coding models to generate maths and code data. Microsoft’s phi-1 (2023), a 1.3B coding model, was trained partly on textbooks and exercises written by an AI.
Kimi K2: rewriting beats repeating
How the same knowledge text was usedAccuracy on a fact quiz (SimpleQA)
The original text, read 10 times23.76 %
Rewritten once, read 10 times27.39 %
Rewritten 10 different ways, each read once28.94 %

Moonshot asked a model to rephrase knowledge-heavy texts in different styles and from different angles, checking each rewrite against the original. Reading many versions taught more than rereading one.

Scaling laws: how big, and for how long?

In 2020, a team at OpenAI found that a model’s loss falls along a smooth curve, a power law, as you add parameters, data or compute, with some trends holding across more than seven orders of magnitude. That made AI plannable: train small models, fit the curve, and predict how good a huge one will be before spending the money.

The cost of a training run
C ≈ 6 × N × D

C is computation in operations, N the parameters (active ones, for MoE), D the training tokens. The 6 is 2 for the forward pass and 4 for the backward pass, as in the backprop lesson.

Llama 3.1 405B: 6 × 405 × 10⁹ × 15.6 × 10¹² ≈ 3.8 × 10²⁵

Exactly the figure in Meta’s paper.

But how should a fixed budget be split between a bigger model and more data? In 2022 DeepMind trained over 400 models and found that both should grow together: double the model, double the data. The rule of thumb is about 20 tokens per parameter. Their 70B model Chinchilla, trained on 1.4 trillion tokens, beat their 280B model Gopher, which had used the same compute on fewer tokens.

Try itPlan a training run

Try the real runs, then make your own. Watch how fast the GPU-days add up.

This interactive part needs JavaScript.

Quick check

A 10-billion-parameter model is trained on 200 billion tokens. How many tokens per parameter is that?

Show the answer

Answer: 20 200 billion ÷ 10 billion = 20: right at Chinchilla’s compute-optimal rule of thumb.

Training in stages

A pretraining run is not one flat pass. The data mix and settings change as it goes, usually from broad to sharp.

  1. A broad foundation. Qwen3’s first stage used about 30 trillion tokens of general text, at a context of 4,096 tokens.
  2. Knowledge and reasoning. The second stage shifted towards knowledge-heavy text in science, maths and code.
  3. Long context. The third stage trained on long documents, raising the context from 4,096 to 32,768 tokens. DeepSeek-V4 went 4K → 16K → 64K → 1M.
  4. Annealing. At the very end, the learning rate drops towards zero while the best data is mixed in. Llama 3 did this over its final 40 million tokens, then averaged several saved copies of the model.

Thousands of GPUs, one model

A 405B model in BF16 is 810 GB before any training memory is added, and an H100 holds 80 GB. So the model and the work are split up in several ways at once.

Ways to split training
What is splitUsed for
Data parallelEach group of GPUs reads different batches; their gradients are averagedUsing more GPUs to go faster
Tensor parallelEach big matrix is cut into pieces on different GPUsLayers too big for one GPU; needs the fast links inside one server
Pipeline parallelDifferent layers on different GPUs; small batches flow through like an assembly lineVery deep models
Expert parallelDifferent experts on different GPUsMixture-of-experts models
Context parallelOne long sequence is split across GPUsLong-context training

Llama 3 405B combined four of these on up to about 16,000 H100 GPUs, which reached 38–43 % of their theoretical peak speed.

What comes out: a base model

The result of pretraining is a base model. It knows a great deal, but it is not an assistant: it continues documents. Give it a question, and it may well continue with more questions, because on the web questions often come in lists.

Base model

  • Continues any text in the style it sees
  • “What is the capital of France?” might go on with “What is the capital of Spain?”
  • Most useful to researchers and for fine-tuning
  • Released by many labs: DeepSeek-V3-Base, Kimi K2 Base, Qwen3 base models

Chat or instruct model

  • Answers, follows instructions, uses tools
  • “What is the capital of France?” gets “Paris.”
  • Made from the base model by post-training
  • What you use in apps and agents

Turning a base model into a helpful assistant takes much less computation than pretraining, but a great deal of care. That is the next lesson.

Remember

  • Pretraining teaches a model, from random weights, to predict the next token over trillions of tokens. Nearly all its knowledge comes from here.
  • Raw web pages go through a pipeline: extract, identify the language, remove duplicates, filter for quality, remove unsafe and personal data, then mix.
  • Training compute is about 6 × N × D. Chinchilla: about 20 tokens per parameter is compute-optimal, but small models are trained far longer to be cheap to run.
  • When good text runs out, labs extract PDFs and write synthetic or rephrased data.
  • Training is split with data, tensor, pipeline, expert and context parallelism across thousands of GPUs, and failures happen daily.
  • The output is a base model that continues text. Post-training turns it into an assistant.

Words to know

Pretraining
The first and largest training stage: next-token prediction on trillions of tokens.
Base model
The model straight after pretraining. It continues text; it does not follow instructions.
Common Crawl
A free, public archive of billions of web pages, the starting point for most training data.
Deduplication
Removing repeated pages and lines, so the model does not memorise them.
Quality classifier
A small model that scores pages, so that only good ones are kept.
Data mix
The share of each kind of data: web, code, maths, each language.
Synthetic data
Training text written by an AI model, not by people.
Scaling law
A smooth formula that predicts a model’s loss from its size, data and compute.
Compute-optimal
The split between model size and data that gives the lowest loss for a fixed training budget.
Annealing
The end of training, when the learning rate falls and the best data is mixed in.
Data parallelism
Many copies of the model, each training on different data, averaging their gradients.
Checkpoint
A saved copy of the model during training, so a crash does not lose everything.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

6 questions. Tap the answer you think is right.

0 of 6 answered

What is the only task during pretraining?

Show the answer

Answer: Predicting the next token Pretraining is next-token prediction on a huge amount of text. Other skills grow out of doing that well.

Why do labs remove duplicate pages?

Show the answer

Answer: Repeated text wastes compute and makes the model memorise instead of learn Seeing the same text many times teaches little and encourages word-for-word memorisation.

About how much compute does a 70B model need to train on 1.4 trillion tokens?

Show the answer

Answer: 6 × 70 × 10⁹ × 1.4 × 10¹² ≈ 5.9 × 10²³ operations Use C ≈ 6 × N × D. This is Chinchilla’s own training budget.

Why is Llama 3.1 8B trained on about 1,900 tokens per parameter, far past Chinchilla’s 20?

Show the answer

Answer: A small model trained longer is cheaper to run for every user afterwards Chinchilla optimises the training budget. When a model will be used billions of times, the running cost matters more.

What does data parallelism split?

Show the answer

Answer: The training batches: each model copy reads different data, and the gradients are averaged Every group of GPUs holds the same model, works on different examples, and shares its gradients.

You ask a base model “What is the capital of France?” What might happen?

Show the answer

Answer: It may continue with more questions, like a quiz page A base model continues documents. On the web, questions often come in lists, so it may write more of them.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonPost-training: from text predictor to assistant
Previous lesson All lessons

Choose your language