NVIDIA-NeMo/RL #4670
· perf(cispo): support single-forward training · permalinks pin the PR head a67cc3e
prev, one to train. force_on_policy_ratio, which skips the first, was rejected for CISPO.force_on_policy_ratio: true when IS correction with TIS is on. The trainer then skips the prev forward.This is what NeMo-RL computes today for CISPO with IS correction and TIS on. Each token ot gets a probability from three policies:
gen): vLLM's probability when it sampled the token. Comes free with the sample.prev): the trainer's weights before this step's update. Costs one extra forward pass, with no gradient.curr): the trainer's weights inside the training forward. The only one with a gradient.TIS(x) clamps it to [truncated_importance_sampling_ratio_min, truncated_importance_sampling_ratio]
(code).ratio_clip_min / ratio_clip_max. sg[…] means no
gradient goes through it (code).The one assumption this PR uses: in the first optimizer update on a batch, πθ and
πprev are the same weights. So (2) is exactly 1, and πprev can be
replaced by a copy of πθ with no gradient. That is what force_on_policy_ratio: true does
(code):
Same value, same gradient. This is also the CISPO paper's own formula with πold = the policy that sampled the tokens, using the TIS bounds as its clip. When does the assumption hold?
| sync: vLLM has the trainer's current weights | async: vLLM can be some versions behind | |
|---|---|---|
| one optimizer update per batch | (2) = 1, (1) ≈ 1 (only small number differences). Single-forward OK. |
(2) = 1, (1) ≠ 1 (lag), and TIS clamps it. Single-forward OK. |
| several updates per batch | (2) ≠ 1 from update 2 on, so the two forms stop matching. GRPO rejects force mode here at setup. |
Same: (2) ≠ 1 from update 2 on. GRPO rejects force mode here at setup. |
So the row decides, not the column. The saving is the same in sync and async. Async is where (1) is far from 1, so that is where the TIS bounds matter most.
The "several updates" row, more exactly. The GRPO trainers block it: force mode requires
train_global_batch_size = prompts × generations
(grpo.py L850-L857).
PPO's ppo_epochs is not checked
(ppo.py L500-L509).
For CISPO that is still sound: each update uses clamp(πθ / πgen), the CISPO paper's form with
πold = the sampling policy. It just no longer equals the two-forward version. For plain PPO-clip it
removes the trust region, but that gap already existed on main and this PR does not touch it.
The figure follows one token through an async run where vLLM is one weight version behind the trainer.
force_on_policy_ratio means, and why async still worksIt does not mean "sync". It means: "each rollout batch gets exactly one optimizer update, so
curr / prev is 1; use curr.detach() wherever prev is needed"
(loss_functions.py L637-L638).
The GRPO trainer checks the one-update rule at setup
(train_global_batch_size == prompts × generations).
Async lag lives in the other ratio. In async RL the gap is between the weights vLLM sampled
with and the trainer's weights, which is prev / gen. This mode keeps that ratio (as
curr.detach() / gen, the same numbers) and TIS still clamps it. The async GRPO loop skips the
extra forward the same way
(grpo.py L5522),
and this PR lets SingleController's async ready_first sampler use it too.
What you give up is several updates per batch, not async. The CISPO nightly recipe samples
32 × 16 = 512 sequences per step but trains in batches of 32, so it takes 16 optimizer steps per rollout
(recipe L17-L28).
In steps 2 to 16, curr ≠ prev, so single-forward would no longer match that recipe's
two-forward math, and the GRPO trainer rejects force mode for it at setup.
Same 3 tokens through both paths. A = [4, -1, 5]; curr / gen = [0.2, 1.5, 8]; TIS bounds [0.5, 3]:
Two things follow. In this mode the loss never reads ratio_clip_min / ratio_clip_max:
TIS is the only clip. And the gradient, -A · w per token, is the same one GRPO with
force_on_policy_ratio and the same TIS settings already gives; only the logged loss differs.
Where the change lands: RL only. One assert in
ClippedPGLossFn.__init__
and one sampler check in
validate_single_controller_config.
No trainer change: both trainers already skip the prev forward whenever force_on_policy_ratio is on.
@@ loss_functions.py L400-L417 · ClippedPGLossFn.__init__ - assert not self.force_on_policy_ratio, ( - "use_cispo is incompatible with force_on_policy_ratio; " - "forcing ratio=1 removes the clipped IS-weight that CISPO optimizes" - ) + if self.force_on_policy_ratio: + assert ( + self.use_importance_sampling_correction + and self.truncated_importance_sampling_type == "tis" + ), "CISPO with force_on_policy_ratio requires IS correction with TIS" + assert ( + self.truncated_importance_sampling_ratio is not None + and math.isclose( + self.truncated_importance_sampling_ratio, + 1.0 + self.ratio_clip_max, + ) + and math.isclose( + self.truncated_importance_sampling_ratio_min or 0.0, + max(0.0, 1.0 - self.ratio_clip_min), + ) + ), ( + "CISPO with force_on_policy_ratio requires matching TIS and ratio_clip bounds" + ) @@ single_controller_utils/config.py L1392-L1399 · ready_first sampler check - if master_config.loss_fn.force_on_policy_ratio: + if ( + master_config.loss_fn.force_on_policy_ratio + and not master_config.loss_fn.use_cispo + ):
The PR also adds two CISPO-only branches in
clipped_pg_actor_objective.
They change no output: the existing force branch already makes the ratio exactly 1, and the existing CISPO line
already detaches it, which also reads closer to the CISPO formula. The review asks to drop those branches, and to
drop the second assert, since it checks two keys the loss never reads in this mode.
Review comments: clipped_pg.py:137 · no-op branches loss_functions.py:405 · bounds assert cispo.md:61 · what this mode does cispo.md:71 · which trainers skip
prev forward and train exactly the same, in sync or async runs. Async lag is still corrected
by TIS on curr / gen. If your recipe splits a batch into several optimizer steps (like the CISPO
nightly), GRPO rejects this mode at setup. The PR has no step-time numbers yet, so the speedup is expected but not measured.