This repo collects post-training methods for Large Language Models (LLMs) with small, focused implementations and runnable examples. The goal is to make alignment and reinforcement post-training practical, understandable, and reproducible.
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -U pip
pip install -r requirements.txt
python -m pytest tests/ -v
gymnasium/: RL foundations (CartPole examples).chess/: Toy chess Q-learning (KQ vs K).tests/: unit and smoke tests (pytest).blog/: blog post drafts for the learning series.requirements.txt: Python dependencies.README.md: learning path and run instructions.Runs a single random rollout to verify environment setup.
Code: gymnasium/cartpole_random.py
python gymnasium/cartpole_random.py
Trains a discretized Q-learning agent and evaluates it.
Code: gymnasium/cartpole_q_learning.py
python gymnasium/cartpole_q_learning.py
Evaluation renders by default.
Trains a deep Q-network with replay and a target network.
Code: gymnasium/cartpole_dqn.py
python gymnasium/cartpole_dqn.py
Evaluation renders by default.
Trains an actor-critic with the PPO clipped objective and GAE.
Code: gymnasium/cartpole_ppo.py
python gymnasium/cartpole_ppo.py
Evaluation renders by default.
Trains a critic-free policy using group-normalized episode returns as advantages, the same mechanism GRPO uses for LLM post-training.
Code: gymnasium/cartpole_grpo.py
python gymnasium/cartpole_grpo.py
Evaluation renders by default.
Trains a Q-learning agent on a toy chess endgame (King + Queen vs King).
Code: chess/chess_q_learning.py
python chess/chess_q_learning.py
Two build-from-scratch blog series, taken in order. They build up slowly: no post uses a concept that an earlier post has not taught, and every method is implemented from scratch in PyTorch first, then with a library.
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A["Build a Tiny LLM from Scratch<br/>10 posts"] --> B["LLM Post-Training from Scratch<br/>22 posts"]
A -.-> C["Architectures in Code<br/>(later)"]
The concepts behind the architecture posts are covered separately in the LLM Model Architectures Deep Dive series; the posts here build what that series explains.
The shared foundation. Ends with a working tiny base model.
One running project ties this series together: a Wordle-playing agent that starts as the raw Qwen2.5-0.5B base model. Each post-training method is applied to the same agent, and every post reports the same scoreboard (win rate, average guesses, illegal-move rate) on a fixed set of target words.
Opener
RL basics
Supervised fine-tuning
Preferences
Verifiable rewards and reasoning
Wrap-up