Single-forward CISPO: which logprob it stops computing, and why that is safe in async RL

NVIDIA-NeMo/RL #4670 · perf(cispo): support single-forward training · permalinks pin the PR head a67cc3e

Before
CISPO always ran two trainer forwards per step: one with no gradient to get prev, one to train. force_on_policy_ratio, which skips the first, was rejected for CISPO.
This PR
Allows CISPO with force_on_policy_ratio: true when IS correction with TIS is on. The trainer then skips the prev forward.
Status
New feature; the math checks out. It works in sync and async runs, but only with one optimizer update per rollout batch. The review asks for small cleanups (end of page).

The CISPO loss, one term at a time

This is what NeMo-RL computes today for CISPO with IS correction and TIS on. Each token ot gets a probability from three policies:

\mathcal{L}(\theta)=-\frac{1}{N}\sum_{t}\; \htmlClass{t1}{\underbrace{\mathrm{TIS}\!\left(\frac{\pi_{\text{prev}}(o_t)}{\pi_{\text{gen}}(o_t)}\right)}_{\text{(1) IS weight}}} \cdot \htmlClass{t2}{\underbrace{\mathrm{sg}\!\left[\mathrm{clip}\!\left(\frac{\pi_\theta(o_t)}{\pi_{\text{prev}}(o_t)},\;1-\varepsilon_{\text{low}},\;1+\varepsilon_{\text{high}}\right)\right]}_{\text{(2) CISPO trust-region weight}}} \cdot \htmlClass{t3}{\underbrace{A_t\,\log\pi_\theta(o_t)}_{\text{(3) gradient flows here}}}

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):

\mathcal{L}_{\text{1-fwd}}(\theta)=-\frac{1}{N}\sum_{t}\; \htmlClass{t1}{\mathrm{TIS}\!\left(\frac{\mathrm{sg}[\pi_\theta(o_t)]}{\pi_{\text{gen}}(o_t)}\right)} \cdot\htmlClass{t2}{1}\cdot \htmlClass{t3}{A_t\,\log\pi_\theta(o_t)} \qquad\text{(no }\pi_{\text{prev}}\text{, so no extra forward)}

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 weightsasync: 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.

Where the three logprobs come from

The figure follows one token through an async run where vLLM is one weight version behind the trainer.

rollout engine (vLLM) trainer (Megatron / DTensor) 1 · sample the tokens weights v4 (async: one version behind) gen = log π_v4(token) gen [-1.39, -2.91, -2.78] free: comes with the sample 2 · extra forward, no gradient policy.get_logprobs (async loop) prev = log π_v5(token) prev [-3.0, -2.5, -0.7] full pass over the batch; skipped here 3 · training forward, update 1 weights v5, gradients on curr = log π_v5(token) curr [-3.0, -2.5, -0.7] same weights as step 2, same numbers IS ratio prev / gen = π_v5 / π_v4 Not 1: the async lag plus small vLLM-vs-trainer number differences. TIS clamps it, e.g. to [0.5, 3] (loss_functions.py L741-L780) trust-region ratio curr / prev = π_v5 / π_v5 = 1 in update 1. CISPO's clip on it (clipped_pg.py L144-L150) has nothing to do when the ratio is 1. update 2, 3, … of the same batch Only when one batch is split into several optimizer steps. The weights have moved past v5, so curr ≠ prev and the clip does real work. GRPO rejects force mode here. the pass this PR removes gives the same numbers as the red pass not allowed in this mode Example values: 3 tokens, from running the real ClippedPGLossFn at a67cc3e on CPU.

What force_on_policy_ratio means, and why async still works

It 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 forwards (main today) gen [-1.39, -2.91, -2.78] prev forward [-3.0, -2.5, -0.7] extra pass curr (training) [-3.0, -2.5, -0.7] weight clip(curr/prev)=[1,1,1] × TIS(prev/gen) = [0.5, 1.5, 3] loss, grad loss 4.25 [-0.67, 0.5, -5.0] one forward (this PR) gen [-1.39, -2.91, -2.78] skipped _skip_prev_logprobs prev := curr.detach() curr (training) [-3.0, -2.5, -0.7] weight ratio forced to 1 × TIS(curr/gen) = [0.5, 1.5, 3] loss, grad loss 4.25 [-0.67, 0.5, -5.0] Green: identical in both rows. The only difference is the red pass, which the second row never runs.

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.

What the PR changes

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

So what. If each rollout batch gets one optimizer update, CISPO can drop the 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.