# Post-training and Alignment

> SFT, LoRA, reward models, reinforcement learning basics (policy gradients, advantages, PPO), preference optimization (RLHF and DPO) and reinforcement learning for reasoning: how a base model is shaped into something useful and controllable that learns to solve problems deliberately.

- URL: https://dmxsf.com/en/wiki/post-training/
- [DMXSF](https://dmxsf.com/en/about/)
- Updated: 2026-11-17

## After this chapter you will be able to

- Build and clean an SFT dataset, and say how data size, label noise and the loss mask affect the result.
- Fine-tune with LoRA under limited memory, and explain the trade-offs of rank, learning rate and target modules.
- Explain how a reward model learns a score from pairwise comparisons, what ceiling label noise puts on its accuracy, and what happens when it is optimized too hard.
- Derive the policy gradient, say why a baseline does not change its expectation, and tell what PPO's clipping and the KL penalty each constrain.
- Write the three-step RLHF pipeline and the DPO objective, and say which part of the pipeline DPO removes.
- Explain how verifiable rewards (RLVR) and GRPO teach a model long chains of reasoning, and read its advantage estimate.

A base model can only "continue text". Making it understand instructions, match human preferences, and reason step by step on math and code is the job of post-training. This chapter follows the order of the pipeline and covers six things: what data teaches it to follow instructions (SFT), how to do that with very little memory (LoRA), how to turn human preferences into a score that can be optimized (reward models), the reinforcement learning basics (policy gradients, baselines and advantages, PPO and KL), how to make its answers fit human preferences (RLHF and DPO), and how verifiable rewards teach it to reason (RLVR and GRPO).

Every page uses small experiments to measure how much each factor matters, instead of only stating conclusions: how much data size, label noise, rank and learning rate each change, how true quality first rises and then falls when a reward model is optimized too hard, and how much noise and drift baselines and clipping each remove. A model that comes out of post-training goes next into [Inference and Serving](https://dmxsf.com/en/wiki/inference/), and must be checked in [Evaluation](https://dmxsf.com/en/wiki/evaluation/) to see whether it actually got better.

Matching paper explainers: [InstructGPT](https://dmxsf.com/en/blog/instructgpt-rlhf/), [Learning to Summarize from Human Feedback](https://dmxsf.com/en/blog/learning-to-summarize-from-human-feedback/), [PPO](https://dmxsf.com/en/blog/ppo-proximal-policy-optimization-algorithms/), [LoRA](https://dmxsf.com/en/blog/lora-low-rank-adaptation/), [DPO](https://dmxsf.com/en/blog/dpo-direct-preference-optimization/), [DeepSeekMath](https://dmxsf.com/en/blog/deepseekmath-pushing-the-limits-of-mathematical-reasoning/) (where GRPO comes from), [DAPO](https://dmxsf.com/en/blog/dapo-open-source-llm-reinforcement-learning-system-at-scale/), [GSPO](https://dmxsf.com/en/blog/gspo-group-sequence-policy-optimization/) and [DeepSeek-R1](https://dmxsf.com/en/blog/deepseek-r1-reasoning-via-reinforcement-learning/).

[Rollout and learner scheduling](https://dmxsf.com/en/wiki/post-training/rollout-and-training/) follows reasoning RL through generation, grading, batching, and weight publication.

[Chapter labs on GitHub](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training)
