Open Documentation

Post-Training Techniques

The techniques that actually change a model's behavior: LoRA and QLoRA, DPO, knowledge distillation, and the failure modes that show up along the way, from catastrophic forgetting to the specific bugs that appear when combining these techniques together.

Post-Training Techniques·Deep Dive

The Math of DPO, Explained | SR Cookbooks

A step-by-step mathematical derivation of Direct Preference Optimization (DPO), showing how the partition function cancels and verifying the implicit reward gradient in Python.

DPORLHFAlignmentMachine LearningPython
Post-Training Techniques·Bug Fix

Fixing EOS Errors: Why Fine-Tuned Models Talk to Themselves | SR Cookbooks

A technical guide to fixing the infinite generation bug in SFT by properly mapping EOS tokens and chat templates in Hugging Face.

EOS TokenSFTHugging FaceChat Templates
Post-Training Techniques·Deep Dive

PEFT Explained: LoRA vs. QLoRA | SR Cookbooks

Understand the architectural differences between LoRA and QLoRA, and learn when to use each Parameter-Efficient Fine-Tuning technique based on your VRAM limits.

LoRAQLoRAPEFT
Post-Training Techniques·Bug Fix

How to Train Custom Tokens with LoRA | SR Cookbooks

Learn how to fix untrained embedding errors when adding custom tokens to an LLM vocabulary during PEFT and LoRA fine-tuning.

LoRAPEFTTokenization
Post-Training Techniques·Deep Dive

Catastrophic Forgetting in Fine-Tuning | SR Cookbooks

What catastrophic forgetting is, why it happens when you fine-tune an LLM, what it costs you, and how to spot it, plus when a specialized small model can safely ignore it.

Catastrophic ForgettingFine-TuningLoRA
Post-Training Techniques·Deep Dive

Implementing LoRA from Scratch in PyTorch | SR Cookbooks

Learn how to write a custom LoRA wrapper in pure PyTorch. Freeze a base model, train low-rank A and B matrices, and merge the weights without using PEFT.

PyTorchFine-TuningLoRA
Post-Training Techniques·Bug Fix

LoRA & Gradient Checkpointing: The Phantom Bug | SR Cookbooks

Wondering why combining LoRA with gradient checkpointing no longer crashes your script? A deep dive into PyTorch detached tensors, Hugging Face PEFT fixes, and manual graph attachment.

PyTorchLoRAMemory OptimizationMLOps & Debugging
Post-Training Techniques·Deep Dive

Knowledge Distillation from Scratch: Pure PyTorch | SR Cookbooks

Learn the underlying math of Knowledge Distillation. Move beyond standard SFT by implementing temperature scaling and Kullback-Leibler divergence from scratch in PyTorch.

PyTorchDistillationMath