Repository navigation
feat(fsdp): score centering for Flow-GRPO under train/rollout mismatch - #298
Merged
Merged
Conversation
Callers unpacked a positional 4-tuple, and the transition std that log_prob scores against (noise_std) never left the backend; flow-SDE keeps it distinct from the std_dev_t the KL uses. A NamedTuple keeps the reference field order and adds noise_std so the loss can evaluate log_prob at another mean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rollout transitions come from the engine's N(mu_q, s^2) while the trainer scores them under N(mu_theta, s^2). Any numeric gap makes the expected score nonzero, so the policy gradient gains a drift term, E[A] times that expected score, that distills the trainer toward the rollout and compounds through weight sync (arXiv:2609.20807). --diffusion-score-centering subtracts the expected score. For a Gaussian SDE step with a theta-independent std it is exact, grad E_q[log p] = grad log p(mu_q), so it needs only the rollout's per-step means, which sglang-diffusion returns under --diffusion-debug-mode. The correction is scaled by each pair's PPO gradient weight, zero-valued in the forward so logged losses stay comparable, and a no-op when trainer and rollout agree. train/prev_mean_diff_over_noise_std logs the trainer-vs-rollout mean gap in noise-std units whenever debug tensors are present; it flattens per pair like the model_output diff, so only the correction requires matching layouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same recipe, topology and determinism as test_sd3_ocr_grpo_2xGPU, plus --diffusion-score-centering --diffusion-debug-mode --diffusion-recompute-old-log-prob, so the rollout -> trainer path for the per-step means and the correction run on GPU. Labelled e2e so it is opt-in on PRs and runs nightly. Its standard must be recorded on the 3-GPU H200 runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Subtracting E_q[score] and re-weighting by the sample's own clipped ratio
leaves E_q[1{inside} r (score - E_q[score])] in the gradient. Flow-GRPO's
per-element mean log-prob makes log r normal under the rollout Gaussian, so
E_q[clip_A(r)] has a closed form in kappa = |mu_theta - mu_q|^2 / sigma^2; the
loss adds A * (center - center.detach()) with a hand-written d/dkappa that is
finite at kappa == 0. The rollout's noise stds and stored log-probs are checked
against the trainer's before the closed form is trusted, and the argument
checks grow from two to six (sde type, stock backend, no recompute, clip range).
…ithout --diffusion-recompute-old-log-prob
…DE backend page and CLI reference
Rockdu
force-pushed
the
feat/flow-grpo-score-centering
branch
from
November 4, 2026 01:46
5e86198 to
0d8bea9
Compare
…t_model_output handling below
The one-rollout overlap does not depend on the loss: under policy_loss the engines sample with the previous step's actor weights instead of the EMA. This is the setting score centering is meant for.
…cipe Same 6 + 2 pools, batch, LoRA and OCR eval as the Krea-2 async NFT recipe, with SDE rollouts (noise 0.7, SDE steps 3-4 of 10), PPO clip 1e-4, no KL and no EMA. --no-score-centering runs the plain one-step-async baseline with everything else unchanged. Listed as NV: no complete curve has been run on this code.
…tandard It never had a standard to compare against, so it could not pass in stage-c. The CPU tests cover the closed-form center, the loss integration and the argument checks.
Rockdu
approved these changes
Nov 4, 2026
… an fp8 rollout and the output store
…urves, mark score centering experimental
…he Flow-GRPO loss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
--diffusion-score-centering(experimental) to the Flow-GRPO loss. It ports score centering from Score Centering Stabilizes Off-policy Reinforcement Learning (arXiv:2609.20807) to SDE transitions.Why
Rollout transitions are drawn from the engine's
N(μ_q, s²)and re-scored by the trainer underN(μ_θ, s²). When the two disagree numerically,E_q[∇θ log p_θ] ≠ 0, so the policy gradient picks up a drift term,E[A] · E_q[∇θ log p_θ]. It distills the trainer toward the rollout, and weight sync feeds the bias back each step. Our own committed e2e standards show the mismatch is real:log_prob_mean_abs_diff--diffusion-clip-rangemodel_output_mean_abs_diff~0.05)The PPO log-prob is a per-element mean, so
exp(log p_θ − log q)is not an importance weight and does not cancel drift. That makes Flow-GRPO behave like uncorrected policy gradient plus a clip mask.For a Gaussian step with a θ-independent std the correction is exact and needs only
μ_q:∇θ E_q[log p_θ(x')] = ∇θ log p_θ(μ_q). No top-k approximation is needed, unlike the LLM case.Changes
SdeStepBackend.sde_step_logprobreturns a typedSdeStepOutput(a NamedTuple) that also carries the transitionnoise_std.--diffusion-score-centering(Flow-GRPO only).--diffusion-debug-mode, the only way sglang-diffusion returnsrollout_prev_sample_meanstoday.SdeStepBackend.expected_log_probis the override point for non-Gaussian backends.loss_hub/score_centering.py(score_centering_term); the Flow-GRPO loss only adds that term when the flag is on.train/prev_mean_diff_over_noise_std, the RMS trainer-vs-rollout transition-mean gap in noise-std units. It is logged whenever debug tensors are present.scripts/run_diffusion_grpo_krea2_async.py, Krea-2 async Flow-GRPO + OCR on 4 training + 4 rollout GPUs, 30 prompts × 8 samples per step, 300 rollouts, an fp8 rollout engine with dynamic LoRA, and the output store with a 64gb segment (debug mode stores every step's debug tensors, beyond the 16gb default).--no-score-centeringis the plain async baseline.mainis merged in for the output store (feat(rollout): add --use-output-store with its Mooncake master and the engines' store config #359–feat(fsdp): read a shard's store slices back from the output store before training on it #361, refactor(rollout): read the output store one field per sample and step #370, test(e2e): run the RL e2e tests with the output store on, keep two inline gates #373).test_sd3_ocr_grpo_score_centering_2xGPU(labele2e,stage-c-3-gpu-h200). It runs the canonical SD3.5 OCR recipe with--diffusion-score-centering --diffusion-debug-mode --diffusion-recompute-old-log-prob.Testing
tests/fast: 414 passed, 2 failed.test_hybrid_shard_mesh::test_mesh_axesandtest_metric_buffer_dist::test_metric_buffer_reductionfail identically onmainon that machine (gloo cannot resolve the macOS hostname).Needs a maintainer
I don't have write access, so this is a fork PR. It can't dispatch workflows and gets no CI secrets (the gated SD3.5 download needs
HF_TOKEN). To get it onto the H200s:radixark/miles_diffusion.test=tests/e2e/short/test_sd3_ocr_grpo_score_centering_2xGPU.pyandruns_on=["h200", "3gpu"].tests/ci/fixtures/e2e_standards/test_sd3_ocr_grpo_score_centering_2xGPU.jsonto this PR.run-ci-e2eso stage C verifies the run bit for bit.Deliberately not in this PR
🤖 Generated with Claude Code