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 insightCombine length-adaptive discounted per-token advantages (discounting KL and return credit backward across long traces), asymmetric Clip-Higher (, ), and an auxiliary positive-example NLL anchor 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
- 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) - 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 whileadvantages.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)) - 03
Fuse asymmetric Clip-Higher with positive-example NLL in CustomLoss
VAPOLossapplies asymmetric clipping to all rollouts and adds 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
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().artifactBenchmarks
Reported results from the original paper compared against its baseline.
Models & datasets
| Model | Duration | Est. cost |
|---|---|---|
Qwen3 8Brecommendedqwen/qwen3-8b | ~38 min | ~$3.00 |
Qwen3 14Bqwen/qwen3-14b | ~58 min | ~$5.10 |
| Dataset | Source | Size |
|---|---|---|
| DAPO-Math-17k | Hugging Face | 17,000 competition math prompts |
| GSM8K Math | Hugging Face | 7,473 train / 1,319 test |
Practical gotchas
- Server-side custom token-level value heads (
specs.heads) are deferred pastgradv0; use group baselines + discounted KL today, or add Monte Carlo prefix branching (see VinePPO) when you need denser intermediate value estimates. - Keep
nll_coefsmall () — 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_coefuntil pass rate rises so the policy does not memorize a handful of lucky traces.