Skip to content

REINFORCE++ and REINFORCE++-baseline

Relax exposes two separate estimator names because the baseline variant is not just a different recipe:

  • reinforce_plus_plus
  • reinforce_plus_plus_baseline

This page fixes their return, advantage, normalization, mask, KL and reduction semantics. The implementation follows the main equations of REINFORCE++ arXiv v9 and the executable normalization convention in OpenRLHF commit bc71bb1.

Version and naming note

The paper changed between v1 and v9, and even v9's main method and Appendix B.2 do not describe exactly the same token placement. The following table makes the version and implementation boundary explicit.

SourceReturn / baselineNormalization and KLStatus in this implementation
paper v1token k1 KL-to-go advantage plus PPO clippingdescribes reward normalization/clipping and batch z-score advantage normalization, but has no separately named group-baseline-plus-k2 varianthistorical REINFORCE++ only; not the baseline definition
paper v9 main equationstoken KL-to-go return; inclusive group-mean baseline variantglobal normalization of advantage tokensnormative paper definition
paper v9 Appendix B.2zero advantage before the final tokensample-level reward normalizationdocumented conflict; not selected
OpenRLHF bc71bb1inclusive group mean and global valid-token population normalizationits pinned baseline training script enables token KL shaping and a separate k2 lossnormalization reference only; its combined-KL baseline is intentionally not copied
Relax before this featurepartial helper names and return codeno registered pair, frozen validation, dedicated population moments, recipe, or complete numerical contractcompatibility baseline

Relax selects the v9 main-equation interpretation. “OpenRLHF aligned” in this document refers specifically to its executable inclusive-baseline and masked population-normalization convention. The Relax baseline deliberately keeps KL out of the advantage and applies only the independent k2 loss, as frozen in the Task 29 Proposal; it is therefore not an exact reproduction of the pinned OpenRLHF training script.

Notation and mask contract

For response (i) and response position (t):

  • (R_i) is the scalar terminal reward;
  • (m_{i,t}\in{0,1}) is the response loss mask;
  • (T_i) is the final valid response position;
  • (L_i=\sum_t m_{i,t}) is the valid response length.

Prompt tokens, padding and response tokens with mask=0 do not contribute to reward shaping, return, normalization or loss. Production return and advantage tensors are explicitly zero outside the mask. Selection is boolean rather than multiplicative, so even NaN or Inf in a masked storage position cannot contaminate a valid-token result.

REINFORCE++

Let the signed k1 estimator be

di,t=logπold(ai,t)logπref(ai,t).

The shaped token reward is

ri,t=mi,t[βdi,t+1(t=Ti)Ri].

The terminal reward is added only to the final valid response token. Returns are accumulated backwards:

Gi,t=mi,tu=tTiγutri,u.

The formal recipe fixes gamma=1. The raw advantage is (G), followed by the global masked normalization below. This variant uses token KL reward shaping and does not add a second KL loss.

text
--advantage-estimator reinforce_plus_plus
--normalize-advantages
--gamma 1.0
--kl-coef 0.01
--kl-loss-type k1

REINFORCE++-baseline

For a prompt group (g) with (K) sampled responses,

bg=1KjgRj,Ci=Ribg.

The group mean includes the current response. It is not a leave-one-out baseline. Relax does not divide (C_i) by a group standard deviation.

The raw token advantage is

Ai,traw=mi,tCi.

Token KL is not subtracted from this advantage. Reference regularization is a separate k2 loss:

Di,tk2=12(logπθ(ai,t)logπref(ai,t))2.
text
--advantage-estimator reinforce_plus_plus_baseline
--normalize-advantages
--n-samples-per-prompt 8
--kl-coef 0
--use-kl-loss
--kl-loss-type k2
--kl-loss-coef 0.01

The baseline variant requires more than one sample per prompt. The group mean includes each sample itself, so n_samples_per_prompt=1 would collapse every raw advantage to zero and is rejected. Custom reward post-processing and agentic custom-advantage hooks are also rejected for this estimator because they would bypass the frozen inclusive group-mean semantics.

Global masked normalization

The statistical population consists of every valid response token in the closed synchronous global batch across all data-parallel ranks:

S={(r,i,t)mr,i,t=1},N=|S|.

Relax uses population variance (ddof=0):

μ=1NSA,σ2=1NS(Aμ)2.

The normalized output is

A^=m(Aμ)[max(σ2,108)]1/2.

The epsilon convention is a variance floor, matching the pinned OpenRLHF implementation. It is different from both sqrt(var) + epsilon and Relax's legacy sqrt(unbiased_var + epsilon) helper. The REINFORCE++ variants use a dedicated helper; existing algorithms keep their current normalization.

Expected edge behavior:

  • zero variance and a single valid token produce finite zero advantages;
  • an all-zero baseline reward group produces finite zeros;
  • an all-zero reward with nonzero KL can produce finite KL-shaped REINFORCE++ returns;
  • a fully masked local response contributes a zero tensor and still reaches the data-parallel collective;
  • a globally empty mask triggers a device-side asynchronous assertion on every participating rank without extracting a host scalar in the training hot path.

Because the baseline scalar is broadcast to each valid token, longer responses have greater weight in these token-level global moments. This is intentional.

PPO and KL reduction

Both variants use the ordinary token PPO clipped surrogate. Their formal scalar objective is a response mean:

LPG=1Bi1Litmi,tmax(ρi,tA^i,t,clip(ρi,t,1ϵ,1+ϵ)A^i,t).

The baseline k2 loss uses the same response-mean reduction. The initial implementation rejects --calculate-per-token-loss for these variants because it changes the objective to a global token mean.

Formula-level comparison

Let

ρi,t=exp(logπθ(ai,t)logπold(ai,t)),

and let clip-PPO denote the token objective shown above. Relax's existing group-relative algorithms first compute

Aigrp=RiR¯g,

and, when --grpo-std-normalization is enabled, divide by torch.std({R_j:j in g}) + 1e-6. That existing torch.std call uses Bessel's sample correction (ddof=1), unlike the new global population variance.

AlgorithmRaw advantage and statistical axesRatio / policy objectiveReference regularization
REINFORCE++token KL-to-go Gi,t; normalize over every valid token and DP rank with ddof=0token ρi,t and clip-PPO; response meank1 inside token reward
REINFORCE++-baselineRiR¯g broadcast to valid tokens, without group-std division; then the same global token/DP normalizationtoken ρi,t and clip-PPO; response meanseparate k2 loss with response mean
GRPOAigrp with optional same-prompt sample-std scaling; broadcast within the responsetoken ρi,t and clip-PPOexisting configurable Relax KL
GSPOthe same group advantage as GRPOsequence ratio ρi=exp[Li1tmi,t(logπθlogπold)] expanded to its tokens, then clip-PPOexisting configurable Relax KL
SAPOthe same group advantage as GRPOtoken ratio with fτ(ρ)=4σ[τ(ρ1)]/τ; loss fτ(ρ)A, using separate positive/negative τ valuesexisting configurable Relax KL

For all five paths, masks select contributing response tokens and the existing Relax reducer computes a mean within each response followed by a mean across responses. The new variants reject the alternative global-token reduction so that this denominator cannot change silently.

This feature does not change GRPO, GSPO or SAPO defaults.

Supported modes

The first implementation supports:

  • synchronous colocate training;
  • data-parallel normalization;
  • context_parallel_size=1;
  • response-mean loss reduction.

It rejects fully-async, hybrid, context parallelism greater than one, and per-token global loss reduction. Fully-async does not currently define a closed global batch over which these moments can be calculated, while CP greater than one requires a separately verified unique-token ownership contract.

Monitoring

The rollout metrics include:

  • raw global advantage mean and standard deviation;
  • normalized advantage mean and standard deviation;
  • valid-token count;
  • zero-variance indicator;
  • ordinary reward, return and advantage summaries.

The three KL-related observables have deliberately different meanings:

  • train/ppo_kl is the response-reduced old-policy/current-policy log-prob difference used to form the PPO importance ratio. It measures policy-update drift; it is not a reference-policy KL and does not show whether k1 or k2 regularization is active.
  • For REINFORCE++, reference-policy k1 shaping is already folded into rollout/returns. Comparing the same-step rollout/returns and rollout/raw_reward summaries exposes its empirical effect; there is no independent train/kl_loss for this variant.
  • For REINFORCE++-baseline, train/kl_loss is the separately reduced k2 reference-policy penalty. It is absent from the advantage and is added to the total loss with --kl-loss-coef.

Training metrics also continue to report policy loss and clip fraction.

Testing

The numerical tests use an independent float64 reference that does not invoke the production return, advantage, normalization or loss functions. Coverage includes variable response lengths, padding, internal mask holes, finite and non-finite sentinels outside the mask, zero rewards, zero variance, a single valid token, a fully masked local rank, PPO clipping and response-reduced policy/k2 losses. A Megatron-backend integration test also calls the production compute_advantages_and_returns dispatcher. On a host without Megatron it injects only the minimal mpu interface needed by that function, so the real Relax dispatch and normalization code still execute rather than being mocked.

Distributed normalization is tested with two real Gloo processes and a real all_reduce, including a case where one rank has no valid token. Its output is compared with the independently concatenated global population.

See examples/algorithms/run-qwen3-0.6B-1xgpu-reinforce-plus-plus.sh for the parameterized Qwen3-0.6B recipe.

The equal-budget Qwen3-0.6B stability experiment, numerical evidence, curves, and comparison with GRPO are documented in the training and numerical validation report.

Released under the Apache 2.0 License.