Skip to content

[H3-Image 4/4] feat(h3-image): add the 8-GPU OCR Flow-GRPO recipe with LoRA and the model page - #400

Open
zhihengy wants to merge 19 commits into
h3-image/02-familyfrom
h3-image/03-recipe
Open

zhihengy wants to merge 19 commits into
h3-image/02-familyfrom
h3-image/03-recipe

Conversation

@zhihengy

@zhihengy zhihengy commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

[H3-Image 4/4] Stacked on #395. The 8-GPU recipe for MiniMax-H3-Image, t2i Flow-GRPO + OCR with LoRA, and its model page.

Stack: main <- #393 (step index) <- #394 (loader) <- #395 (family) <- #400 (recipe and model page) and #410 (full-weight training), both on #395.

The recipe's rollouts need sgl-project/sglang#51113, which is not in sglang-miles yet:

ci-sglang-pr: #51113

What

  • scripts/run_diffusion_grpo_h3_image_ocr_8gpu.py: FSDP DP=8 colocated with four TP2 rollout engines on 8 GPUs. 512x512, OCR reward, 8 prompts x 16 samples and 2 optimizer steps per rollout, LoRA rank 64 synced over CUDA IPC, --diffusion-debug-mode on, eval on the 1018-prompt test split every 20 rollouts, 200 rollouts.

  • docs/models/h3/h3-image.md: the model page. Family config, launch, what to watch, recipe notes, reference results.

  • A row for the model in docs/index.md and README.md, and the recipe under V in docs/user-guide/recipe-verification.md.

  • miles/backends/fsdp_utils/actor.py (shared): a --debug-rollout-only run skips the checkpoint save. The last rollout always saves and such an actor has loaded no model, so the frozen-weights control the page documents ran its rollouts and then failed in save_model.

  • docs/user-guide/rewards.md: the recipe under the OCR subset and among the OCR reward's users.

Why these settings

The step count, the flow shift and the guidance are fixed by the release (6-step distilled, one output head per step, CFG distilled in). Everything the recipe does choose comes from a measurement on 8 H200; the model page has the tables. [A7]

Setting Measured
cps at 0.8, not flow-sde Against the noise-free rollout of the same prompt and seed, flow-SDE costs PickScore in proportion to its level (0.004 at 0.3, 0.016 at 0.5, about 0.04 at 0.7); cps at 0.8 costs none on any window (sgl-project/sglang#51113)
lr 1e-4 After 20 rollouts eval/ocr_test is 0.621 at 1e-4 and 0.550 at 2e-4, from 0.600
The engine applies the adapters at forward time (--sglang-lora-merge-mode dynamic) Merged into bf16 weights, the engine drifts from the trainer as the adapters grow: first-optimizer-step train/model_output_mean_abs_diff goes from 0.021 on rollout 0 to 0.030 on rollout 24; it stays at 0.020 with dynamic. A sync takes 1.2 s instead of 11.5 s, a rollout 14 s instead of 8 s
The trainer recomputes the old log-probs The engine's and the trainer's differ by 0.7e-4 to 1.7e-4 on the base model, the size of the clip range: 20-38% of the pairs are clipped on a rollout's first optimizer step
All five steps before the last are noisy and trained The last step ends at sigma 0, where cps adds no noise. On 8 fixed prompts the reward rose twice as fast as with a 2-step window. That measures fitting, not generalization; the two windows were not compared on unseen prompts
No gradient checkpointing One pair per forward peaks at 16 GB on the trainer; with checkpointing the training phase took 64 s instead of 47 s

The learning rate is the setting that was first chosen wrong, and the page says how to avoid that. On 8 fixed prompts lr 2e-4 raises the reward 1.5 times as fast as 1e-4. On the full dataset the same 2e-4 makes the policy worse on every prompt it has not trained on. Two readings separate the cases:

  • eval/ocr_test is sampled without noise on fixed prompts, so two evals differ only by the weights.
  • The fixed --rollout-seed and the unshuffled prompt order give rollout k the same prompts and noise in every run; --deterministic-mode reaches only the trainer and makes the trained run itself repeatable. A run's rollout/reward/raw_mean minus that of a --debug-rollout-only run is therefore its gain on unseen prompts, with the prompt-to-prompt spread (0.46 to 0.84 per rollout) cancelled. Rollout 0 differs by exactly 0.
lr eval at rollout 0 eval at rollout 19 Rollout reward minus frozen weights, rollouts 10-19
1e-4 (recipe) 0.6003 0.6213 +0.013 +- 0.007
2e-4 0.6003 0.5500 -0.061 +- 0.013

Validation

On this box, 8 H200, CI-recipe environment with diffusers 0.43.0 and numpy 1.26.4, sglang at sgl-project/sglang#51113 (b5e82c7ea), weights MiniMaxAI/MiniMax-H3-Image at 8ced6006.

One run of the recipe's settings, 1000 rollouts in 22 hours. The recipe stops at 200 (25,600 images, 4.4 hours); train/lr is 1e-4 on every optimizer step, so the recipe's run is the first 200 rollouts of this one.

The second row is the detail left in the 8 eval images wandb logs, always for the same 8 prompts: the mean luminance step between neighbouring pixels.

Rollouts trained 0 100 180 200 240 280 320 400 600 800 1000
eval/ocr_test 0.6003 0.6795 0.8181 0.8303 0.8813 0.8101 0.9141 0.7991 0.9475 0.9650 0.9565
Image detail 0.061 0.066 0.060 0.054 0.035 0.025 0.013 0.022 0.013 0.015 0.016
  • The recipe hacks its reward past 200 rollouts. Up to 180 the eval rises (0.600 to 0.818) with the scene still there. Between 200 and 320 it goes from 0.83 to 0.91 while the image detail falls to a quarter, and from 800 on the images are the quoted text on an empty background. The reward is OCR alone and --diffusion-kl-beta is 0, so nothing in the objective keeps the scene.
  • Before 200 the images are not clean either. From about 140 rollouts the logged eval images carry a fine repeating texture on smooth regions (skin, paper, a sign's background), plain at full size by 160. The detail measure does not see it: over the ten evals up to 180 it stays between 0.059 and 0.066. At 200, where the recipe stops, the scene is there and the measure reads 0.054.
  • The drop at 400 is the scene coming back: the eval is 0.115 below its value at 320 and the image detail is up from 0.013 to 0.022. Not every drop is: from 240 to 280 the eval and the detail fall together.
  • Rollout reward minus the frozen-weights control, which ran its 60 rollouts and then exited FAILED in save_model (fixed here; its metrics were complete): +0.013 +- 0.007 over rollouts 10-19, +0.032 +- 0.006 over 30-39, +0.042 +- 0.006 over 50-59.
  • Two launches of the same settings gave identical rewards on their 21 shared rollouts and the same eval after 20 (0.621282328606862).
  • Cost: 79 s per rollout with the evals (14 s to generate and score 128 images, 47 s to train on their 640 pairs). A GPU peaks near 70 GB.
  • train/model_output_mean_abs_diff on a rollout's first optimizer step is 0.021 and 0.023 over the recipe's 200 rollouts (100-rollout means; 20-rollout means reach 0.025) and falls to 0.010 by 1000, as the scene fades. train/clipfrac on the second optimizer step stays below 0.32 (20-rollout means).
  • The run's argv is the recipe's at this head except --num-rollout and two flags the recipe no longer passes because they change nothing: --diffusion-eval-num-steps 6 (the fallback to --diffusion-num-steps) and --diffusion-log-prob-no-const (forced on for cps).
  • pre-commit run on the changed files is clean. tests/ci/run_suite.py --hw cpu --suite stage-a-cpu at this head (d587966): 688 passed.

Not run:

  • The frozen-weights control was not run again with the save_model guard, nor with the page's command, which no longer passes the --save-interval 100000 that kept its periodic saves from the same crash. The guard is one early return, the same on every rank.
  • No CI suite exercises the recipe. The CI node does not hold the release's transformer_diffusers/, and sglang-miles does not have [Feat] diffusion: [sglang-miles] Serve MiniMax-H3-Image training rollouts (cherry-pick #49552, #49574) sgl-project/sglang#51113.
  • Nothing that keeps the scene has been measured on this model: a KL to the base model (--diffusion-kl-beta, 0.04 in the SD3.5 OCR recipe) or a second reward such as PickScore. A run with KL 0.04 and PickScore as a zero-weight monitor had not finished when this was written.
  • Image detail is a proxy from 8 images per eval. No image-quality reward was logged during the 1000-rollout run.

Open

  • The save_model guard fixes a crash that is on main for any --debug-rollout-only run that reaches a save. It sits here because the page's control needs it; it could go to main first as a one-commit PR.
  • Whether 200 rollouts stays the recipe's endpoint, and the recipe stays under V, given the texture from about 140 rollouts. The page now says what the images show; the endpoint and the status are unchanged here.
  • [H3-Image] feat(h3-image): support full-weight training (per-step head sync and head gradients) #410 lifts the LoRA-only limits the page states (§ 1, § 3, § 5). Whichever of the two lands second updates them.

Not in this PR

eval/ocr_test goes from 0.6003 to 0.8303 over the recipe's 200 rollouts, with one eval at 0.696
after 160. The page says to pick a checkpoint by its eval.
On a 1000-rollout run of these settings eval/ocr_test is 0.830 after 200 rollouts and 0.948 after
600; the 400 rollouts after that add about 0.01.
eval/ocr_test goes from 0.6003 to 0.9475 over the recipe's 600 rollouts and lies between 0.930 and
0.975 from rollout 700 to 1000. The page lists the drops along the way.
Past 200 rollouts the OCR reward keeps rising because the scene is erased: the detail left in the
eval images falls to a fifth by rollout 320, and from 800 on they are text on an empty background.
The reward is OCR alone and the recipe has no KL to the base model.
The results section pairs eval/ocr_test with the detail left in the logged eval images and says
which part of the curve is a real gain.
The last rollout always saves, and a `--debug-rollout-only` actor has loaded no model: the frozen-weights
control the H3 Image page documents ran its 60 rollouts and then failed in `save_model` with an
AttributeError, before the rollout manager was disposed.
`--diffusion-eval-num-steps 6` repeats the fallback to `--diffusion-num-steps`, and the family's own error
tells a user to drop it; `--diffusion-log-prob-no-const` is forced on for cps. The prompt directory is named
as the H3 recipe names it, and the docstring words the cost of gradient checkpointing as the page does.
…d correct the page's numbers

The page called the first 180 rollouts clean. The scene is there, but from about 140 rollouts the logged eval
images carry a repeating texture on smooth regions, which the detail measure cannot see; the page says so, and
says what the 200-rollout endpoint is. "The drops in the eval are the scene coming back" holds for the drop at
400 only. Smaller corrections: detail falls to a quarter, not a fifth; the resolver matches a substring; the
recipe syncs adapters over IPC without merging them; a few figures read off the logs.
…give the recipe window's own numbers

- `--deterministic-mode` reaches only the trainer; the control and a run share prompts and noise through the
  fixed `--rollout-seed` and the unshuffled prompt order.
- The alignment metric was quoted over 1000 rollouts, where it falls as the scene fades. Over the recipe's 200
  it stays between 0.021 and 0.025.
- "20-47% clipped before any update" included a second optimizer step; on first steps it is 20-38%.
- The control command no longer needs `--save-interval 100000` now that a rollout-only run skips the save.
- The recipe's docstring carries the texture caveat the page leads with.

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