# Train LLM From Scratch

> Plain-PyTorch codebase to pretrain and post-train your own small language models

Source: https://talira.ai/catalog/train-llm-from-scratch-k1fbb78n
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library, Command-line tool
- Categories: [ai / ml / pretraining](https://talira.ai/categories/ai/ml/pretraining), [ai / ml / fine tuning](https://talira.ai/categories/ai/ml/fine-tuning)
- Licence: MIT[^2]
- Pricing: Free and open source[^1]
- Free tier: yes[^1]
- Backed by: [Fareed Khan](https://talira.ai/orgs/fareedkhan-dev.md)

Train LLM From Scratch is an MIT-licensed Python codebase for training your own language model end to end in plain PyTorch, from raw text and a BPE tokenizer through pretraining to SFT, a reward model, PPO, DPO, ORPO, KTO and GRPO, then evaluation and chat. It installs with pip in editable mode, runs each stage from scripts driven by per-stage JSON configs whose fields can be overridden on the command line, saves checkpoints between stages, and offers a classic and a modern Transformer (RoPE, RMSNorm, SwiGLU, grouped-query attention, Mixture of Experts). Presets range from a 369K-parameter model that trains on a laptop CPU in minutes to billion-parameter configs on GPUs, with a Streamlit control panel and a docs site. It began as a pretraining tutorial and its README still explains each step.

## Links

- GitHub: https://github.com/FareedKhan-dev/train-llm-from-scratch
- Docs: https://fareedkhan-dev.github.io/train-llm-from-scratch/

## Problems it solves

- train my own small language model from raw text without Hugging Face libraries
- run SFT, DPO and GRPO on a model I pretrained myself to see each stage work
- train a tiny language model on my laptop CPU to learn how pretraining behaves

## Features

- pretraining and post-training stages (SFT, reward model, PPO, DPO, ORPO, KTO, GRPO) in plain PyTorch
- per-stage JSON configs with command-line overrides
- presets from a CPU-sized 369K-parameter model to billion-parameter configs
- classic and modern Transformer architectures, including Mixture of Experts
- Streamlit control panel

## Limitations

- billion-parameter configs need a large GPU; a free Colab or Kaggle T4 fits the 13M model but not a billion-parameter one[^1]

## Trust

Overall: 0.69 out of 1.
Signals: maintenance 1.00, adoption 0.83, momentum 0.84, community 0.47, backing 0.30, extensibility 0.00.

- last commit 14 days ago
- 115 commits in the last 90 days
- latest release v1.0.0 14 days ago
- 13.3k GitHub stars
- 14 contributors
- backed by Fareed Khan

## Alternatives

- [PaddleFormers](https://talira.ai/catalog/paddleformers-mkjm9xth.md): A Transformers library for PaddlePaddle that trains large language and vision-language models

## Sources

[^1]: https://github.com/FareedKhan-dev/train-llm-from-scratch/blob/main/README.md (checked 30 Nov 2026)
[^2]: https://github.com/FareedKhan-dev/train-llm-from-scratch/blob/main/LICENSE (checked 30 Nov 2026)
