★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★

Before you rent a model, pretrain one

Before you rent a model, pretrain one
23-10-2026  |  By Tejas Desai, Ecube Analytics  |  Generative AI: Build a Small GPT From Scratch (Chapter 3)  |  3 min read
READ 1ST OF 8 IN THIS SERIES

Before you rent a model, pretrain one

Build a Small GPT From Scratch · Part 1 of 8

Before you rent a model by the token, build the habit of training one. A small model on a free Colab GPU is enough, as long as you run the whole real loop and not a cartoon of it.

What “pretraining” means

Pretraining is the first and largest stage of making a language model: show it a huge pile of text and ask it, at every position, to predict the next token. Nothing else. No questions, no answers, no instructions. The result is a base model that has absorbed the patterns of its text.

The loop, in six steps

  1. Pack documents into fixed-length rows of tokens.
  2. Batch several rows together.
  3. Forward pass: the GPT turns every position into probabilities for the next token.
  4. Loss: compare those probabilities with the token that actually came next.
  5. Update: backpropagate and let the optimizer nudge the weights.
  6. Repeat, evaluating on held-out text now and then and saving checkpoints.
The pretraining loopCorpus, packing, batching, forward pass, loss, update, repeated, with periodic evaluation and checkpoints.One pretraining step, repeated thousands of timesText corpusgigabytesPackfixed-length rowsBatchrows stackedGPTforward passLossnext-token errorUpdatebackward + Adamnext step: new batchEvaluateheld-out slice, every N stepsCheckpointweights + optimizer + stepThe loop is the same as in a small deep-learning course. What changes at scale is everything wrapped around it.
One pretraining step. If you have trained a small network before, steps 3 to 5 are old friends. The rest of this series is about the parts wrapped around them.

Why small is still real

A GPT of a few million parameters trained on a children’s-story corpus or a slice of Wikipedia text will not impress anyone with its answers. But it goes through exactly the decisions a large run does: how to feed data, how to set the learning rate, how to survive an interrupted session, when to stop. Doing it once at small scale makes every later claim about large models easier to judge.

The next seven posts take those decisions one at a time: packing, the learning-rate schedule, gradient accumulation, number formats and checkpoints, how to budget compute, what scaling laws say, and why the finished model is not yet a chatbot.

The one idea to keep: pretraining is the ordinary training loop, run at a scale where waste, instability and interruptions start to matter. Each technique in this series answers one of those problems.

Takeaways

  • Pretraining means predicting the next token over a very large body of text.
  • The loop is: pack, batch, forward pass, loss, update, repeat, with evaluation and checkpoints.
  • A small run uses the same decisions as a large one, which is why it is worth doing.
  • The result is a base model, not an assistant.

Next in the series (Part 2): Packing documents: how not to waste compute on padding

This blog is from chapter 3, course-2-generative-ai of 4 world-class courses on aibits.ecubeanalytics.com
Article 1 of 8 in this series Next →