Skip to content

[H3-Image 1/4] feat(fsdp): pass each Flow-GRPO pair's denoising step to compute_noise_pred - #393

Open
zhihengy wants to merge 12 commits into
mainfrom
fsdp/denoising-step-index-to-forward
Open

zhihengy wants to merge 12 commits into
mainfrom
fsdp/denoising-step-index-to-forward

Conversation

@zhihengy

@zhihengy zhihengy commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

[H3-Image 1/4] MiniMax-H3-Image's DiT has one output head per denoising step: the family's forward has to know which step a train pair came from, and today it receives only the timestep. No behaviour change for the existing families.

Stack: main <- #393 (step index) <- #394 (loader) <- #395 (family) <- #400 (recipe and model page) and #410 (full-weight training), both on #395. #392 (diffusers 0.43.0) has merged, so the stack runs in the default CI image.

What

  • data_conversion_hub/flow_grpo.py: every Flow-GRPO train pair carries denoising_step_index, its step number in the rollout's schedule.
  • prepare_flow_grpo_batch batches it into the new PreparedBatch.denoising_step_indices ([B] long, 0-based). Of the built-in prepare hooks only this one sets it; the others leave it None, and so does this one when no pair carries the key. The key on only some pairs of a micro-batch is an error.
  • FSDPTrainRayActor._forward_train_pair_batch passes it to TrainPipelineConfig.compute_noise_pred as a new keyword argument. The base forward and the four overrides (Cosmos3, H3, LTX, Qwen-Image 2.1) accept it and do not read it.
  • Docs: PreparedBatch.denoising_step_indices and the pair key in customization.md.

Why

  • The step is a fact the rollout owns and already ships (sde_step_indices, plus latent_step_indices when the engine returns a window), so the trainer receives it instead of matching the timestep against a release's sigma grid. [A4]
  • It is an explicit argument of the forward hook, not a key inside timesteps_input or the cond dict: timesteps_input is keyed by latent stream, and the step is per row. [A5]
  • It is its own PR because every line is shared code and none is specific to H3-Image; the family that reads it is [H3-Image 3/4] feat(h3-image): add the MiniMax H3 Image train family for t2i Flow-GRPO with LoRA #395. [A8]

Behaviour ledger

  • Existing families: unchanged, the argument is ignored.
  • One contract that out-of-tree code implements or calls gets wider, and fails by name at the first micro-batch: a TrainPipelineConfig subclass that overrides compute_noise_pred must accept denoising_step_indices, and a hook that calls compute_noise_pred itself must pass it (it has no default), else TypeError.
  • An expander given through --custom-expand-samples-to-train-pairs-path, or a --custom-convert-samples-to-train-data-path override, that feeds the built-in Flow-GRPO prepare does not have to emit denoising_step_index. Without it the prepared field is None, which only a family whose forward needs the step rejects. One that emits it sets an int or an integer tensor scalar on every pair of a micro-batch; any other value is a ValueError that names the pair key.
  • Alternative not taken: pass the argument only to a config that declares it needs it. That breaks nobody but gives one hook two shapes.

Validation

CPU, on this box, CI-recipe environment with diffusers 0.43.0, head 9579187:

check result
test_traj_window_convert.py::test_prepared_batch_carries_each_pairs_rollout_step new: expander to prepare_flow_grpo_batch, two samples with windows [2, 3] and [6, 7] in one micro-batch give [2, 3, 6, 7], long, with one pair carrying a plain int. It fails when the prepare hook drops the field or stacks the position in the window
...::test_pairs_without_a_step_prepare_without_step_indices, ...::test_a_micro_batch_with_the_step_on_only_some_pairs_is_rejected new: pairs without the key prepare with None; the key on some pairs only raises
...::test_a_step_that_is_not_an_integer_is_rejected new: a float step raises by the key's name. With int() in place of operator.index a step of 2.7 would run the pair through step 2's head
test_reference_models.py::test_the_family_forward_receives_the_prepared_denoising_steps new: the production actor forward hands the prepared tensor to the hook
tests/ci/run_suite.py --hw cpu --suite stage-a-cpu at the stack's two tops, which contain this head 704 passed at #410 (bed8b8d, with the engine branch that PR pins), 686 at #400 (e6259e3)
pre-commit run --all-files passes

Not executed: the GPU suites and the e2e. No e2e standard is expected to move, since no existing family reads the argument.

Follow-ups

  • DMD2's generator hook also trains each pair on its rollout step, which its pairs carry as step_index, and leaves denoising_step_indices unset. Nothing reads it there today ([H3-Image 3/4] feat(h3-image): add the MiniMax H3 Image train family for t2i Flow-GRPO with LoRA #395 accepts only policy_loss). Setting it, and giving the two pair keys one name, belongs with the first family that needs the step under DMD2.
  • DiffusionNFT's expander is in the same position: it picks each pair's train step and keeps only its timestep, and its prepare hook leaves the field unset.

@zhihengy
zhihengy changed the base branch from main to chore/bump-diffusers-0.43 November 17, 2026 23:26
@zhihengy zhihengy changed the title feat(fsdp): pass each Flow-GRPO pair's denoising step to compute_noise_pred [H3-Image 1/4] feat(fsdp): pass each Flow-GRPO pair's denoising step to compute_noise_pred Nov 17, 2026
@zhihengy
zhihengy added this pull request to stack #396 November 17, 2026 23:34
Base automatically changed from chore/bump-diffusers-0.43 to main November 18, 2026 06:30
…se_pred`

A DiT with one output head per denoising step (MiniMax-H3-Image's PDD heads) cannot choose the head from the timestep input alone. The rollout already records which step a train pair came from, so the pair now carries it as `denoising_step_index`, the Flow-GRPO prepare hook batches it into `PreparedBatch.denoising_step_indices`, and the actor hands it to the family's forward. A loss that samples its own noise levels leaves it None. The existing families ignore it.
…p index

A custom expander that emits the step as a Python int, as the DMD2 one does for its own key, failed in torch.stack.
Nothing called prepare_flow_grpo_batch, so dropping the field or stacking another one kept every test green.
… set it

DMD2's generator hook also trains on its rollout's step and leaves the field None, so the None rule is which hook
sets it, not whether the loss samples its own noise levels.
The prepare hook accepts an int or a tensor scalar, and only the tensor was exercised.
`test_prepared_batch_carries_each_pairs_rollout_step` runs the real expander on two windowed trajectories and
checks the steps after the prepare hook, so the test that read the same key off one pair could not fail alone.
The file's estimate goes to 20 s: the prepare test imports the loss hub, which takes about 9 s.
The built-in prepare hook read `denoising_step_index` off every pair, so a custom expander written before the
key existed failed with a KeyError on every family, though only a family whose forward depends on the step
reads it. Pairs without the key now prepare with `denoising_step_indices=None`, which such a family rejects
by name; a micro-batch with the key on only some pairs is an error, and so is a step that is not an integer.
…amily must do

"A family whose forward needs it rejects a batch without it" read as something the framework does; it is the
family's job. The field's comment and the forward's docstring no longer list which built-in hooks set it,
which the user guide says once.
A float step raised operator.index's bare TypeError, and no test pinned that it raises at all: with int() a
step of 2.7 would run the pair through step 2's head.
…atch field

The base forward's docstring and the stacking helper's repeated the field comment, and the operator.index
comment repeated the error below it.
…e each

The every-pair-or-none and integer rules are the prepare hook's error messages; the guide keeps what the
default expander sets and where the prepared field goes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant