Companion GitHub Repository: agemagician/torchtpu-zero-to-hero
From 0.0% to 96.9% Verifiable Math Accuracy in 45 Online GRPO Steps — on a Single 16 GiB Colab TPU
Post-training is where base language models turn into helpful assistants ( Direct Preference Optimization [DPO] ) and verifiable step-by-step reasoners ( Group Relative Policy Optimization [GRPO] , the online RL algorithm popularized by DeepSeek-R1).
Running post-training and online RL on a single 16 GiB TPU TensorCore ( TPU v5e-1 ) forces you to solve three classic systems bottlenecks:
Vocabulary Logit HBM Blowups: Upcasting [B*G=8, S=192, V=151,936] Qwen3 logits to float32 allocates ~ 0.93 GiB per tensor ( >5 GiB across forward + autograd), leaving no room for KV caches and weights.
Mid-Step Dynamo Guard Breaks: Toggling with model.disable_adapter(): inside a DPO training step mutates module state and invalidates torch.compile guards.
Variable-Length Rollout Recompilations: Generating G = 4 online reasoning rollouts per prompt with variable…