Skip to content

[H3-Image 3/4] feat(h3-image): add the MiniMax H3 Image train family for t2i Flow-GRPO with LoRA - #395

Open
zhihengy wants to merge 19 commits into
h3-image/01-loaderfrom
h3-image/02-family
Open

zhihengy wants to merge 19 commits into
h3-image/01-loaderfrom
h3-image/02-family

Conversation

@zhihengy

@zhihengy zhihengy commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

[H3-Image 3/4] Stacked on #394. The train family for MiniMax-H3-Image: t2i Flow-GRPO, LoRA only.

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

  • configs/h3_image.py: family h3_image, a subclass of the H3 family.
    • MiniMaxAI/MiniMax-H3-Image and a local .../h3-image or .../h3_image path resolve to it: the id's pattern minimax-h3-image is longer than H3's minimax-h3. A local path that also contains minimax-h3, such as /data/minimax-h3/h3-image, still resolves to h3 and needs --diffusion-model-family h3_image.
    • compute_noise_pred runs MiniMaxH3ImageTransformer2DModel on the engine's packed t2i layout, at t = 1 - sigma, through the PDD output head of the pair's rollout step, and negates the result like H3 (H3 predicts clean - noise). A step that names none of the model's heads is refused: the built-in expander cannot emit one, but a custom expander's -1 would index a head from the end.
    • apply_rollout_sampling_params sets min_generation_area to --diffusion-width x --diffusion-height, so the engine generates on the requested canvas.
    • validate_args refuses, before anything loads:
      • any loss but policy_loss (no other built-in loss sets the step; custom_loss is untested); --diffusion-flow-shift; trainer sequence parallelism;
      • a run that trains without --use-lora. Only --debug-rollout-only, which has no trainer, is exempt: --train-only syncs nothing but would still train the per-step heads;
      • a run that syncs its LoRA to the engine other than as adapters (colocated --lora-ipc-weight-sync, or adapters over NCCL without --colocate);
      • a config named by --train-pipeline-config-path for a run that syncs to an engine: the fused-qkv LoRA group is looked up by --diffusion-model-family, which a config path leaves unset, so the adapters of q, k and v could split across buckets. That second key is on main for every family; here the run is refused by name;
      • what the engine answers with a 400: a step count other than the release's 6 for rollout or eval (the default --diffusion-num-steps is 10), more than one image per request (--rollout-microgroup-size, --diffusion-output-num-frames), --diffusion-quality high, --diffusion-true-cfg-scale;
      • a micro-batch above one pair (--micro-batch-size, --micro-batch-size-sample, --micro-batch-size-tstep), which the packed forward does not take.
  • models/diffusers/h3_image/parallel_plan.py: H3's FSDP dtype patterns, which cover the image DiT's fp32 modules (proj_in, time_embedder, pdd_proj_out).
  • atomic_groups.py: h3_image gets H3's fused-qkv LoRA group.
  • cli-reference.md: the family key and its task; the three H3-named rollout flags are family h3's alone; --load-debug-rollout-data implies --train-only.
  • miles/utils/arguments.py (shared): train_only is derived from --load-debug-rollout-data before the checks that read it. Four read it before it was set: the family hook, the LoRA sync check, the actor LoRA adapter check (through rollout_merges_lora) and the sft check. A run on dumped rollouts, which starts no engine, was refused for the sync mode of its LoRA.
    • Refused before and accepted now, for every family, under --load-debug-rollout-data: --lora-ipc-weight-sync without --colocate; an rsLoRA or rank/alpha-pattern --lora-adapter-path; --loss-type sft_loss without --train-only (it passes the train-only requirement and goes on to the next sft check).
    • Each of these ends with the same args as its explicit --train-only twin, which was already accepted.

Why

  • A subclass of H3 because the DiT blocks, the packed layout, the time convention and the velocity sign are H3's; only the forward's arguments, the request and the supported settings differ. sglang cuts it the same way (MiniMaxH3ImagePipeline(MiniMaxH3Pipeline)). [A8]
  • LoRA only, and refused at argument validation otherwise, for two reasons. The engine keeps the per-step output heads outside its parameters and skips a pushed pdd_proj_out.* with a warning, so a full-weight run would train heads that never reach the rollout. And on the trainer each rank's pairs can come from different steps, so each rank would give a different head its gradient, which nobody has run under FSDP. [A2] [H3-Image] feat(h3-image): support full-weight training (per-step head sync and head gradients) #410 lifts both.
  • min_generation_area: by default the engine generates a 512x512 request on a 2048x2048 canvas and resizes the image back, which is 16 times the tokens for the trainer too.
  • Trainer sequence parallelism is refused because nobody has run it for this DiT. [A2]
  • The engine's own rejections are repeated at argument time because they arrive late: both sides have loaded the DiT by the first rollout, and the client retries a 400 for a minute before it raises. [A2]
  • Without the fused-qkv group the adapters of to_q, to_k, to_v could reach the engine in different buckets, and its merge replaces a fused layer's LoRA with the sections one request carries.

Contract with the engine

The forward reads what the engine's image rollout returns (sgl-project/sglang#51113, the rollout hook for the image denoise loop): encoder_hidden_states, h3_packed_layout, h3_token_tags, per-step target rows [T + 1, N, 96] fp32, and the trajectory's step numbers. Until #51113 is in sglang-miles, CI's engine has no image pipeline, so the CPU tests build their layouts with sglang's minimax_h3_packed_sequence_ref2va_blocks (latent_t=1, audio_t=0), the function the engine's image path calls.

Validation

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

check result
test_h3_image.py::test_forward_runs_the_output_head_of_the_pairs_step[fp32, bf16] a tiny real MiniMaxH3ImageTransformer2DModel with 3 heads: the prediction for step k equals the negated direct forward with pdd_step_index=k and timestep=1 - sigma; steps 0 and 2 differ
...::test_forward_without_the_rollout_step_is_rejected, ...::test_forward_rejects_a_layout_with_reference_rows pass; the first error names the pair key an expander did not set, not the loss
...::test_forward_rejects_a_step_without_an_output_head[-1, 3] new: on the 3-head model both are a ValueError that names the pair key. Without the check -1 runs the last head and 3 is a bare IndexError
...::test_unsupported_training_settings_are_rejected (12 cases), ...::test_full_weight_training_is_rejected_even_without_an_engine pass
...::test_lora_flow_grpo_is_accepted, ...::test_supported_variations_are_accepted (rollout-only without LoRA, train-only with LoRA, adapters over NCCL without --colocate, 6 eval steps, a config named by path with --train-only) pass
...::test_a_launch_with_the_required_flags_passes_the_real_parser load_fsdp_args, set_default_diffusion_args and miles_validate_args on a launch line, with the parser's own defaults
...::test_micro_batch_tiles_above_one_pair_are_rejected_through_the_parser new: the tiles are folded into micro_batch_size before the family hook reads it
...::test_a_run_on_dumped_rollouts_is_not_held_to_a_sync_mode new: fails without the earlier train_only derivation
test_loss_type_recipes_parse.py::test_a_run_on_dumped_rollouts_counts_as_train_only_for_every_check new, no model family: --use-lora --lora-ipc-weight-sync on dumped rollouts without --colocate validates; with the derivation after the shared LoRA sync check it is refused. The H3 Image case above stops discriminating once #410 accepts a merged LoRA sync
...::test_a_config_named_by_path_cannot_sync_to_an_engine new: fails without the refusal
...::test_parallel_plan_keeps_the_fp32_modules_in_fp32 compile_param_dtype_maps pins exactly the parameters under the class's _keep_in_fp32_modules
test_train_pipeline_config_registry.py::test_known_patterns MiniMaxAI/MiniMax-H3-Image, /data/ckpts/h3-image, /data/ckpts/h3_image -> h3_image; MiniMaxAI/MiniMax-H3 -> h3
test_lora_atomic_update_groups.py::test_fused_qkv_adapters_share_one_bucket[h3_image] pass
test_h3_image.py at this head 30 passed
tests/ci/run_suite.py --hw cpu --suite stage-a-cpu at the stack's two tops, which contain this head 705 passed at #410 (5a79901), 688 at #400 (d587966)
pre-commit run --all-files passes

GPU, H200, the released MiniMaxAI/MiniMax-H3-Image weights (8ced6006), trainer loaded through DiffusersModelBackend.load_component with a bf16 master, engine from sgl-project/sglang#51113 (TP2). These ran at 5aad91a or earlier; the forward has not changed since, and the loader only in its error paths:

check result
compute_noise_pred on a 512x512 t2i layout (256 image rows, 20 text rows), random inputs, once per step of the release's grid all six heads return finite (1, 256, 96) fp32 predictions; at sigma 0.75 head 3 and head 0 differ by up to 0.28 on the same input; 61.9 GiB allocated
trainer against engine: compute_noise_pred on a deterministic rollout's returned latents and conditioning, against the velocity its consecutive latents imply 1.8-3.8% relative error per step, cosine >= 0.9993; as a control, step 3 through head 0 is off by 5.5%, against 2.1% through its own head
LoRA adapters (rank 64, every target module type) pushed through update_weights_from_tensor in one bucket or three Updated 312 LoRA layers ... (skipped 0 unknown layers); the trainer holding the same adapter predicts the engine's velocity to 1.7-3.0% per step, the trainer without it is off by 9-27%; a zero adapter restores the pre-LoRA image and trajectory bit for bit
end to end on 8 H200 (FSDP DP=8 colocated with four TP2 engines), miles at 5aad91a with the next PR's recipe draft on top: cps at noise level 0.8 on 2 of the 6 steps, 8 prompts x 16 samples, OCR reward, engine debug mode 4 rollouts and 8 optimizer steps complete. train/log_prob_mean_abs_diff 0.7e-4 to 1.1e-4; train/model_output_mean_abs_diff 0.020 to 0.027 (the trainer's forward against the engine's own model output, whose mean magnitude is about 1); train/prev_mean_diff_over_noise_std 0.014 to 0.019; 72 GB peak per GPU

Not executed: the GPU suites and the e2e of CI; the adapter sync over NCCL (non-colocated engines) and the async entry point, which accept the same adapters through the same engine call but were not run here. The recipe, its training curve and its e2e are the next PR.

Files

  • miles/backends/fsdp_utils/configs/h3_image.py
  • miles/backends/fsdp_utils/models/diffusers/h3_image/{__init__,parallel_plan}.py
  • miles/backends/training_utils/weight_update/hf_weight_iterator/atomic_groups.py
  • docs/user-guide/cli-reference.md
  • miles/utils/arguments.py
  • tests/fast/backends/fsdp_utils/configs/test_h3_image.py
  • tests/fast/backends/fsdp_utils/configs/test_train_pipeline_config_registry.py
  • tests/fast/utils/test_loss_type_recipes_parse.py
  • tests/fast/backends/training_utils/weight_update/hf_weight_iterator/test_lora_atomic_update_groups.py

Not in this PR

@zhihengy zhihengy changed the title [H3-Image 2/3] feat(h3-image): add the MiniMax H3 Image train family for t2i Flow-GRPO with LoRA [H3-Image 3/4] feat(h3-image): add the MiniMax H3 Image train family for t2i Flow-GRPO with LoRA Nov 17, 2026
@zhihengy
zhihengy added this pull request to stack #396 November 17, 2026 23:34
…PO with LoRA

The family key is `h3_image`; `MiniMaxAI/MiniMax-H3-Image` resolves to it over `h3` by the longer name pattern. Its forward runs `MiniMaxH3ImageTransformer2DModel` on the engine's packed t2i layout and selects the PDD output head by the pair's rollout step. It reuses H3's conditioning, FSDP dtype patterns and fused-qkv LoRA group. Argument validation refuses what cannot work yet: any loss but Flow-GRPO, any weight sync that sends the per-step heads, a flow shift, and trainer sequence parallelism.
… refuses

The default --diffusion-num-steps 10 passed validation and failed at the first rollout with a 400 that the client
retries for a minute, after both sides had loaded the DiT; a micro-batch above one failed at the first train step.
The LoRA requirement now applies only to runs that sync weights, a local path spelled h3_image resolves to this
family, and the plan test goes through compile_param_dtype_maps like H3's. The test file runs in the default CPU
suite like its siblings.
The LoRA check was skipped for --train-only, which syncs nothing but still trains: without --use-lora it would
train all weights, the per-step output heads among them. LoRA is now required unless the run has no trainer
(--debug-rollout-only); the adapter sync mode is required only of runs that sync. The sync error names the form
each topology accepts. A parse-level test drives a launch through the real parser, whose defaults the hand-built
namespace did not have.
…d LoRA errors as what they reject

The family re-derived the sample x timestep tiles that miles_validate_args has already folded into
micro_batch_size, and one test pinned a namespace the parser cannot produce. The loss error claimed no other loss
sets the step, which custom_loss can; the LoRA error spoke of training for a run that only has a trainer.
Adapters over NCCL, the form non-colocated and async runs use, get an accepted case.
…e checks that read it

`miles_validate_args` set `train_only` for a run on dumped rollouts near its end, after the family hook, the
LoRA sync check and the sft check had read it. Such a run starts no engine, yet H3 Image refused it for the
sync mode of its LoRA.
…an engine

`--train-pipeline-config-path` leaves `--diffusion-model-family` unset, and the fused-qkv LoRA group is looked
up by that key: the adapters of to_q, to_k and to_v could reach the engine in different buckets, and its
merge replaces a fused layer's LoRA with the sections one request carries. The lookup by a second key is on
main for every family; here the run is refused by name until the group follows the config class.
…onditions

`--diffusion-quality high` alone was told to drop `--diffusion-true-cfg-scale`, and the condition named the
one level the engine refuses instead of the two it serves.
`validate_args` reads only `micro_batch_size`, which the parser folds the tiles into before the family hook
runs. The cases that set the tile fields on a hand-built namespace read nothing; one launch line through the
parser pins the fold order instead.
The only test of the move went through H3 Image's refusal of a merged LoRA sync, which #410 relaxes. A run on
dumped rollouts with `--lora-ipc-weight-sync` and no `--colocate` is refused by the shared LoRA sync check
when `train_only` is derived after it.
The error blamed the loss, which `validate_args` already restricts to policy_loss. Since the prepare hook
takes pairs without `denoising_step_index`, the forward sees None only when an expander did not set the key.
The forward handed the pair's step to `pdd_proj_out[step]` as it came: a step of -1 from a custom expander
ran the last head without a word, and one past the end raised a bare IndexError.

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