From 9841c409682d135db8534ad11c8a8ca96505aa06 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Tue, 17 Nov 2026 23:15:50 +0000 Subject: [PATCH 01/12] feat(fsdp): pass each Flow-GRPO pair's denoising step to `compute_noise_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. --- docs/user-guide/customization.md | 4 +++- miles/backends/fsdp_utils/actor.py | 1 + miles/backends/fsdp_utils/configs/cosmos3.py | 1 + miles/backends/fsdp_utils/configs/h3.py | 3 ++- miles/backends/fsdp_utils/configs/ltx.py | 1 + .../fsdp_utils/configs/qwen_image21.py | 2 ++ .../configs/train_pipeline_config.py | 7 ++++++- .../backends/fsdp_utils/loss_hub/flow_grpo.py | 2 ++ miles/backends/fsdp_utils/loss_hub/types.py | 2 ++ miles/ray/data_conversion_hub/flow_grpo.py | 1 + .../fsdp_utils/configs/test_qwen_image21.py | 1 + .../test_train_pipeline_config_registry.py | 1 + .../backends/fsdp_utils/test_h3_streams.py | 4 ++++ .../backends/fsdp_utils/test_loss_hub_dmd2.py | 1 + .../fsdp_utils/test_reference_models.py | 20 +++++++++++++++++++ .../fast/rollout/test_traj_window_convert.py | 11 ++++++++-- 16 files changed, 57 insertions(+), 5 deletions(-) diff --git a/docs/user-guide/customization.md b/docs/user-guide/customization.md index d4eed2185..e4e136415 100644 --- a/docs/user-guide/customization.md +++ b/docs/user-guide/customization.md @@ -296,7 +296,9 @@ counts from 0; the old-log-prob recompute of windows 1.. passes their training f `timesteps_for_model` are keyed by latent stream name: `"visual"`, plus e.g. `"audio"` for joint audio-video models. `PreparedBatch.teacher_guidance_scale` asks the trunk to run the frozen teacher (`--teacher-load`) without grad on this micro-batch at that CFG scale, over `neg_cond` / `joint_cond`, before -the training forward; the formula receives it as `teacher_pred`. +the training forward; the formula receives it as `teacher_pred`. `PreparedBatch.denoising_step_indices` hands the +family's forward each row's step number in its rollout's schedule; leave it unset when the loss samples its own noise +levels. ### `--custom-loss-function-path` diff --git a/miles/backends/fsdp_utils/actor.py b/miles/backends/fsdp_utils/actor.py index b948f444c..4c2c6e290 100644 --- a/miles/backends/fsdp_utils/actor.py +++ b/miles/backends/fsdp_utils/actor.py @@ -554,6 +554,7 @@ def _compute_noise_pred( model=model, latents_input=latents_in, timesteps_input=timesteps_in, + denoising_step_indices=prepared.denoising_step_indices, pos_cond=pos_cond_in, neg_cond=neg_cond_in, joint_cond=joint_cond_in, diff --git a/miles/backends/fsdp_utils/configs/cosmos3.py b/miles/backends/fsdp_utils/configs/cosmos3.py index 827662b42..4d2e616b0 100644 --- a/miles/backends/fsdp_utils/configs/cosmos3.py +++ b/miles/backends/fsdp_utils/configs/cosmos3.py @@ -74,6 +74,7 @@ def compute_noise_pred( model: torch.nn.Module, latents_input: dict[str, torch.Tensor], timesteps_input: dict[str, torch.Tensor], + denoising_step_indices: torch.Tensor | None, pos_cond: dict | None, neg_cond: dict | None, joint_cond: dict | None, diff --git a/miles/backends/fsdp_utils/configs/h3.py b/miles/backends/fsdp_utils/configs/h3.py index 2b80d95c7..eeaf8e3c7 100644 --- a/miles/backends/fsdp_utils/configs/h3.py +++ b/miles/backends/fsdp_utils/configs/h3.py @@ -125,6 +125,7 @@ def compute_noise_pred( model: torch.nn.Module, latents_input: dict[str, torch.Tensor], timesteps_input: dict[str, torch.Tensor], + denoising_step_indices: torch.Tensor | None, pos_cond: dict | None, neg_cond: dict | None, joint_cond: dict | None, @@ -145,7 +146,7 @@ def compute_noise_pred( RL feeds the visual stream alone, so its audio rows stay zero at the video time. """ - del neg_cond, joint_cond, use_cfg, cfg_batching, guidance_scale, true_cfg_scale + del denoising_step_indices, neg_cond, joint_cond, use_cfg, cfg_batching, guidance_scale, true_cfg_scale cond = pos_cond visual = latents_input["visual"] device, dtype = visual.device, visual.dtype diff --git a/miles/backends/fsdp_utils/configs/ltx.py b/miles/backends/fsdp_utils/configs/ltx.py index 9b6ef9269..c2fc5196e 100644 --- a/miles/backends/fsdp_utils/configs/ltx.py +++ b/miles/backends/fsdp_utils/configs/ltx.py @@ -90,6 +90,7 @@ def compute_noise_pred( model: torch.nn.Module, latents_input: dict[str, torch.Tensor], timesteps_input: dict[str, torch.Tensor], + denoising_step_indices: torch.Tensor | None, pos_cond: dict | None, neg_cond: dict | None, joint_cond: dict | None, diff --git a/miles/backends/fsdp_utils/configs/qwen_image21.py b/miles/backends/fsdp_utils/configs/qwen_image21.py index 1dc55755a..5d93dd565 100644 --- a/miles/backends/fsdp_utils/configs/qwen_image21.py +++ b/miles/backends/fsdp_utils/configs/qwen_image21.py @@ -169,6 +169,7 @@ def compute_noise_pred( model: torch.nn.Module, latents_input: dict[str, torch.Tensor], timesteps_input: dict[str, torch.Tensor], + denoising_step_indices: torch.Tensor | None, pos_cond: dict | None, neg_cond: dict | None, joint_cond: dict | None, @@ -182,6 +183,7 @@ def compute_noise_pred( model=model, latents_input=latents_input, timesteps_input=timesteps_input, + denoising_step_indices=denoising_step_indices, pos_cond=pos_cond, neg_cond=neg_cond, joint_cond=joint_cond, diff --git a/miles/backends/fsdp_utils/configs/train_pipeline_config.py b/miles/backends/fsdp_utils/configs/train_pipeline_config.py index 82b0b0e4b..5a45e1deb 100644 --- a/miles/backends/fsdp_utils/configs/train_pipeline_config.py +++ b/miles/backends/fsdp_utils/configs/train_pipeline_config.py @@ -143,6 +143,7 @@ def compute_noise_pred( model: torch.nn.Module, latents_input: dict[str, torch.Tensor], timesteps_input: dict[str, torch.Tensor], + denoising_step_indices: torch.Tensor | None, pos_cond: dict | None, neg_cond: dict | None, joint_cond: dict | None, @@ -151,7 +152,11 @@ def compute_noise_pred( guidance_scale: float, true_cfg_scale: float | None, ) -> dict[str, torch.Tensor]: - """Default diffusers forward with CFG over the visual stream; families with a different forward override.""" + """Default diffusers forward with CFG over the visual stream; families with a different forward override. + + ``denoising_step_indices`` is each row's step number in its rollout's schedule, for a DiT whose forward + depends on the step; None when the loss samples its own noise levels. + """ latents = latents_input["visual"] timesteps = timesteps_input["visual"] diff --git a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py index acb203b7f..b63872570 100644 --- a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py +++ b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py @@ -40,6 +40,7 @@ def prepare_flow_grpo_batch( next_sigmas = _stack_pair_field(batch, "next_sigma", device) sigma_max = _stack_pair_field(batch, "sigma_max", device) log_prob_old = _stack_pair_field(batch, "log_prob_old", device) + denoising_step_indices = torch.stack([pair["denoising_step_index"] for pair in batch]).to(device) advantage = torch.tensor( [float(pair["advantage"]) for pair in batch], device=device, @@ -109,6 +110,7 @@ def prepare_flow_grpo_batch( "sigma_max": sigma_max, "log_prob_old": log_prob_old, }, + denoising_step_indices=denoising_step_indices, ) diff --git a/miles/backends/fsdp_utils/loss_hub/types.py b/miles/backends/fsdp_utils/loss_hub/types.py index 449d49a34..ede3327f3 100644 --- a/miles/backends/fsdp_utils/loss_hub/types.py +++ b/miles/backends/fsdp_utils/loss_hub/types.py @@ -71,3 +71,5 @@ class PreparedBatch: extras: dict[str, Any] = field(default_factory=dict) # CFG scale of the frozen teacher's no-grad forward on this batch; None runs no teacher forward. teacher_guidance_scale: float | None = None + # each row's step number in its rollout's schedule; None when the loss samples its own noise levels + denoising_step_indices: torch.Tensor | None = None diff --git a/miles/ray/data_conversion_hub/flow_grpo.py b/miles/ray/data_conversion_hub/flow_grpo.py index 9712b0e93..f8614f843 100644 --- a/miles/ray/data_conversion_hub/flow_grpo.py +++ b/miles/ray/data_conversion_hub/flow_grpo.py @@ -132,6 +132,7 @@ def _build_per_timestep_features( return { "latent": [_own_row(all_latents[position[int(s)]]) for s in sde_idx], "next_latent": [_own_row(all_latents[position[int(s) + 1]]) for s in sde_idx], + "denoising_step_index": idx, "timestep": timesteps[idx], "sigma": sigmas[idx], "next_sigma": sigmas[idx + 1], diff --git a/tests/fast/backends/fsdp_utils/configs/test_qwen_image21.py b/tests/fast/backends/fsdp_utils/configs/test_qwen_image21.py index 9920be40f..f1987f6af 100644 --- a/tests/fast/backends/fsdp_utils/configs/test_qwen_image21.py +++ b/tests/fast/backends/fsdp_utils/configs/test_qwen_image21.py @@ -88,6 +88,7 @@ def test_compute_noise_pred_keeps_target_tail(): model=_TailDiT(), latents_input={"visual": latents}, timesteps_input={"visual": torch.tensor([0.5])}, + denoising_step_indices=None, pos_cond={}, neg_cond=None, joint_cond=None, diff --git a/tests/fast/backends/fsdp_utils/configs/test_train_pipeline_config_registry.py b/tests/fast/backends/fsdp_utils/configs/test_train_pipeline_config_registry.py index 9735eff5e..c3b77913e 100644 --- a/tests/fast/backends/fsdp_utils/configs/test_train_pipeline_config_registry.py +++ b/tests/fast/backends/fsdp_utils/configs/test_train_pipeline_config_registry.py @@ -90,6 +90,7 @@ def _call(self, **overrides): model=_CondBiasDiT(), latents_input={"visual": self.h}, timesteps_input={"visual": torch.tensor([3.0, 5.0])}, + denoising_step_indices=None, pos_cond=self.pos, neg_cond=self.neg, joint_cond=None, diff --git a/tests/fast/backends/fsdp_utils/test_h3_streams.py b/tests/fast/backends/fsdp_utils/test_h3_streams.py index 0f56dd4b0..f8178de55 100644 --- a/tests/fast/backends/fsdp_utils/test_h3_streams.py +++ b/tests/fast/backends/fsdp_utils/test_h3_streams.py @@ -109,6 +109,7 @@ def test_t2va_prediction_matches_the_sft_target_and_skips_padding_rows(): model=context.models["transformer"], latents_input=prepared.latents, timesteps_input=prepared.timesteps_for_model, + denoising_step_indices=prepared.denoising_step_indices, pos_cond=prepared.pos_cond, neg_cond=None, joint_cond=None, @@ -175,6 +176,7 @@ def _forward(model, latents, timesteps, cond): model=model, latents_input=latents, timesteps_input=timesteps, + denoising_step_indices=None, pos_cond=cond, neg_cond=None, joint_cond=None, @@ -229,6 +231,7 @@ def test_t2va_joint_pair_feeds_audio_at_its_own_time(has_soundtrack): model=model, latents_input=latents, timesteps_input={"visual": _timestep(0.25), "audio": _timestep(0.75)}, + denoising_step_indices=None, pos_cond=cond, neg_cond=None, joint_cond=None, @@ -420,6 +423,7 @@ def test_real_tiny_diffusers_h3_joint_sft_forward_and_backward(forward_dtype): model=model, latents_input=prepared.latents, timesteps_input=prepared.timesteps_for_model, + denoising_step_indices=prepared.denoising_step_indices, pos_cond=prepared.pos_cond, neg_cond=None, joint_cond=None, diff --git a/tests/fast/backends/fsdp_utils/test_loss_hub_dmd2.py b/tests/fast/backends/fsdp_utils/test_loss_hub_dmd2.py index aa3a08501..7a952560c 100644 --- a/tests/fast/backends/fsdp_utils/test_loss_hub_dmd2.py +++ b/tests/fast/backends/fsdp_utils/test_loss_hub_dmd2.py @@ -145,6 +145,7 @@ def _forward(config, model, prepared, *, use_cfg, cfg_batching, guidance_scale): model=model, latents_input=prepared.latents, timesteps_input=prepared.timesteps_for_model, + denoising_step_indices=prepared.denoising_step_indices, pos_cond=prepared.pos_cond, neg_cond=prepared.neg_cond, joint_cond=prepared.joint_cond, diff --git a/tests/fast/backends/fsdp_utils/test_reference_models.py b/tests/fast/backends/fsdp_utils/test_reference_models.py index e90e271a2..5c30e0bee 100644 --- a/tests/fast/backends/fsdp_utils/test_reference_models.py +++ b/tests/fast/backends/fsdp_utils/test_reference_models.py @@ -157,6 +157,7 @@ def make_actor_forward_harness( teacher_models=None, teacher_guidance_scale=None, true_cfg_scale=None, + denoising_step_indices=None, ): observed = {} prepared = SimpleNamespace( @@ -172,6 +173,7 @@ def make_actor_forward_harness( guidance_scale=1.0, true_cfg_scale=true_cfg_scale, teacher_guidance_scale=teacher_guidance_scale, + denoising_step_indices=denoising_step_indices, ) def prepare(ctx, batch, **kwargs): @@ -583,6 +585,24 @@ def test_the_teacher_runs_first_without_grad_with_its_own_cfg(cfg_batching): assert actor_call["true_cfg_scale"] == 7.0 +def test_the_family_forward_receives_the_prepared_denoising_steps(): + """A DiT with one output head per step runs the wrong head if the actor drops the step numbers.""" + denoising_step_indices = torch.tensor([3, 4]) + harness, _ = make_actor_forward_harness( + {"transformer": TinyComponent()}, + {}, + "transformer", + torch.ones(2, 3), + None, + denoising_step_indices=denoising_step_indices, + ) + + _run_forward(harness) + + [(_, actor_call)] = harness.train_pipeline_config.noise_pred_calls + assert actor_call["denoising_step_indices"] is denoising_step_indices + + def test_an_unguided_teacher_runs_without_cfg(): harness, _, _, teacher = _teacher_harness(1.0) harness.train_pipeline_config.cfg_batching = True diff --git a/tests/fast/rollout/test_traj_window_convert.py b/tests/fast/rollout/test_traj_window_convert.py index 14bffaf7c..16933501c 100644 --- a/tests/fast/rollout/test_traj_window_convert.py +++ b/tests/fast/rollout/test_traj_window_convert.py @@ -12,8 +12,9 @@ the full trajectory (1), full trajectories without provenance keep the legacy behaviour (2), a missing window latent raises instead of mispairing (3), a non-contiguous kept set still pairs correctly (4), NFT reads x0 off a -final-step-only trajectory but rejects one ending anywhere else (5), and the -final SDE step pairs with next_sigma == 0 (6). +final-step-only trajectory but rejects one ending anywhere else (5), the +final SDE step pairs with next_sigma == 0 (6), and a pair carries its step's +number in the rollout, not its position in the shipped window (7). """ from tests.ci.ci_register import register_cpu_ci @@ -91,6 +92,12 @@ def test_terminal_step_next_sigma_is_zero(): assert feats["next_sigma"].item() == 0.0 +def test_pair_carries_the_rollout_step_number_not_the_window_position(): + """A window ships step 2 at position 0; a DiT with one output head per step needs the 2.""" + feats, _ = _build(_windowed(_full_traj(), [2, 3, 4])) + assert feats["denoising_step_index"].tolist() == SDE + + def test_missing_window_latent_raises(): with pytest.raises(ValueError, match="lacks latents"): _build(_windowed(_full_traj(), [2, 3])) # boundary latent 4 missing From 76fa9d3d30bfbd3c8ab1135139d2db7be70407d9 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:37:04 +0000 Subject: [PATCH 02/12] fix(fsdp): accept an int or a tensor scalar as a pair's denoising step 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. --- miles/backends/fsdp_utils/loss_hub/flow_grpo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py index b63872570..8b9013ea6 100644 --- a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py +++ b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py @@ -40,7 +40,7 @@ def prepare_flow_grpo_batch( next_sigmas = _stack_pair_field(batch, "next_sigma", device) sigma_max = _stack_pair_field(batch, "sigma_max", device) log_prob_old = _stack_pair_field(batch, "log_prob_old", device) - denoising_step_indices = torch.stack([pair["denoising_step_index"] for pair in batch]).to(device) + denoising_step_indices = torch.tensor([int(pair["denoising_step_index"]) for pair in batch], device=device) advantage = torch.tensor( [float(pair["advantage"]) for pair in batch], device=device, From 9f724acf3f3e9b46c02e0b0b4b35dba6bae4224b Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:37:04 +0000 Subject: [PATCH 03/12] test(fsdp): cover the Flow-GRPO prepare hook's step indices Nothing called prepare_flow_grpo_batch, so dropping the field or stacking another one kept every test green. --- .../fsdp_utils/test_reference_models.py | 2 +- .../fast/rollout/test_traj_window_convert.py | 51 ++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/tests/fast/backends/fsdp_utils/test_reference_models.py b/tests/fast/backends/fsdp_utils/test_reference_models.py index 5c30e0bee..e32feca30 100644 --- a/tests/fast/backends/fsdp_utils/test_reference_models.py +++ b/tests/fast/backends/fsdp_utils/test_reference_models.py @@ -586,7 +586,7 @@ def test_the_teacher_runs_first_without_grad_with_its_own_cfg(cfg_batching): def test_the_family_forward_receives_the_prepared_denoising_steps(): - """A DiT with one output head per step runs the wrong head if the actor drops the step numbers.""" + """The actor passes the prepared steps through unchanged; a head-per-step DiT would run another step's head.""" denoising_step_indices = torch.tensor([3, 4]) harness, _ = make_actor_forward_harness( {"transformer": TinyComponent()}, diff --git a/tests/fast/rollout/test_traj_window_convert.py b/tests/fast/rollout/test_traj_window_convert.py index 16933501c..cdb5ce272 100644 --- a/tests/fast/rollout/test_traj_window_convert.py +++ b/tests/fast/rollout/test_traj_window_convert.py @@ -13,8 +13,9 @@ behaviour (2), a missing window latent raises instead of mispairing (3), a non-contiguous kept set still pairs correctly (4), NFT reads x0 off a final-step-only trajectory but rejects one ending anywhere else (5), the -final SDE step pairs with next_sigma == 0 (6), and a pair carries its step's -number in the rollout, not its position in the shipped window (7). +final SDE step pairs with next_sigma == 0 (6), a pair carries its step's +number in the rollout, not its position in the shipped window (7), and the +trainer's prepare hook hands each row of a micro-batch its own pair's step (8). """ from tests.ci.ci_register import register_cpu_ci @@ -98,6 +99,52 @@ def test_pair_carries_the_rollout_step_number_not_the_window_position(): assert feats["denoising_step_index"].tolist() == SDE +def test_prepared_batch_carries_each_pairs_rollout_step(): + """Samples with different SDE windows share a micro-batch; a row given a neighbour's step runs its head.""" + from types import SimpleNamespace + + from miles.backends.fsdp_utils.loss_hub.flow_grpo import prepare_flow_grpo_batch + from miles.ray.data_conversion_hub.flow_grpo import expand_samples_to_train_pairs + from miles.utils.types import DenoisingEnv + + class _Family: + cfg_batching = False + + def process_timestep_as_input(self, timesteps): + return timesteps + + def prepare_cond_kwargs(self, cond, device): + return {} + + def collate_cond_for_sample_batch(self, conds, device, pad_to_len=None): + return {} + + samples = [ + Sample( + index=index, + prompt="p", + train_metadata={"sde_step_indices": sde}, + dit_trajectory=_windowed(_full_traj(), kept), + denoising_env=DenoisingEnv(), + rollout_log_probs=torch.zeros(T), + ) + for index, (sde, kept) in enumerate([([2, 3], [2, 3, 4]), ([6, 7], [6, 7, 8])]) + ] + pairs = expand_samples_to_train_pairs(None, samples, [0.1, 0.2], [0.1, 0.2])["train_data"] + ctx = SimpleNamespace( + args=SimpleNamespace(diffusion_adv_clip_max=5.0, diffusion_guidance_scale=1.0, diffusion_true_cfg_scale=None), + device=torch.device("cpu"), + train_pipeline_config=_Family(), + models={"transformer": torch.nn.Identity()}, + ) + + prepared = prepare_flow_grpo_batch(ctx, pairs, microbatch_id=0, optim_step_idx=0) + + assert prepared.denoising_step_indices.tolist() == [2, 3, 6, 7] + assert prepared.denoising_step_indices.dtype == torch.long + assert torch.equal(prepared.extras["sigmas"], _full_traj().sigmas[[2, 3, 6, 7]]) + + def test_missing_window_latent_raises(): with pytest.raises(ValueError, match="lacks latents"): _build(_windowed(_full_traj(), [2, 3])) # boundary latent 4 missing From 311ab48e8bea69a8a8810827877627c6be01e9a7 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:37:04 +0000 Subject: [PATCH 04/12] docs(fsdp): state the shape of denoising_step_indices and which hooks 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. --- docs/user-guide/customization.md | 7 ++++--- miles/backends/fsdp_utils/configs/train_pipeline_config.py | 5 +++-- miles/backends/fsdp_utils/loss_hub/types.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/user-guide/customization.md b/docs/user-guide/customization.md index e4e136415..4b6e3b94b 100644 --- a/docs/user-guide/customization.md +++ b/docs/user-guide/customization.md @@ -268,7 +268,8 @@ def expand_samples_to_train_pairs(args, samples, rewards, raw_rewards) -> dict: ... ``` -Default for Flow-GRPO lives under `miles/ray/data_conversion_hub/flow_grpo.py`. +Default for Flow-GRPO lives under `miles/ray/data_conversion_hub/flow_grpo.py`. Pairs that feed the built-in +Flow-GRPO prepare hook carry `denoising_step_index`, the pair's 0-based step in its rollout's schedule. ### `--custom-convert-samples-to-train-data-path` @@ -297,8 +298,8 @@ counts from 0; the old-log-prob recompute of windows 1.. passes their training f `"audio"` for joint audio-video models. `PreparedBatch.teacher_guidance_scale` asks the trunk to run the frozen teacher (`--teacher-load`) without grad on this micro-batch at that CFG scale, over `neg_cond` / `joint_cond`, before the training forward; the formula receives it as `teacher_pred`. `PreparedBatch.denoising_step_indices` hands the -family's forward each row's step number in its rollout's schedule; leave it unset when the loss samples its own noise -levels. +family's forward each pair's 0-based denoising step in its rollout's schedule (`[B]` long); of the built-in hooks only +Flow-GRPO's sets it, and a family whose forward needs it rejects a batch without it. ### `--custom-loss-function-path` diff --git a/miles/backends/fsdp_utils/configs/train_pipeline_config.py b/miles/backends/fsdp_utils/configs/train_pipeline_config.py index 5a45e1deb..6cd983b70 100644 --- a/miles/backends/fsdp_utils/configs/train_pipeline_config.py +++ b/miles/backends/fsdp_utils/configs/train_pipeline_config.py @@ -154,8 +154,9 @@ def compute_noise_pred( ) -> dict[str, torch.Tensor]: """Default diffusers forward with CFG over the visual stream; families with a different forward override. - ``denoising_step_indices`` is each row's step number in its rollout's schedule, for a DiT whose forward - depends on the step; None when the loss samples its own noise levels. + ``denoising_step_indices`` is ``[B]`` long: each pair's 0-based denoising step in its rollout's schedule + (not doubled for the CFG joint batch), for a DiT whose forward depends on the step. None unless the + prepare hook sets it; of the built-in hooks only Flow-GRPO's does. """ latents = latents_input["visual"] timesteps = timesteps_input["visual"] diff --git a/miles/backends/fsdp_utils/loss_hub/types.py b/miles/backends/fsdp_utils/loss_hub/types.py index ede3327f3..ebbfb71fb 100644 --- a/miles/backends/fsdp_utils/loss_hub/types.py +++ b/miles/backends/fsdp_utils/loss_hub/types.py @@ -71,5 +71,5 @@ class PreparedBatch: extras: dict[str, Any] = field(default_factory=dict) # CFG scale of the frozen teacher's no-grad forward on this batch; None runs no teacher forward. teacher_guidance_scale: float | None = None - # each row's step number in its rollout's schedule; None when the loss samples its own noise levels + # [B] long, each pair's 0-based denoising step in its rollout's schedule; of the built-in hooks only Flow-GRPO's sets it denoising_step_indices: torch.Tensor | None = None From ce2e7da556408d0746ff104fb2cf005697e90800 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:24:41 +0000 Subject: [PATCH 05/12] test(fsdp): feed the prepare hook a pair whose step index is a plain int The prepare hook accepts an int or a tensor scalar, and only the tensor was exercised. --- tests/fast/rollout/test_traj_window_convert.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/fast/rollout/test_traj_window_convert.py b/tests/fast/rollout/test_traj_window_convert.py index cdb5ce272..e81d3fd19 100644 --- a/tests/fast/rollout/test_traj_window_convert.py +++ b/tests/fast/rollout/test_traj_window_convert.py @@ -131,6 +131,8 @@ def collate_cond_for_sample_batch(self, conds, device, pad_to_len=None): for index, (sde, kept) in enumerate([([2, 3], [2, 3, 4]), ([6, 7], [6, 7, 8])]) ] pairs = expand_samples_to_train_pairs(None, samples, [0.1, 0.2], [0.1, 0.2])["train_data"] + # a custom expander may emit the step as a plain int + pairs[1]["denoising_step_index"] = int(pairs[1]["denoising_step_index"]) ctx = SimpleNamespace( args=SimpleNamespace(diffusion_adv_clip_max=5.0, diffusion_guidance_scale=1.0, diffusion_true_cfg_scale=None), device=torch.device("cpu"), From 2af314317954cdb8ec032b896e4b3baf43361199 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:16:57 +0000 Subject: [PATCH 06/12] test(rollout): drop the pair-key test the prepare test covers `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. --- tests/fast/rollout/test_traj_window_convert.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/fast/rollout/test_traj_window_convert.py b/tests/fast/rollout/test_traj_window_convert.py index e81d3fd19..f1a8f38e9 100644 --- a/tests/fast/rollout/test_traj_window_convert.py +++ b/tests/fast/rollout/test_traj_window_convert.py @@ -13,14 +13,14 @@ behaviour (2), a missing window latent raises instead of mispairing (3), a non-contiguous kept set still pairs correctly (4), NFT reads x0 off a final-step-only trajectory but rejects one ending anywhere else (5), the -final SDE step pairs with next_sigma == 0 (6), a pair carries its step's -number in the rollout, not its position in the shipped window (7), and the -trainer's prepare hook hands each row of a micro-batch its own pair's step (8). +final SDE step pairs with next_sigma == 0 (6), and the trainer's prepare hook +hands each row of a micro-batch its own pair's step in the rollout, not its +position in the shipped window (7). """ from tests.ci.ci_register import register_cpu_ci -register_cpu_ci(est_time=10, suite="stage-a-cpu", labels=[]) +register_cpu_ci(est_time=20, suite="stage-a-cpu", labels=[]) import pytest import torch @@ -93,12 +93,6 @@ def test_terminal_step_next_sigma_is_zero(): assert feats["next_sigma"].item() == 0.0 -def test_pair_carries_the_rollout_step_number_not_the_window_position(): - """A window ships step 2 at position 0; a DiT with one output head per step needs the 2.""" - feats, _ = _build(_windowed(_full_traj(), [2, 3, 4])) - assert feats["denoising_step_index"].tolist() == SDE - - def test_prepared_batch_carries_each_pairs_rollout_step(): """Samples with different SDE windows share a micro-batch; a row given a neighbour's step runs its head.""" from types import SimpleNamespace From 8064cca44dc61ae3e0a046510c4dedaad5a12a77 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:16:57 +0000 Subject: [PATCH 07/12] fix(fsdp): prepare Flow-GRPO pairs that carry no denoising step 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. --- .../backends/fsdp_utils/loss_hub/flow_grpo.py | 15 +++++++- .../fast/rollout/test_traj_window_convert.py | 37 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py index 8b9013ea6..acbfe68bd 100644 --- a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py +++ b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py @@ -2,6 +2,8 @@ from __future__ import annotations +import operator + import torch from miles.backends.fsdp_utils.loss_hub.score_centering import score_centering_term @@ -15,6 +17,17 @@ def _stack_pair_field(batch: list[dict], key: str, device: torch.device) -> torc return torch.stack([pair[key] for pair in batch]).to(device=device, dtype=torch.float32) +def _stack_denoising_step_indices(batch: list[dict], device: torch.device) -> torch.Tensor | None: + """``[B]`` long from each pair's ``denoising_step_index``; None when the expander recorded no step.""" + steps = [pair.get("denoising_step_index") for pair in batch] + if all(step is None for step in steps): + return None + if any(step is None for step in steps): + raise ValueError("only some pairs of this micro-batch carry denoising_step_index; an expander sets it on all") + # operator.index: an int or an integer tensor scalar, never a float + return torch.tensor([operator.index(step) for step in steps], device=device) + + def prepare_flow_grpo_batch( ctx: DiffusionLossContext, batch: list[dict], @@ -40,7 +53,7 @@ def prepare_flow_grpo_batch( next_sigmas = _stack_pair_field(batch, "next_sigma", device) sigma_max = _stack_pair_field(batch, "sigma_max", device) log_prob_old = _stack_pair_field(batch, "log_prob_old", device) - denoising_step_indices = torch.tensor([int(pair["denoising_step_index"]) for pair in batch], device=device) + denoising_step_indices = _stack_denoising_step_indices(batch, device) advantage = torch.tensor( [float(pair["advantage"]) for pair in batch], device=device, diff --git a/tests/fast/rollout/test_traj_window_convert.py b/tests/fast/rollout/test_traj_window_convert.py index f1a8f38e9..920df4e94 100644 --- a/tests/fast/rollout/test_traj_window_convert.py +++ b/tests/fast/rollout/test_traj_window_convert.py @@ -15,7 +15,7 @@ final-step-only trajectory but rejects one ending anywhere else (5), the final SDE step pairs with next_sigma == 0 (6), and the trainer's prepare hook hands each row of a micro-batch its own pair's step in the rollout, not its -position in the shipped window (7). +position in the shipped window, or no steps when the pairs carry none (7). """ from tests.ci.ci_register import register_cpu_ci @@ -93,8 +93,8 @@ def test_terminal_step_next_sigma_is_zero(): assert feats["next_sigma"].item() == 0.0 -def test_prepared_batch_carries_each_pairs_rollout_step(): - """Samples with different SDE windows share a micro-batch; a row given a neighbour's step runs its head.""" +def _prepare_pairs_of_two_windows(edit_pairs=lambda pairs: None): + """Two samples with different SDE windows, expanded and prepared as one micro-batch.""" from types import SimpleNamespace from miles.backends.fsdp_utils.loss_hub.flow_grpo import prepare_flow_grpo_batch @@ -125,22 +125,47 @@ def collate_cond_for_sample_batch(self, conds, device, pad_to_len=None): for index, (sde, kept) in enumerate([([2, 3], [2, 3, 4]), ([6, 7], [6, 7, 8])]) ] pairs = expand_samples_to_train_pairs(None, samples, [0.1, 0.2], [0.1, 0.2])["train_data"] - # a custom expander may emit the step as a plain int - pairs[1]["denoising_step_index"] = int(pairs[1]["denoising_step_index"]) + edit_pairs(pairs) ctx = SimpleNamespace( args=SimpleNamespace(diffusion_adv_clip_max=5.0, diffusion_guidance_scale=1.0, diffusion_true_cfg_scale=None), device=torch.device("cpu"), train_pipeline_config=_Family(), models={"transformer": torch.nn.Identity()}, ) + return prepare_flow_grpo_batch(ctx, pairs, microbatch_id=0, optim_step_idx=0) + + +def test_prepared_batch_carries_each_pairs_rollout_step(): + """Samples with different SDE windows share a micro-batch; a row given a neighbour's step runs its head.""" + + def emit_one_step_as_a_plain_int(pairs): + pairs[1]["denoising_step_index"] = int(pairs[1]["denoising_step_index"]) - prepared = prepare_flow_grpo_batch(ctx, pairs, microbatch_id=0, optim_step_idx=0) + prepared = _prepare_pairs_of_two_windows(emit_one_step_as_a_plain_int) assert prepared.denoising_step_indices.tolist() == [2, 3, 6, 7] assert prepared.denoising_step_indices.dtype == torch.long assert torch.equal(prepared.extras["sigmas"], _full_traj().sigmas[[2, 3, 6, 7]]) +def test_pairs_without_a_step_prepare_without_step_indices(): + """An expander written before the key existed still feeds the families whose forward ignores the step.""" + + def drop_the_step(pairs): + for pair in pairs: + del pair["denoising_step_index"] + + assert _prepare_pairs_of_two_windows(drop_the_step).denoising_step_indices is None + + +def test_a_micro_batch_with_the_step_on_only_some_pairs_is_rejected(): + def drop_one_step(pairs): + del pairs[2]["denoising_step_index"] + + with pytest.raises(ValueError, match="only some pairs"): + _prepare_pairs_of_two_windows(drop_one_step) + + def test_missing_window_latent_raises(): with pytest.raises(ValueError, match="lacks latents"): _build(_windowed(_full_traj(), [2, 3])) # boundary latent 4 missing From 9721f86cae0a72f23430c8199b82a33472517cb2 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:17:03 +0000 Subject: [PATCH 08/12] docs(fsdp): state the step-index contract as what an expander and a family 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. --- docs/user-guide/customization.md | 11 +++++++---- .../fsdp_utils/configs/train_pipeline_config.py | 4 ++-- miles/backends/fsdp_utils/loss_hub/types.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/user-guide/customization.md b/docs/user-guide/customization.md index 4b6e3b94b..6965063f9 100644 --- a/docs/user-guide/customization.md +++ b/docs/user-guide/customization.md @@ -268,8 +268,10 @@ def expand_samples_to_train_pairs(args, samples, rewards, raw_rewards) -> dict: ... ``` -Default for Flow-GRPO lives under `miles/ray/data_conversion_hub/flow_grpo.py`. Pairs that feed the built-in -Flow-GRPO prepare hook carry `denoising_step_index`, the pair's 0-based step in its rollout's schedule. +Default for Flow-GRPO lives under `miles/ray/data_conversion_hub/flow_grpo.py`. It sets `denoising_step_index` on +every pair: the pair's 0-based step in its rollout's schedule. An expander that feeds the built-in Flow-GRPO prepare +hook for a family whose forward depends on the step must set it too, as an int or an integer tensor scalar, on all +pairs or on none. ### `--custom-convert-samples-to-train-data-path` @@ -298,8 +300,9 @@ counts from 0; the old-log-prob recompute of windows 1.. passes their training f `"audio"` for joint audio-video models. `PreparedBatch.teacher_guidance_scale` asks the trunk to run the frozen teacher (`--teacher-load`) without grad on this micro-batch at that CFG scale, over `neg_cond` / `joint_cond`, before the training forward; the formula receives it as `teacher_pred`. `PreparedBatch.denoising_step_indices` hands the -family's forward each pair's 0-based denoising step in its rollout's schedule (`[B]` long); of the built-in hooks only -Flow-GRPO's sets it, and a family whose forward needs it rejects a batch without it. +family's forward each pair's 0-based denoising step in its rollout's schedule (`[B]` long). It is `None` when the +prepare hook has none: of the built-in hooks only Flow-GRPO's sets it, from pairs that carry `denoising_step_index`. +A family whose forward needs it must raise on `None`. ### `--custom-loss-function-path` diff --git a/miles/backends/fsdp_utils/configs/train_pipeline_config.py b/miles/backends/fsdp_utils/configs/train_pipeline_config.py index 6cd983b70..c65e62569 100644 --- a/miles/backends/fsdp_utils/configs/train_pipeline_config.py +++ b/miles/backends/fsdp_utils/configs/train_pipeline_config.py @@ -155,8 +155,8 @@ def compute_noise_pred( """Default diffusers forward with CFG over the visual stream; families with a different forward override. ``denoising_step_indices`` is ``[B]`` long: each pair's 0-based denoising step in its rollout's schedule - (not doubled for the CFG joint batch), for a DiT whose forward depends on the step. None unless the - prepare hook sets it; of the built-in hooks only Flow-GRPO's does. + (not doubled for the CFG joint batch), for a DiT whose forward depends on the step. None when the + prepare hook has none. """ latents = latents_input["visual"] timesteps = timesteps_input["visual"] diff --git a/miles/backends/fsdp_utils/loss_hub/types.py b/miles/backends/fsdp_utils/loss_hub/types.py index ebbfb71fb..f73c980bc 100644 --- a/miles/backends/fsdp_utils/loss_hub/types.py +++ b/miles/backends/fsdp_utils/loss_hub/types.py @@ -71,5 +71,5 @@ class PreparedBatch: extras: dict[str, Any] = field(default_factory=dict) # CFG scale of the frozen teacher's no-grad forward on this batch; None runs no teacher forward. teacher_guidance_scale: float | None = None - # [B] long, each pair's 0-based denoising step in its rollout's schedule; of the built-in hooks only Flow-GRPO's sets it + # [B] long: each pair's 0-based denoising step in its rollout's schedule; None when the prepare hook has none denoising_step_indices: torch.Tensor | None = None From 87357e0e1d0c3e90ddb8e413147ff2d0bb7895fa Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:51:03 +0000 Subject: [PATCH 09/12] fix(fsdp): name the pair key when a denoising step is not an integer 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. --- miles/backends/fsdp_utils/loss_hub/flow_grpo.py | 12 +++++++++--- tests/fast/rollout/test_traj_window_convert.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py index acbfe68bd..92dfa2aa8 100644 --- a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py +++ b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py @@ -23,9 +23,15 @@ def _stack_denoising_step_indices(batch: list[dict], device: torch.device) -> to if all(step is None for step in steps): return None if any(step is None for step in steps): - raise ValueError("only some pairs of this micro-batch carry denoising_step_index; an expander sets it on all") - # operator.index: an int or an integer tensor scalar, never a float - return torch.tensor([operator.index(step) for step in steps], device=device) + raise ValueError( + "only some pairs of this micro-batch carry denoising_step_index; an expander sets it on every pair or on none" + ) + try: + # operator.index: an int or an integer tensor scalar, never a float + steps = [operator.index(step) for step in steps] + except TypeError as error: + raise ValueError(f"denoising_step_index must be an int or an integer tensor scalar: {error}") from error + return torch.tensor(steps, device=device) def prepare_flow_grpo_batch( diff --git a/tests/fast/rollout/test_traj_window_convert.py b/tests/fast/rollout/test_traj_window_convert.py index 920df4e94..985ed7101 100644 --- a/tests/fast/rollout/test_traj_window_convert.py +++ b/tests/fast/rollout/test_traj_window_convert.py @@ -166,6 +166,16 @@ def drop_one_step(pairs): _prepare_pairs_of_two_windows(drop_one_step) +def test_a_step_that_is_not_an_integer_is_rejected(): + """Truncating 2.7 to 2 would run the pair through another step's output head.""" + + def emit_one_step_as_a_float(pairs): + pairs[0]["denoising_step_index"] = float(pairs[0]["denoising_step_index"]) + 0.7 + + with pytest.raises(ValueError, match="denoising_step_index must be an int"): + _prepare_pairs_of_two_windows(emit_one_step_as_a_float) + + def test_missing_window_latent_raises(): with pytest.raises(ValueError, match="lacks latents"): _build(_windowed(_full_traj(), [2, 3])) # boundary latent 4 missing From e23c16c0fddb910c7cfc3351f86d100b6ec36330 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:51:03 +0000 Subject: [PATCH 10/12] docs(fsdp): the step key goes on every pair or on none; a step-dependent family needs it on every pair --- docs/user-guide/customization.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user-guide/customization.md b/docs/user-guide/customization.md index 6965063f9..72f1b73d5 100644 --- a/docs/user-guide/customization.md +++ b/docs/user-guide/customization.md @@ -270,8 +270,8 @@ def expand_samples_to_train_pairs(args, samples, rewards, raw_rewards) -> dict: Default for Flow-GRPO lives under `miles/ray/data_conversion_hub/flow_grpo.py`. It sets `denoising_step_index` on every pair: the pair's 0-based step in its rollout's schedule. An expander that feeds the built-in Flow-GRPO prepare -hook for a family whose forward depends on the step must set it too, as an int or an integer tensor scalar, on all -pairs or on none. +hook sets it on every pair or on none, as an int or an integer tensor scalar; a family whose forward depends on the +step needs it on every pair. ### `--custom-convert-samples-to-train-data-path` From f22889fdb26fc1d7066dfb7ce0f58a4a687e25e8 Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:48:05 +0000 Subject: [PATCH 11/12] docs(fsdp): say what denoising_step_indices is once, on the PreparedBatch 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. --- miles/backends/fsdp_utils/configs/train_pipeline_config.py | 7 +------ miles/backends/fsdp_utils/loss_hub/flow_grpo.py | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/miles/backends/fsdp_utils/configs/train_pipeline_config.py b/miles/backends/fsdp_utils/configs/train_pipeline_config.py index c65e62569..46e98bff9 100644 --- a/miles/backends/fsdp_utils/configs/train_pipeline_config.py +++ b/miles/backends/fsdp_utils/configs/train_pipeline_config.py @@ -152,12 +152,7 @@ def compute_noise_pred( guidance_scale: float, true_cfg_scale: float | None, ) -> dict[str, torch.Tensor]: - """Default diffusers forward with CFG over the visual stream; families with a different forward override. - - ``denoising_step_indices`` is ``[B]`` long: each pair's 0-based denoising step in its rollout's schedule - (not doubled for the CFG joint batch), for a DiT whose forward depends on the step. None when the - prepare hook has none. - """ + """Default diffusers forward with CFG over the visual stream; families with a different forward override.""" latents = latents_input["visual"] timesteps = timesteps_input["visual"] diff --git a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py index 92dfa2aa8..0800420d3 100644 --- a/miles/backends/fsdp_utils/loss_hub/flow_grpo.py +++ b/miles/backends/fsdp_utils/loss_hub/flow_grpo.py @@ -18,7 +18,6 @@ def _stack_pair_field(batch: list[dict], key: str, device: torch.device) -> torc def _stack_denoising_step_indices(batch: list[dict], device: torch.device) -> torch.Tensor | None: - """``[B]`` long from each pair's ``denoising_step_index``; None when the expander recorded no step.""" steps = [pair.get("denoising_step_index") for pair in batch] if all(step is None for step in steps): return None @@ -27,7 +26,6 @@ def _stack_denoising_step_indices(batch: list[dict], device: torch.device) -> to "only some pairs of this micro-batch carry denoising_step_index; an expander sets it on every pair or on none" ) try: - # operator.index: an int or an integer tensor scalar, never a float steps = [operator.index(step) for step in steps] except TypeError as error: raise ValueError(f"denoising_step_index must be an int or an integer tensor scalar: {error}") from error From 957918752937416062fb00acf3ac57a0621d528e Mon Sep 17 00:00:00 2001 From: Andy Ye <89891424+zhihengy@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:48:05 +0000 Subject: [PATCH 12/12] docs(fsdp): cut the step-index notes in customization.md to a sentence 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. --- docs/user-guide/customization.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/user-guide/customization.md b/docs/user-guide/customization.md index 72f1b73d5..e38085831 100644 --- a/docs/user-guide/customization.md +++ b/docs/user-guide/customization.md @@ -269,9 +269,7 @@ def expand_samples_to_train_pairs(args, samples, rewards, raw_rewards) -> dict: ``` Default for Flow-GRPO lives under `miles/ray/data_conversion_hub/flow_grpo.py`. It sets `denoising_step_index` on -every pair: the pair's 0-based step in its rollout's schedule. An expander that feeds the built-in Flow-GRPO prepare -hook sets it on every pair or on none, as an int or an integer tensor scalar; a family whose forward depends on the -step needs it on every pair. +every pair (the pair's 0-based step in its rollout's schedule), which a family whose forward depends on the step needs. ### `--custom-convert-samples-to-train-data-path` @@ -299,10 +297,8 @@ counts from 0; the old-log-prob recompute of windows 1.. passes their training f `timesteps_for_model` are keyed by latent stream name: `"visual"`, plus e.g. `"audio"` for joint audio-video models. `PreparedBatch.teacher_guidance_scale` asks the trunk to run the frozen teacher (`--teacher-load`) without grad on this micro-batch at that CFG scale, over `neg_cond` / `joint_cond`, before -the training forward; the formula receives it as `teacher_pred`. `PreparedBatch.denoising_step_indices` hands the -family's forward each pair's 0-based denoising step in its rollout's schedule (`[B]` long). It is `None` when the -prepare hook has none: of the built-in hooks only Flow-GRPO's sets it, from pairs that carry `denoising_step_index`. -A family whose forward needs it must raise on `None`. +the training forward; the formula receives it as `teacher_pred`. `PreparedBatch.denoising_step_indices` (`[B]` long) +reaches the family's forward; of the built-in hooks only Flow-GRPO's sets it, from the pairs' `denoising_step_index`. ### `--custom-loss-function-path`