Reinforcement Learning2025

VAPO

VAPO: Value-Augmented Policy Optimization for Long Reasoning Yue et al. (ByteDance Seed) arXiv

VAPO uses a critic to estimate how likely a partial solution is to end in a correct answer.

Why it mattered

ByteDance Seed studied why long-horizon reasoning RL collapses when traces stretch past thousands of tokens. VAPO combined four stabilizing mechanisms: value-guided credit assignment with decoupled length-adaptive discounting, asymmetric Clip-Higher (0.20 / 0.28), group-level filtering, and a small positive-example NLL imitation term on passing traces so correct reasoning patterns never wash out.

Core insight

Combine length-adaptive discounted per-token advantages (discounting KL and return credit backward across long traces), asymmetric Clip-Higher (εlow=0.20\varepsilon_{\text{low}} = 0.20, εhigh=0.28\varepsilon_{\text{high}} = 0.28), and an auxiliary positive-example NLL anchor LNLL+=−λNLLlog⁡πθ(y+∣x)\mathcal{L}_{\text{NLL}}^{+} = -\lambda_{\text{NLL}} \log \pi_\theta(y^{+} \mid x) strictly on verified passing trajectories.

grad.KL(trainer, coef=0.01, weights='initial', discount=0.95) computes reverse-discounted per-token KL shaping natively, while a 16-line losses.CustomLoss fuses asymmetric Clip-Higher with positive-example NLL anchoring on 1× GPU (custom server-side token value heads remain Wave 2).

When to use

Use VAPO techniques (length-aware clipping, discounted KL, and positive-example NLL anchoring) on long chain-of-thought reasoning problems where sparse binary rewards cause pure policy-gradient runs to forget valid proofs. On shorter tasks under 1,024 tokens, DAPO or Dr. GRPO is simpler.

Step-by-step walkthrough

  1. 01

    Roll out long reasoning chains with MathEquivalence

    Sample 4 long CoT trajectories per prompt (up to 2,048 tokens) and tag passing trajectories via traj.reward. Generating long traces up to 2,048 tokens gives the policy room to backtrack and self-verify on hard math problems.

    env.rollout_groups(trainer, tasks=chunk, group_size=4, max_tokens=2048)
  2. 02

    Apply reverse-discounted per-token KL shaping

    grad.KL(trainer, coef=0.01, weights='initial', discount=0.95) propagates KL credit backward across long chains while advantages.GroupStd() supplies a critic-free baseline. Discounted backward KL keeps early reasoning tokens anchored while letting late solution tokens adapt freely.

    grad.with_advantages(groups, advantages.GroupStd(), kl=KL(trainer, coef=0.01, weights='initial', discount=0.95))
  3. 03

    Fuse asymmetric Clip-Higher with positive-example NLL in CustomLoss

    VAPOLoss applies asymmetric clipping [0.20, 0.28][0.20,\, 0.28] to all rollouts and adds −λNLLlog⁡πθ-\lambda_{\text{NLL}} \log \pi_\theta on passing traces so correct proofs stay anchored. Adding a small NLL term on passing trajectories reinforces exact winning derivation steps alongside RL updates.

    trainer.forward_backward(batch, loss=VAPOLoss(positive_flags, eps_lo=0.2, eps_hi=0.28, nll_coef=0.1))

Implementation

train.py
import torch
import grad
from grad import Environment, Grad, KL, Rubric, Scorer, Task, adapters, advantages, losses, optim, validators

class VAPOLoss(losses.CustomLoss):
    def __init__(self, positives: list[bool], eps_lo: float = 0.2, eps_hi: float = 0.28, nll_coef: float = 0.1):
        self.positives, self.eps_lo, self.eps_hi, self.nll_coef = positives, eps_lo, eps_hi, nll_coef

    def compute(self, data, out):
        terms = []
        for i, (d, is_pos) in enumerate(zip(data, self.positives)):
            lp, mask = out.logprobs[i], out.mask(i)
            old_lp = torch.tensor(d.sampling_logprobs, dtype=torch.float32)
            adv = torch.tensor(d.advantages, dtype=torch.float32)
            r = torch.exp(lp - old_lp)
            pg = -torch.minimum(r * adv, r.clamp(1.0 - self.eps_lo, 1.0 + self.eps_hi) * adv)
            nll = (-lp * self.nll_coef) if is_pos else torch.zeros_like(lp)
            terms.append(grad.masked_mean(pg + nll, mask))
        return torch.stack(terms).mean()

client = Grad()
ds = client.datasets.from_hf("openai/gsm8k", config="main", split="train", prompt="question", answer="answer", limit=2560)
tasks = [Task(id=str(i), prompt=r["messages"][0]["content"], expected_output=r["expected_output"]) for i, r in enumerate(ds.records())]
env = Environment(
    rubric=Rubric([Scorer("math", fn=validators.MathEquivalence())]),
    max_turns=1,
    system_prompt="Think step by step and end with \\boxed{...}.",
)

total_steps = 80
with client.trainers.create(
    model="qwen/qwen3-8b",
    name="vapo-math",
    adapter=adapters.LoRA(rank=32),
    total_steps=total_steps,
    max_cost_usd=12.0,
) as trainer:
    for step in range(1, total_steps + 1):
        chunk = tasks[((step - 1) * 32) % len(tasks) : ((step - 1) * 32) % len(tasks) + 32]
        groups = env.rollout_groups(trainer, tasks=chunk, group_size=4, max_tokens=2048, temperature=1.0)
        batch = grad.with_advantages(
            groups,
            advantages.GroupStd(),
            skip_zero_var=False,
            kl=KL(trainer, coef=0.01, weights="initial", discount=0.95),
        )
        positives = [float(t.reward or 0.0) > 0.5 for g in groups for t in g if not t.failed]
        fb = trainer.forward_backward(batch, loss=VAPOLoss(positives, eps_lo=0.2, eps_hi=0.28, nll_coef=0.1))
        opt = trainer.optim_step(optim.AdamW(lr="auto", objective="rl"))
        fb_res, opt_res = fb.result(), opt.result()
        trainer.log_metrics(opt_res.step, {"reward": grad.mean_reward(groups), "loss": fb_res.loss})
    artifact = trainer.export(name="vapo-math").result().artifact

Benchmarks

Reported results from the original paper compared against its baseline.

AIME 2024 pass@1Qwen2.5-32B long-CoT RL (VAPO vs. DAPO)
+10.4 pts
DAPO (32B)50%
VAPO (32B)60.4%

Models & datasets

ModelDurationEst. cost
Qwen3 8Brecommendedqwen/qwen3-8b
~38 min~$3.00
Qwen3 14Bqwen/qwen3-14b
~58 min~$5.10
DatasetSourceSize
DAPO-Math-17kHugging Face17,000 competition math prompts
GSM8K MathHugging Face7,473 train / 1,319 test

Practical gotchas

  • Server-side custom token-level value heads (specs.heads) are deferred past grad v0; use group baselines + discounted KL today, or add Monte Carlo prefix branching (see VinePPO) when you need denser intermediate value estimates.
  • Keep nll_coef small (0.05–0.100.05\text{–}0.10) — larger SFT anchoring weights overfit early passing traces and choke exploration.
  • Monitor positive-NLL loss separately from RL policy loss: if passing proofs make up fewer than 10% of the batch, down-weight nll_coef until pass rate rises so the policy does not memorize a handful of lucky traces.

grad primitives