Skip to content

Studio: LoRA training for MiniMax-H3-Image, and loading the trained LoRA - #17863

Merged
danielhanchen merged 15 commits into
mainfrom
studio-train-minimax-h3-image
Nov 16, 2026
Merged

danielhanchen merged 15 commits into
mainfrom
studio-train-minimax-h3-image

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Summary

MiniMax-H3-Image could not be trained in Studio (the family was not trainable and no trainer handled its distilled 6-step DiT). This adds LoRA training for it, and loading the trained LoRA for H3-Image generation.

How it works

  • Trainer (core/training/diffusion_h3_image_trainer.py, on diffusion_train_common, like the MiniMax-H3 video trainer): captions are encoded once with the hosted int8 Qwen3-VL-32B conditioner, which is then freed; VAE latents are cached, each picture on its own canvas of about resolution^2 pixels at its own aspect (batch 1). The DiT loads through the same converter inference uses, AdaLN as the timestep table; Auto picks a bf16 base with 56 GB or more free, else an int8 weight-only base.
  • Objective: each step draws one of the sampler's 6 distilled sigmas (the sigmas the sampler actually uses, recorded in the training events) and trains through that step's own frozen output head, target x0 - noise at model time t = 1 - sigma. This is the same convention as the public reference trainer for this model (ai-toolkit: fixed_train_sigmas = the 6 nonzero sample sigmas, the final 0 is the endpoint, its target is the negation of ours with the prediction negated). Every training timestep is a row of the AdaLN table, so the table stays exact, and the LoRA trains through gradient checkpointing.
  • Training adapter: by default the frozen base is first merged with ostris' de-distillation training adapter for this model (rank 16, 208 layers, in MiniMax's native key names), as the reference trainer does, pinned to the adapter repo commit the defaults were tuned with (e4e119c; the repo keeps receiving uploads); it is active only while training and never saved into or loaded with the user's LoRA. UNSLOTH_H3_IMAGE_TRAINING_ADAPTER=auto|ostris|off|<path>; auto trains without it, with a warning, if it cannot be downloaded.
  • LoRA targets: the trunk attention and MLP linears (transformer_blocks.N.{attn.to_q, to_k, to_v, to_out.0, ff.net.0.proj, ff.net.2}); heads, AdaLN and the text refiner stay frozen.
  • Loading the LoRA: load_minimax_h3_image_pipeline(loras=[(path, weight)]) merges it into the dense DiT block by block before int8 / fp8 quantisation, so every placement and speed path runs unchanged. A LoRA load streams the 66 GB release DiT instead of the hosted prequant, and the set and weight are fixed per load (another selection at render time returns the existing "load again" 400); Deploy to Create puts the LoRA in the load request. Native-key (ai-toolkit format) H3-Image LoRAs load too: the fused qkv is reordered and split, the fc1 halves swapped, checked against the checkpoint converter. The GGUF / sd.cpp engine refuses with "LoRAs need the diffusers engine".
  • Wiring: trainable=True, base MiniMaxAI/MiniMax-H3-Image, nf4 / fp8 / mxfp8 refused for training; defaults rank 32, lr 5e-5, 150 steps, 1024, constant with 20 warmup steps; VRAM facts; 6-step training previews; the Train panel hides flow shift, CFG dropout and random flip for this family and now takes a family's recommended step count (it was fixed at 500).

Results

Colab G4 (RTX PRO 6000) and A100 80 GB, 18 cards from Studio's 1920 tarot example dataset, trigger trtcrd, training adapter on, rank 32:

run concept LPIPS vs base (cat, astronaut), weight 1.0 mean drift on 4 unrelated prompts, weight 0.6 / 0.8 / 1.0
lr 1e-4, 150 steps 0.65, 0.69 0.23 / 0.33 / 0.44
lr 1e-4, 300 steps 0.63, 0.66 0.29 / 0.38 / 0.48
lr 5e-5, 150 steps (default) 0.61, 0.71 0.22 / 0.30 / 0.38
lr 5e-5, 300 steps 0.65, 0.70 0.21 / 0.30 / 0.39

With the default, the trigger prompt renders a clean tarot card that keeps the subject and a legible title; lr 5e-5 x 300 starts garbling the title, lr 1e-4 x 300 drifts most. The style still leaks into prompts without the trigger (most on a car and a lighthouse prompt), so lower weights (0.6 to 0.8) suit subtler use. Without the training adapter the same data gives blotchy cards with garbled titles, which is why it is on by default.

The sampler's x0 estimate on the training images moves closer to the image at every head after training (head 0: 1.013 -> 0.583, head 5: 0.0181 -> 0.0177).

bf16 base int8 base (20-step check)
speed 1.51 step/s on G4, 0.94 on A100 80 GB 0.81 step/s on A100 80 GB
peak VRAM 45.5 GB 24.3 GB

A fresh process reloads the LoRA into 300 / 300 layers with every speed lever on; renders at 1536x2720 take 5 to 6 s on the A100.

Tests

  • New tests/test_diffusion_h3_image_trainer.py (20): loss falls on the tiny native-layout release, the saved adapter holds exactly the trunk leaves, reload merges all layers and changes the output while weight 0 is bit-identical, merge equals W + s * B @ A, native-key LoRAs merge like the converter, one sampler step fed the training target lands exactly on the next sigma at every head, every head is exercised, training sigmas equal the sampler's, a foreign LoRA and a changed render-time selection are refused.
  • Training, LoRA and H3-Image suites match main apart from environmental failures that fail the same there; frontend tsc clean, train-panel tests pass.

Not covered

  • int8 training on an actual 32 to 48 GB card (the floor is inferred from the 24.3 GB int8 peak), training at 2048, the continuous-sigma variant.
  • A browser run of Deploy and the LoRA picker. A G4 run through Studio's own backend (the load request Deploy sends) trained, merged the LoRA into 300 / 300 layers, rendered, and refused a changed weight; it ran before the catalog publish commit, which is covered by a CPU end-to-end test.
  • One dataset (tarot); rank 16 and the reference trainer's wider layer set were not tried.

Screenshots

Images > Train, Model family list: BEFORE 9 families, AFTER adds MiniMax-H3-Image:

Model family list before and after

MiniMax-H3-Image picked: 33B, QLoRA 32GB+ VRAM, the bf16 / int8 note, Steps 150, rank 32, res 1024, lr 0.00005, Constant + warmup 20, and Timestep shift, Caption dropout and Random flip hidden (BEFORE cannot pick it and stays on FLUX.1-dev):

MiniMax-H3-Image Train panel before and after

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T03:51:40.834324Z 38e37dc Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…load; auto never picks int8 where int8 cannot run

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…alog so Deploy, Export and the picker see it

[skip ci]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 03cdf919d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The adapter repo keeps receiving uploads; fetch the exact file the recommended
hyperparameters were tuned with (sha256 45a5d60d...68bb60) instead of main.

[skip ci]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: e258574e24

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 16, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 16, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 9734d46b00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…h3-image

# Conflicts:
#	studio/backend/core/training/diffusion_samples.py
#	studio/frontend/src/features/images/images-page.tsx

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 16, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 38e37dc964

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 47d036a into main Nov 16, 2026
@danielhanchen
danielhanchen deleted the studio-train-minimax-h3-image branch November 16, 2026 05:17
danielhanchen added a commit that referenced this pull request Nov 16, 2026
…iniMax LoRA sidecar read (#17913)

## Summary

Two checks are red on main right now:

1. **`Repo tests (CPU, rest)`:
`tests/test_ci_repo_cpu_shards.py::TestEveryGlobRootMatchesAFile::test_no_shard_hands_pytest_an_unexpanded_pattern`**

   ```
AssertionError: these shard globs match no test file: [('gloo',
'tests/test_t[!p]*gloo*.py')]
   ```

#17892 added `tests/test_t[!p]*gloo*.py` to the gloo shard so that
`tests/test_tokenizer_save_ddp_gloo.py` (from #17862) was collected by
some shard. #17882 landed at the same time and renamed that file to
`tests/test_local_save_tokenizer_ddp_gloo.py`, which the gloo shard's
first glob (`tests/test_[!dfimpstu]*gloo*.py`) already covers. The
`test_t[!p]` glob now matches nothing, and an unmatched glob reaches
pytest as a literal path. Both PRs were right on their own; together
they leave one dead glob.

2. **`(Python 3.13, rest)` and `Repo tests (CPU, rest)`: the text I/O
encoding gates**

   ```
   test_text_io_names_its_encoding[diffusion_minimax_h3_image.py]
assert not ['diffusion_minimax_h3_image.py:3422: read_text() without
encoding']
   ```

#17863 added `json.loads(sidecar.read_text())` for the LoRA
`adapter_config.json` sidecar. Without an encoding that read uses the
locale codepage on Windows.

## Change

- `.github/workflows/studio-backend-ci.yml`: remove
`tests/test_t[!p]*gloo*.py` from the gloo shard and restore the comment
that a `test_t[!p]*` gloo file would be reported as dropped by
`tests/test_ci_repo_cpu_shards.py` (with a note on why the glob is not
kept for later: an unmatched glob is a missing file to pytest).
- `studio/backend/core/inference/diffusion_minimax_h3_image.py`:
`sidecar.read_text(encoding = "utf-8")`. JSON is UTF-8, so behaviour on
Linux and macOS is unchanged.

## Testing

- `tests/test_ci_repo_cpu_shards.py` and
`test_text_io_encoding.py::test_text_io_names_its_encoding[diffusion_minimax_h3_image.py]`:
16 passed on this branch, 2 failed on main.
- `tests/test_runtime_text_encoding.py` and
`studio/backend/tests/test_diffusion_minimax_h3_image.py` pass;
`studio/backend/tests/test_text_io_encoding.py` passes for every tracked
file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant