Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2682ce5
feat(h3-image): add the MiniMax H3 Image train family for t2i Flow-GR…
zhihengy Nov 17, 2026
29da8d1
fix(h3-image): reject at argument time what the engine or the forward…
zhihengy Nov 18, 2026
a5c672c
docs(h3-image): list the family in the CLI reference
zhihengy Nov 18, 2026
5b62490
fix(h3-image): require LoRA whenever the trainer runs
zhihengy Nov 18, 2026
958db5a
fix(h3-image): check the folded micro-batch size and word the loss an…
zhihengy Nov 18, 2026
f8cee3e
Merge h3-image/01-loader into h3-image/02-family
zhihengy Nov 20, 2026
af1ac5a
fix(args): derive train_only from --load-debug-rollout-data before th…
zhihengy Nov 20, 2026
29191e5
fix(h3-image): refuse a config named by path for a run that syncs to …
zhihengy Nov 20, 2026
5b8b83f
fix(h3-image): give the quality and the guidance refusals their own c…
zhihengy Nov 20, 2026
a287c1d
test(h3-image): check the micro-batch tiles through the parser
zhihengy Nov 20, 2026
6f098bb
docs(cli): say the H3 rollout flags are family h3's alone
zhihengy Nov 20, 2026
09a51b8
Merge h3-image/01-loader into h3-image/02-family
zhihengy Nov 20, 2026
e6961ad
test(args): pin the early train_only derivation without a model family
zhihengy Nov 20, 2026
8045752
fix(h3-image): say what a forward without the denoising step is missing
zhihengy Nov 20, 2026
64eb077
refactor(h3-image): name once the condition under which the run syncs…
zhihengy Nov 20, 2026
a427d1e
docs(cli): --load-debug-rollout-data implies --train-only
zhihengy Nov 20, 2026
1572c3d
Merge h3-image/01-loader into h3-image/02-family
zhihengy Nov 20, 2026
fcd56d4
fix(h3-image): refuse a denoising step that names no output head
zhihengy Nov 20, 2026
81949fe
Merge h3-image/01-loader into h3-image/02-family
zhihengy Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/user-guide/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ See [Dtype Control](../advanced/dtype-control.md).
| Flag | Type | Default | Notes |
|---|---|---|---|
| `--hf-checkpoint` | str | – | **Required.** Pipeline to train and to serve; also the family source. |
| `--diffusion-model-family` | str | – | Registered family key: `sd3`, `wan2_2`, `ltx`, `qwen_image`, `qwen_image21`, `cosmos3`, `krea2`, `h3`. Overrides name matching. The longest pattern wins, so `Qwen-Image-2.1` resolves to `qwen_image21`. |
| `--diffusion-task` | str | – | **Required** unless the config declares no `tasks`. The task to train, one of the family config's `tasks`: `t2i` (sd3, krea2, qwen_image, qwen_image21, cosmos3), `t2v` (wan2_2, ltx), `t2va` (h3, the only H3 rollout task) or `ref2va` (h3 joint video/audio SFT with ordered references on `transformer_ref`). |
| `--diffusion-model-family` | str | – | Registered family key: `sd3`, `wan2_2`, `ltx`, `qwen_image`, `qwen_image21`, `cosmos3`, `krea2`, `h3`, `h3_image`. Overrides name matching. The longest pattern wins, so `Qwen-Image-2.1` resolves to `qwen_image21`. |
| `--diffusion-task` | str | – | **Required** unless the config declares no `tasks`. The task to train, one of the family config's `tasks`: `t2i` (sd3, krea2, qwen_image, qwen_image21, cosmos3, h3_image), `t2v` (wan2_2, ltx), `t2va` (h3, the only H3 rollout task) or `ref2va` (h3 joint video/audio SFT with ordered references on `transformer_ref`). |
| `--rollout-function-path` | str | `miles.rollout.sglang_rollout.generate_rollout` | Inherited Miles default; that module is not shipped in miles-diffusion, so set it — diffusion recipes pass `miles.rollout.sglang_diffusion_rollout.generate_rollout`. |
| `--train-pipeline-config-path` | str | – | Your own `TrainPipelineConfig` for an unregistered family. Mutually exclusive with `--diffusion-model-family`. |
| `--model-backend-path` | str | – | Override the family's model loader. |
Expand All @@ -192,9 +192,9 @@ See [Dtype Control](../advanced/dtype-control.md).
| `--diffusion-noise-level` | float | `0.7` | |
| `--diffusion-quality` | enum | `exact` | `exact` / `lossless` / `high`: sglang-diffusion request quality level. `exact` is the bit-identical reference path; the looser levels mount rounding-changing fusions. |
| `--diffusion-height` / `--diffusion-width` | int | `512` | Rollout output size; SFT target media must already be this size. |
| `--diffusion-h3-aspect-ratio` | str | `16:9` | MiniMax H3 only: `21:9` / `16:9` / `4:3` / `1:1` / `3:4` / `9:16`. |
| `--diffusion-h3-duration-seconds` | float | `5.0` | MiniMax H3 only: rollout duration, 4.0–15.0 s. |
| `--diffusion-audio-flow-shift` | float | `3.0` | MiniMax H3 only: audio flow shift for rollout. |
| `--diffusion-h3-aspect-ratio` | str | `16:9` | Family `h3` only (`h3_image` takes its canvas from `--diffusion-width` / `--diffusion-height`): `21:9` / `16:9` / `4:3` / `1:1` / `3:4` / `9:16`. |
| `--diffusion-h3-duration-seconds` | float | `5.0` | Family `h3` only: rollout duration, 4.0–15.0 s. |
| `--diffusion-audio-flow-shift` | float | `3.0` | Family `h3` only: audio flow shift for rollout. |
| `--diffusion-sde-type` | str | `sde` | `sde` / `cps` / `ode`, checked at startup unless `--sde-step-backend-path` is set. Selects the train-side SDE backend too. |
| `--sde-step-backend-path` | str | – | Custom dynamics. See [SDE backends](#sde-step-backends). |
| `--diffusion-num-sde-steps` | int | `0` | Read by the step strategy. |
Expand Down Expand Up @@ -409,7 +409,7 @@ Every one takes a dotted path.
| `--debug-skip-optimizer-step` | flag | off | No backward/step — weights never drift. Use it to measure pure forward divergence from the engine. |
| `--save-debug-rollout-data` | path template | – | Fills `{rollout_id}`. |
| `--save-eval-media-dir` | path | – | Keeps every eval sample's video (with its audio when the engine returns it) or image under `<dir>/eval_<rollout_id>/`, with an `index.jsonl` of prompts, seeds and rewards. Independent of `--wandb-log-num-images`. |
| `--load-debug-rollout-data` | path template | – | Replays a rollout with **no engines started**. |
| `--load-debug-rollout-data` | path template | – | Replays a rollout with **no engines started**; implies `--train-only`, also for the checks that refuse a setting only when an engine runs. |
| `--load-debug-rollout-data-subsample` | float | – | |
| `--save-debug-train-data` | path template | – | Fills `{rollout_id}` and `{rank}`. |
| `--dump-details` | dir | – | Sets the debug dump paths for post-hoc analysis. |
Expand Down
145 changes: 145 additions & 0 deletions miles/backends/fsdp_utils/configs/h3_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"""MiniMax H3 Image: t2i Flow-GRPO on the release's PDD grid, LoRA only."""

from __future__ import annotations

from argparse import Namespace

import torch

from .h3 import H3TrainPipelineConfig, _without_padding_tail
from .train_pipeline_config import register_train_pipeline_config


@register_train_pipeline_config("h3_image")
class H3ImageTrainPipelineConfig(H3TrainPipelineConfig):
"""MiniMax H3 Image: the H3 DiT without audio rows, with one output head per denoising step."""

tasks = ("t2i",)
hf_ckpt_name_patterns = ("minimax-h3-image", "minimax_h3_image", "/h3-image", "/h3_image")
# the release's sigma grid, one output head per step
num_denoising_steps = 6

@classmethod
def validate_args(cls, args: Namespace) -> None:
from miles.utils.arguments import rollout_merges_lora

if args.loss_type != "policy_loss":
raise ValueError(
"H3 Image trains with --loss-type policy_loss only: its DiT picks an output head by the rollout's "
"denoising step, which no other built-in loss sets, and custom_loss is untested"
)
has_trainer = not args.debug_rollout_only
syncs_weights_to_rollout = has_trainer and not args.train_only
if has_trainer and not args.use_lora:
raise ValueError(
"H3 Image runs its trainer with LoRA adapters only (--use-lora): full-weight training would update "
"the DiT's per-step output heads, each from the ranks whose pairs came from its step, which is untested"
)
if syncs_weights_to_rollout and not rollout_merges_lora(args):
raise ValueError(
"H3 Image syncs its LoRA as adapters (--lora-ipc-weight-sync under --colocate, plain --use-lora "
"otherwise): a merged sync sends the DiT's per-step output heads, which the rollout engine cannot "
"receive"
)
if syncs_weights_to_rollout and args.diffusion_model_family != cls.model_family:
raise ValueError(
"H3 Image named by --train-pipeline-config-path cannot sync to a rollout engine: the fused-qkv LoRA "
"group is looked up by --diffusion-model-family, which a config path leaves unset. Let "
"--hf-checkpoint or --diffusion-model-family name the family, or run --train-only"
)
if args.diffusion_flow_shift is not None:
raise ValueError("H3 Image samples on its release's sigma grid; drop --diffusion-flow-shift")
if args.sequence_parallel_size != 1:
raise ValueError("H3 Image is untested with trainer sequence parallelism; set --sequence-parallel-size 1")
if args.diffusion_num_steps != cls.num_denoising_steps or args.diffusion_eval_num_steps not in (
None,
cls.num_denoising_steps,
):
raise ValueError(
f"H3 Image has one output head per step of its release's {cls.num_denoising_steps}-step grid; set "
f"--diffusion-num-steps {cls.num_denoising_steps} and drop --diffusion-eval-num-steps"
)
if args.rollout_microgroup_size != 1 or args.diffusion_output_num_frames != 1:
raise ValueError(
"H3 Image rollout serves one image per request; keep --rollout-microgroup-size and "
"--diffusion-output-num-frames at 1"
)
# miles_validate_args has folded the sample x timestep tiles into micro_batch_size
if args.micro_batch_size != 1:
raise ValueError(
"H3 Image's packed forward takes one pair; keep --micro-batch-size, --micro-batch-size-sample and "
"--micro-batch-size-tstep at 1"
)
if args.diffusion_quality not in ("exact", "lossless"):
raise ValueError(
f"H3 Image rollout serves --diffusion-quality exact or lossless, got {args.diffusion_quality!r}"
)
if args.diffusion_true_cfg_scale not in (None, 1.0):
raise ValueError("H3 Image rollout is unguided; drop --diffusion-true-cfg-scale")

@classmethod
def apply_rollout_sampling_params(
cls,
args: Namespace,
sampling_params: dict,
extra_sampling_params: dict,
) -> None:
# the engine generates a request below its default area on a larger canvas and resizes the image back
extra_sampling_params["min_generation_area"] = int(args.diffusion_width) * int(args.diffusion_height)

def compute_noise_pred(
self,
*,
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,
use_cfg: bool,
cfg_batching: bool,
guidance_scale: float,
true_cfg_scale: float | None,
) -> dict[str, torch.Tensor]:
"""Run the H3 Image forward on the target image rows, through the output head of the pair's rollout step."""
del neg_cond, joint_cond, use_cfg, cfg_batching, guidance_scale, true_cfg_scale
if denoising_step_indices is None:
raise ValueError(
"H3 Image picks its output head by each pair's denoising step, which these pairs do not carry: "
"an expander that feeds Flow-GRPO must set denoising_step_index on every pair"
)
step = int(denoising_step_indices.item())
num_heads = len(model.pdd_proj_out)
# a negative step would index a head from the end
if not 0 <= step < num_heads:
raise ValueError(
f"denoising_step_index {step} is not one of H3 Image's {num_heads} per-step output heads "
f"(0..{num_heads - 1})"
)
cond = pos_cond
visual = latents_input["visual"]
device, dtype = visual.device, visual.dtype
if visual.shape[0] != 1:
raise NotImplementedError("H3 Image packed forward supports batch size 1 for now")

layout = {k: (v.to(device) if isinstance(v, torch.Tensor) else v) for k, v in cond["h3_packed_layout"].items()}
token_tags, position_ids = _without_padding_tail(layout, torch.as_tensor(cond["h3_token_tags"], device=device))
if not bool(layout["update_mask"].all()):
raise NotImplementedError("H3 Image trains t2i only; this layout carries reference image rows")

out = model(
hidden_states=visual,
encoder_hidden_states=cond["encoder_hidden_states"].to(device=device, dtype=dtype),
# H3 time runs from t=0 noise to t=1 clean; every row of a t2i sequence is at the target's time
timestep=(1.0 - timesteps_input["visual"].float() / float(self.num_train_timesteps)).view(-1).to(dtype),
timestep_indices=torch.zeros(token_tags.shape[0], device=device, dtype=torch.long),
token_tags=token_tags.long(),
position_ids=position_ids.to(device=device, dtype=torch.float32),
image_indices=layout["img_pos"].view(-1).long(),
text_indices=layout["text_pos"].view(-1).long(),
pdd_step_index=step,
return_dict=False,
)
# H3 predicts clean - noise; the shared flow objective predicts noise - clean.
return {"visual": (-out[0]).to(dtype)}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# the H3 patterns cover H3 Image's fp32 modules: proj_in, time_embedder, pdd_proj_out
from miles.backends.fsdp_utils.models.diffusers.h3.parallel_plan import FSDP_PARALLEL_PLAN

__all__ = ["FSDP_PARALLEL_PLAN"]
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@


def get_hf_atomic_update_groups(diffusion_model_family: str | None) -> list[AtomicUpdateGroup]:
"""Atomic groups for a diffusion model family. H3 fuses to_q/k/v into qkv_proj; Qwen-Image and Cosmos3
fuse add_q/k/v_proj (into to_added_qkv / cross_attention.to_qkv)."""
if diffusion_model_family == "h3":
"""Atomic groups for a diffusion model family. H3 and H3 Image fuse to_q/k/v into qkv_proj; Qwen-Image and
Cosmos3 fuse add_q/k/v_proj (into to_added_qkv / cross_attention.to_qkv)."""
if diffusion_model_family in ("h3", "h3_image"):
return list(_H3_LORA_GROUPS)
if diffusion_model_family in ("qwen_image", "cosmos3"):
return list(_ADDED_QKV_LORA_GROUPS)
Expand Down
15 changes: 8 additions & 7 deletions miles/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,14 @@ def validate_dmd2_args(args) -> None:


def miles_validate_args(args):
# before the checks below that read train_only
if args.load_debug_rollout_data is not None:
logger.info(
f"load_debug_rollout_data {args.load_debug_rollout_data} is set, "
"will not instantiate sglang servers and will only run the training process."
)
args.train_only = True

args.eval_datasets = _resolve_eval_datasets(args)

if args.eval_interval is not None:
Expand Down Expand Up @@ -2257,13 +2265,6 @@ def miles_validate_args(args):
args.save_debug_rollout_data = f"{args.dump_details}/rollout_data/{{rollout_id}}.pt"
args.save_debug_train_data = f"{args.dump_details}/train_data/{{rollout_id}}_{{rank}}.pt"

if args.load_debug_rollout_data is not None:
logger.info(
f"load_debug_rollout_data {args.load_debug_rollout_data} is set, "
"will not instantiate sglang servers and will only run the training process."
)
args.train_only = True

validate_output_store_args(args)

if args.offload:
Expand Down
Loading
Loading