12.5K-star GitHub repo is a full LLM engineering course: pretraining to GRPO in plain PyTorch

techNmak · x · 2026-10-27

A 12.5K-star GitHub repo, "Train LLM From Scratch", packs an entire LLM engineering course into one codebase: it builds a Transformer in plain PyTorch from raw text and goes all the way to RL, without trl, peft or transformers.

It implements tokenization/attention/pretraining, SFT with assistant-token loss masking, Bradley-Terry reward modeling, DPO/ORPO/KTO preference optimization, PPO with a value head and GAE, and GRPO with group-relative rewards plus GSM8K eval. All post-training methods build on the same base Transformer so you can compare objectives and optimization loops across stages; a modern variant adds RoPE, RMSNorm, SwiGLU, GQA, MoE, KV cache, plus Muon, LoRA, SimPO, speculative decoding and int8 weights — trainable on a single GPU or laptop CPU.

Original post →

More from coding & agent

coding & agent channel →