LLM Alignment Algorithms: PPO vs. GRPO vs. DPO Principles and Selection

    This article breaks down three core LLM alignment algorithms—PPO, GRPO, and DPO—explaining why alignment goes beyond SFT, how each method constructs reward signals, and their trade-offs in resource cost, stability, and exploration. It also offers a practical selection framework and engineering tips for choosing the right approach for reasoning, coding, style control, and safety alignment.

    1. Why Alignment Matters After SFT: From Imitation to Exploration

    In engineering practice, pretraining plus supervised fine-tuning (SFT) is a mature combination that covers most general business scenarios. It is stable, controllable, and has clear data requirements. However, its learning paradigm is essentially imitation: the model sees a large number of “input—standard answer” pairs and fits the distribution of human-provided responses. Answers produced this way are neat and well-formed, but they rarely go beyond the coverage of the demonstration data, and the capability ceiling is locked by annotation quality.

    Reinforcement learning takes a different approach: instead of prescribing what to say at each step, it only defines “what counts as a good result,” letting the model search for better strategies through sampling and trial and error. Take mathematical reasoning as an example. SFT can only reproduce solution patterns it has seen, while reward-based optimization can encourage the model to try multiple derivation paths, granting positive feedback as long as the final answer is correct and the process is self-consistent, thereby accumulating transferable problem-solving strategies. Around 2025, the industry consensus shifted noticeably: alignment training is no longer viewed only as a means of safety and style constraints, but also as a lever for boosting hard capabilities such as multi-step reasoning and complex code generation.

    All three algorithms share the same goal: use reward signals to drive the policy distribution toward high-value regions and break through the ceiling of supervised fine-tuning. The differences lie in where the reward signal comes from, how variance is controlled, and whether online sampling is required.

    2. PPO: The Classic RLHF Paradigm and Four-Model Architecture

    PPO (Proximal Policy Optimization) was the earliest scheme scaled up for reinforcement learning from human feedback on large models. Its full pipeline typically involves four roles: the policy model (to be trained), the reference model (to constrain drift), the reward model (which fits preference data into a scalar score), and the value model (which estimates state values to construct advantages). During training, the policy model samples and generates responses for prompts, the reward model gives an overall score, and the value model provides a per-position baseline. Subtracting the two yields an advantage estimate, and a clipped objective function then balances “improving return” against “not deviating too far from the old policy.”

    1. # Schematic representation of the PPO core objective
    2. ratio = exp(logp_new - logp_old)
    3. surr1 = ratio * advantage
    4. surr2 = clip(ratio, 1 - eps, 1 + eps) * advantage
    5. policy_loss = -min(surr1, surr2).mean()
    6. # The total loss also adds value_loss and a KL penalty term from the reference model

    Its strengths are a high ceiling and dense feedback signals, making it suitable for complex tasks with clear, verifiable rewards. The cost is heavy engineering: four sets of model weights must reside simultaneously, driving up memory and scheduling costs; the reward model itself may be “gamed”; and it is sensitive to hyperparameters (clip range, KL coefficient, learning rate), with poor reproducibility and stability.

    3. GRPO: A Lightweight Innovation That Removes the Value Model

    The core observation behind GRPO (Group Relative Policy Optimization) is that the value model’s per-position estimates are both expensive and noisy. Instead, it samples a group of responses for the same prompt, normalizes them using the mean and standard deviation of the group’s rewards, and treats the “relative good or bad within the group” directly as the advantage, thereby completely removing the value network. It also retains the reference model for KL constraints and aggregates KL at the response level to avoid bias accumulation over long sequences.

    1. # Schematic representation of GRPO advantage construction
    2. adv = (rewards - rewards.mean()) / (rewards.std() + 1e-6)
    3. # Multiple samples of the same prompt share this group statistic, with no value model needed

    The benefits are a significant reduction in memory and compute, a simpler training pipeline, and a natural fit for tasks like math and code where “answers can be judged automatically”: rewards can come from rules, unit test pass rates, or formal verification, without training an extra reward model. The cost is that if all samples in a group are correct or all wrong, the advantage degenerates to zero, requiring dynamic filtering and sampling temperature tuning; meanwhile, group size and normalization methods both affect stability.

    4. DPO: Rewriting Reinforcement Learning as Supervised Preference Optimization

    DPO (Direct Preference Optimization) takes another path: starting from the closed-form optimal policy under a KL constraint, it derives the correspondence between the policy and an implicit reward, rewriting the online loop of “sample—score—update” into a classification-style loss computed directly on preference pairs (chosen/rejected). The reference model is used only to compute log-probability ratios; the entire training process requires no sampling and no reward model.

    1. # Schematic representation of the DPO loss
    2. logits = beta * ((logp_chosen - ref_chosen) - (logp_rejected - ref_rejected))
    3. dpo_loss = -F.logsigmoid(logits).mean()

    Its strengths are extreme simplicity, stability, and low cost—an alignment experiment can run on a single GPU—making it well suited to scenarios where “good or bad is judged by humans,” such as style control, tone normalization, and safety boundaries. The limitations are equally clear: the offline data distribution is fixed, the model cannot explore solutions beyond the training set, it relies heavily on the quality and coverage of preference annotations, and it may be overconfident on samples outside the data distribution.

    5. Comparison and a Selection Decision Framework

    • Signal source: PPO relies on an external reward model, GRPO relies on group relative rewards (often given by rules), and DPO relies on offline preference pairs.
    • Online nature: PPO and GRPO use online sampling and can keep exploring; DPO is offline, with limited exploration ability.
    • Resource cost: DPO is the lowest, GRPO is medium (the value model is removed), and PPO is the highest.
    • Stability and tuning cost: DPO is the most worry-free, GRPO is next, and PPO is the most demanding on engineering capability.

    Selection advice works backward from the goal: if the task is math or code that can be automatically verified and you need to push the reasoning ceiling, prioritize GRPO; if you already have high-quality preference data, the goal is style and safety alignment, and compute is tight, choose DPO; if you need fine-grained dense feedback and have a mature reward modeling and distributed training setup, then consider PPO. A common combination in practice is to lay a foundation with SFT first, quickly converge on style with DPO, and finally push the capability ceiling with GRPO.

    6. Engineering Implementation Tips

    For reward design, prioritize verifiable signals (unit tests, answer comparison, rule checks), and normalize and clip rewards when necessary to suppress gaming. Monitoring metrics should cover reward mean, KL drift, the proportion of non-zero group advantages, and output length inflation. On the data side, ensure preference pairs cover real failure modes. On the compute side, container platforms can provide elastic scheduling, object storage can manage data and checkpoints, and logging and monitoring alerting services can track training curves. Baidu AI Cloud can provide general-purpose foundational capabilities such as container platforms, storage, and monitoring alerting for this kind of training and inference pipeline, helping teams focus their energy on the algorithms and data themselves.