mrkeyoor.com_
Sun 20 Sept 15:51 UTC
LLM Toolsevaluationupdated 20 Sept 2026

train-llm-from-scratch review

Train LLM From Scratch is an educational PyTorch codebase that builds a decoder-only Transformer and carries it through pretraining, supervised fine-tuning, reward modeling, DPO, PPO, and GRPO. It explains each stage with runnable scripts, smoke configurations, diagrams, a documentation site, and a small Streamlit control panel.

Verdict

Our run installed 150 packages and used 8,363 MB, then all 17 pytest cases passed in 42 seconds. That makes Train LLM From Scratch a good code-reading course for someone with a GPU and enough disk, especially if the goal is to connect pretraining math to DPO, PPO, and GRPO in one repository. Use TRL or another maintained training stack when shipping models matters more than seeing each loss written out.

We ran it

Lab card: what happened when we ran train-llm-from-scratchScreenshot of train-llm-from-scratch (fareedkhan-dev.github.io/train-llm-from-scratch)
Install✓ · 111s150 packages · 8363 MB
Build✓ · 1s
Tests✓ · 42s17 passed · 0 failed of 17 (pytest)
Known vulns0(pip-audit)
Repo186 files~6,998 lines of source · 6.7 MB · 1 CI workflows · tests dir

Answers from our run

Does train-llm-from-scratch build from source?

Dependencies installed in 111 seconds (150 packages), and the build succeeded in 1 seconds. We cloned commit b995104 into a clean Debian container with 3 CPUs and no project-specific setup.

Do train-llm-from-scratch's tests pass?

Yes: 17 of 17 passed when we ran the project's own test command (pytest). Some failures need services or credentials a bare container does not have.

Does train-llm-from-scratch have known vulnerabilities in its dependencies?

pip-audit found none in the dependency tree at the time of our run.

Who should not use train-llm-from-scratch?

CPU-only beginners expecting the documented training path to finish on an ordinary laptop: the README says a GPU is required, and issue 38 requests a separate low-hardware track.

What are the alternatives to train-llm-from-scratch?

nanoGPT, LLMs from Scratch, TRL. Our run installed 150 packages and used 8,363 MB, then all 17 pytest cases passed in 42 seconds.

Setup3/5Tests pass, but 8,363 MB and GPU training raise the entry cost
Docs5/5README, diagrams, code pointers, configs, and a docs site agree
Community4/510,075 stars with a small queue active through September
Maturity3/517 tests pass; GPU checkpoint edge case and no release remain

Who it’s for

Students who already know basic Python, neural networks, and PyTorch and want to read the full training path.
Engineers who want compact implementations of SFT, reward modeling, DPO, PPO, and GRPO without a framework hiding the math.
Researchers who need a small common backbone for comparing post-training objectives.
GPU users prepared to download public datasets and manage checkpoints stage by stage.

Who it’s NOT for

CPU-only beginners expecting the documented training path to finish on an ordinary laptop: the README says a GPU is required, and issue 38 requests a separate low-hardware track.
Readers who interpret 'from scratch' as writing every layer of the stack: tokenization uses OpenAI's tiktoken and the r50k_base vocabulary, while PyTorch supplies tensors, autograd, and distributed training.
Teams seeking a production trainer for frontier-scale models: the repository teaches with 13M, 77M, and 406M parameter configurations and a direct DistributedDataParallel path.
Users with tight local storage: our dependency install occupied 8,363 MB before datasets or checkpoints.
Anyone enabling torch.compile with DDP without a checkpoint regression test: open issue 36 reports prefix leakage that can load random weights instead of the trained state.

Setup reality

Our sandbox installed 150 Python packages in 111 seconds and used 8,363 MB on disk. The build succeeded in 1 second. Pytest finished in 42 seconds with all 17 tests passing, and pip-audit found 0 known vulnerabilities.

The package requires Python 3.9 or newer. Actual training needs a GPU, tokenized public datasets, and room for checkpoints. Optional extras add dataset and Weights & Biases support, the Streamlit panel, or the MkDocs site. The repository uses tiktoken rather than training a tokenizer.

Two configuration systems coexist: one Python file drives the original pretraining script, while JSON files and command-line overrides drive the newer stages. CPU smoke configs make fast correctness checks possible, but they are not substitutes for the documented GPU training runs.

Seven stages share one readable Transformer

The repository walks through 7 practical stages: data preparation, base pretraining, supervised fine-tuning, reward modeling, preference optimization, reinforcement learning, and evaluation. Its decoder-only Transformer is split into small PyTorch modules for attention, the feed-forward layer, a block, and the full model. Post-training then wraps that same backbone with loss masks, reward and value heads, and policy objectives. You can follow one set of weights from next-token prediction to a chat-formatted model.

That continuity is the best reason to choose this project over a folder of unrelated notebooks. The README points from each explanation to the real source file and command. JSON configurations cover the newer stages, while a Streamlit panel exposes Data, Pretrain, SFT, Reward, DPO, PPO, GRPO, Evaluate, and Chat pages. A separate documentation site explains the assumed theory. The code remains small enough to inspect, yet the path includes checkpoint resume, multi-GPU execution, evaluation, and interactive inference.

The 111-second install occupies 8,363 MB

Our sandbox installed 150 packages in 111 seconds, far longer than the other Python project in this batch. The resulting environment occupied 8,363 MB before adding training datasets or checkpoints. The package itself supports Python 3.9 and newer. Core dependencies include PyTorch, NumPy, HDF5, tiktoken, and compression and download utilities. Optional groups add public dataset tooling, Weights & Biases, Streamlit, pandas, Altair, and the MkDocs documentation stack.

The from-scratch label needs a useful boundary. The model, chat masking, reward head, DPO loss, PPO losses, group-relative advantages, and training loops are written directly in PyTorch rather than delegated to Transformers, TRL, or PEFT. Tokenization is not built here. The data scripts use OpenAI's r50k_base tokenizer through tiktoken, and training examples come from sources such as The Pile, Alpaca, Dolly, GSM8K, HH-RLHF, and UltraFeedback. That choice keeps attention on model and optimization code.

What happened when we ran it

We tested commit b995104 in an unprivileged Debian container with 3 CPUs and 8 GB of RAM. Installation succeeded in 111 seconds with 150 packages, and the build completed in 1 second. Pytest then ran for 42 seconds and reported 17 passed, 0 failed out of 17. Pip-audit found 0 known vulnerabilities in the installed environment. This is the only repository in this four-project batch whose measured test target ran and passed completely.

The checkout contained 186 files, roughly 6,998 source lines, one CI workflow, and a tests directory. The workflow builds and publishes the documentation rather than running the Python suite, so the 17 passing tests are useful local evidence but are not enforced by that GitHub Actions file. Tests cover checkpoint resume and post-training math and smoke behavior. Our CPU sandbox did not reproduce a real multi-GPU training session or judge the quality of generated text.

A 13M model teaches the path without proving scale

The smallest documented configuration has about 13 million parameters, while the README also shows examples around 77 million and 406 million. It says a free T4 can train the 13M version and makes clear that billion-parameter configurations need more capable GPUs. Mixed precision, gradient checkpointing, and gradient accumulation are opt-in memory controls. DistributedDataParallel supports several GPUs for the newer training path. These are enough to demonstrate the mechanics without pretending a teaching run matches commercial model development.

The data and compute bill continues after pretraining. SFT needs instruction rows and assistant-token masks. Reward modeling and DPO need preference pairs. PPO and GRPO need prompts, generated rollouts, rewards, and more checkpoints. The supplied smoke configurations shrink every stage enough for a quick CPU check, which is excellent for debugging. They do not make the main curriculum laptop-first. Open issue 38 specifically asks for a smaller CPU teaching track and bundled sample data for students with 4 to 8 GB of RAM.

Compiled multi-GPU checkpoints need an extra guard

Open issue 36 reports that combining torch.compile with DDP can add _orig_mod. prefixes to checkpoint keys. The current loader strips the DDP module. prefix but, according to the report, can miss the compiled prefix and load a model with 163 missing keys and random initialization. A proposed fix exists in pull request 37. The important operational lesson is simple: checkpoint loading needs an assertion that every expected tensor matched before post-training or inference begins.

That edge case does not contradict our 17 passing CPU tests. Our sandbox did not use torch.compile or DDP, which is the combination named in the report. Anyone scaling beyond the smoke path should add a save-and-reload test under the exact compilation and distributed settings planned for training. A run that finishes and writes a file is not enough. Reload it in a fresh process, compare the key set, and verify a known batch before spending compute on SFT or reinforcement learning.

August code and 7 open items show a maintained course

GitHub showed 10,075 stars and 7 combined open issues and pull requests. The default branch was last pushed on August 17, 2026, while issue 36 received activity on September 13. GitHub returned no latest release, so users should pin a commit instead of looking for a versioned training package. The open queue is small and includes both the compiled-checkpoint fix and a proposed CPU-friendly student mode.

Train LLM From Scratch works because it keeps one question in view: how does the loss change as a base Transformer becomes an assistant? The 17 passing tests make the answer easier to trust, and the 8,363 MB install states the cost plainly. Read the code, run the smoke path, then train the 13M configuration if you have suitable hardware. Move to a production library once your goal shifts from learning the algorithms to operating larger models.

Alternatives

ProjectWhat it isPick it when
nanoGPT gh↗A compact GPT training implementation focused on pretraining and fine-tuning speed.pick this instead when you want a smaller code surface and care mainly about GPT pretraining rather than the full alignment sequence.
LLMs from ScratchA book companion that builds a GPT-style model and training pipeline step by step in PyTorch.pick this instead when you want a slower, chapter-based teaching path with exercises and close ties to a published book.
TRLA maintained library for supervised fine-tuning, preference optimization, and reinforcement learning on Transformer models.pick this instead when you need established trainers and model integrations more than hand-written educational implementations.

What people are saying

  1. [github-trending] FareedKhan-dev/train-llm-from-scratch

Sources

  1. Train LLM From Scratch README
  2. Issue 36: compiled DDP checkpoint prefix leakage
  3. Issue 38: request for a CPU-friendly student path
  4. Documentation publishing workflow

More llm tools reviews

mistral.rs · flue · TensorRT-LLM · pydantic-ai · cc-haha · agent-lightning · the whole board →