Repository navigation
Studio: MiniMax-H3-Image text to image and reference edits - #17453
Conversation
…dits, int8 / fp8 / bf16 DiT, offload tiers)
… budget per placement tier
… fetch ids, freeze fixture); encoder default in the in-tree loader
… and vision tower
…int8 refuses others and torchao fell back to fp32); release on unload
…t int8 refused 4432 rows on an A100, so t2i still ran the fp32 fallback)
…rence held elsewhere cannot keep the card full
…only once the file exists, else quantized on the fly
…bel, 6 locked steps, 4 MP / 16 MP size presets, <Picture N> inputs; refuse Apple Silicon and CPU with a clear message
…3-Image repos and for any folder whose own metadata says MiniMax-H3-Image
…rge commit (files unchanged from the PR head)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…dequantize context_embedder and token_refiner at load), as the on-the-fly path does
…ger than budgeted (bf16 fallback, local text_encoder folder); the per-prompt tier refuses a bf16 fallback [skip ci]
[skip ci]
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…nfig at the release revision, vendored class lookup, release tile floor)
…d DiT runs without the AdaLN table
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…absent (object twice raised at import)
… when the plan cannot hold it
…er is materialised
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ike the scheduler bases)
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…17466) ## Summary Reduce motion is on by default since #17377, and its blanket rule in `index.css` gives every element `transition-duration: 0.01ms`. `transition-property` defaults to `all`, so that one line turns on transitions for every property of every element, including the many no rule ever meant to animate. Chromium makes this expensive. `* { scrollbar-color }` sets a scrollbar colour on every element, and Chromium starts a scrollbar-color transition on each of them whenever they are restyled, even when the value does not change (the from and to keyframes are identical). With any non-`auto` colour, a body-level restyle in a 40 turn Liquid Glass chat started about 2,000 of these transitions, and more as the chat grows. This is behind the Chromium long-chat gate cells that keep failing on recent PRs (`area thread_scroll (liquid-3d)` and `area stream (liquid-3d)` growing 2.5x to 2.8x from 40 to 200 turns, e.g. #17453 and #17460). ## Change - Both Reduce motion blocks (`html.force-reduced-motion`, on by default, and the OS `prefers-reduced-motion` block) now give the `*` blanket `transition-duration: 0s`. A transition that lasts 0.01ms and one that does not run look the same, so nothing on screen changes and Reduce motion stays on. - A second rule in each block keeps 0.01ms for elements that still need their `transitionend`: - elements that declare a transition through a Tailwind class (`[class*="transition"]`), which covers the reasoning and sidebar collapsibles that unmount on `transitionend`; - the overlays `native-view.ts` follows by their transition events (`CLICKABLE_SELECTOR`: toasts, the find bar, native clickables and the rail), so the Desktop browser view keeps its hole in place while they appear. - The annotation layer's zoom only had a transition because of the blanket. Its comment now says what happens without one: the existing `[zoom]` effect redraws it. ## Guard New `studio/frontend/tests/reduced-motion-implicit-transitions.test.ts`: - fails if either Reduce motion `*` blanket sets a nonzero `transition-duration`, with its own cases for the checker; - requires the 0.01ms exemption in both blocks, and that it lists every part of `native-view.ts`'s `CLICKABLE_SELECTOR`, so the two cannot drift apart. `reasoning-grid-collapse.test.ts` now checks that the collapse is reached through the class exemption instead of counting the old blanket lines. Against main's `index.css` the new test and the updated collapse test fail (3 failures); with this change all 20 tests in the four related files pass. ## Measurements Chromium (the long-chat gate's headless build and harness, this host), Liquid Glass 3D, main-thread CPU per area at 200 turns, three interleaved runs each: | Area | main | this PR | |---|---|---| | `thread_scroll` | 1,166 / 679 / 628 ms | 186 / 209 / 166 ms | | `stream` | 3,072 / 3,242 / 3,244 ms | 1,450 / 1,241 / 1,175 ms | | `command_palette` | 1,370 / 1,058 / 1,172 ms | 326 / 236 / 346 ms | Scrollbar-color transitions started by one body-level restyle at 40 turns: 2,550 on main, 0 with this change. ## Long-chat gate: Settings ceiling With the blanket transitions gone, the gate's 40 turn reading of opening Settings in the default appearance drops from about 6,100 elements restyled to about 2,400, while the 200 turn reading stays near 7,900. That made `area settings (default)` read 3.3x against the 2.0x element-growth limit. The growth itself is on main already. Measured on fresh pages with the gate's harness, default appearance: | | 40 turns | 200 turns | growth | |---|---|---|---| | main | 1,975 elements, 290 ms CPU | 9,721 elements, 816 ms CPU | 4.9x | | this PR | 1,663 elements, 217 ms CPU | 7,760 elements, 461 ms CPU | 4.7x | The gate only passed on main because the transitions inflated its 40 turn reading. `KNOWN_DEFAULT` in `tests/studio/_area_matrix.py` now records it as `length:settings=5`, so Settings keeps a ceiling instead of being skipped. This changes only the element and layout count check for that one area; its CPU and paint growth checks are unchanged. Finding what restyles the thread when Settings opens is a separate fix. ## Not covered The Firefox long-chat gate failure that also started with #17377 is a different cost: forcing every transition to 0s does not change the Firefox numbers, so this PR does not address it.
[skip ci]
…ot keep int8 resident (#17479) ## Studio MiniMax-H3: opt-in 4-bit GGUF text encoder for hosts that cannot keep the int8 one resident ### Problem The MiniMax-H3 text encoder (Qwen3-VL 32B, 50 of 64 layers) is hosted as an int8 ConvRot file of 27.1 GB. Beside the int8 denoiser (20.3 GB) and the VAEs (11.1 GB) it does not fit in the page cache of a 53 GB host, so on an L4 at a 12 GiB budget the encoder is re-read from disk on every new prompt (about 33k major page faults per encode). H3-Image (#17453) reuses the same encoder and loader. ### What this changes 1. `diffusion_weight_only_quant.py` (new, family-neutral): GGUF block-format projections (Q4_K / Q6_K / ...) load as diffusers' `GGUFLinear` over the file's blocks, the layer Studio's GGUF denoisers already use. The blocks stay resident and each call rebuilds a transient dense weight for a float GEMM, so any GPU or the CPU runs it. 2. The H3 text encoder loader reads either the hosted int8 safetensors file (unchanged, bit-identical to main) or a GGUF file. GGUF tensors stored with merged dimensions (the vision patch conv, which GGUF holds in 4-D) are reshaped when the element count matches and refused otherwise. 3. New scheme `q4_k_m`: `unsloth/MiniMax-H3-GGUF/qwen3vl_32b_minimax_h3-Q4_K_M.gguf`, the file the sd.cpp path already downloads (18.2 GB, no new upload). Each scheme names its own unsloth source repo (fetch, Hub size check, delete guard). 4. **Opt-in only.** An unset request keeps int8 on every host. `UNSLOTH_H3_TE_QUANT_AUTO=q4_k_m` selects the GGUF encoder (`int8` forces int8). The host-RAM switch is in place behind `H3_TE_LOW_RAM_AUTO = False`: when on, an unset request takes int8 when the host (total RAM, capped by the cgroup limit) holds encoder + denoiser + VAEs + headroom (64.5 GB), else `q4_k_m`, and stays on int8 without a GGUF reader. Turning it on is one line once the accuracy trade below is accepted. `q4_k_m` is not a `text_encoder_quant` request value. ### The trade Accuracy, CPU, real weights, 8 prompts: `hidden_states[50]` against the released bf16 encoder, relative L2 over the valid tokens with token 0 excluded (the attention-sink row carries most of the norm): | encoder | size | rel. L2 mean | rel. L2 worst prompt | worst token cosine | |---|---|---|---|---| | int8 (today) | 27.1 GB | 1.63% | 1.92% | 0.998 | | q4_k_m | 18.2 GB | 5.82% | 7.94% | 0.971 | Clips against the int8 clips (same seeds; int8 itself is deterministic, A/A LPIPS 0): - L4, 8 prompts, 960x544, 25 frames, 2 steps: mean LPIPS 0.080 (0.027 to 0.184), mean PSNR 34.5 dB. - A100-40, 2 prompts, 960x544, 49 frames, 20 steps: LPIPS 0.304 / 0.167, PSNR 18.1 / 23.5 dB. Speed and memory. Studio main 57a486b against main plus this branch, every arm a fresh process, files prefetched and read into the page cache before each arm; major faults counted over each prompt's encode. L4 (55.5 GB host), 12 GiB budget, 8 new prompts per arm: | encoder | encode s per prompt (median) | major faults per encode | process RSS during encode | load s | |---|---|---|---|---| | int8, run 1 | 47.4 | 32.7k-33.2k | 46.7-47.1 GiB | 159 | | int8, run 2 | 53.1 | 32.3k-37.5k | 46.6-47.5 GiB | 187 | | q4_k_m, run 1 | 19.7 | 0 | 43.1-43.2 GiB | 144 | | q4_k_m, run 2 | 19.8 | 0 | 44.0-44.1 GiB | 156 | A100-40 (83 GB host), whole card: | encoder | encode s | process RSS during encode | load s | |---|---|---|---| | int8 (main), two runs | 6.1-6.4 | 45.3-46.8 GiB | 114-139 | | int8 through this branch's loader | 6.2 | 46.5 GiB | 140 | | q4_k_m | 6.2 | 25.9 GiB | 168 | So on a low-RAM host q4_k_m removes the per-prompt re-read (-28 to -33 s per new prompt on the L4) for a 3.6x larger hidden-state error; on a host that holds int8 it only saves host RAM. Repeat runs gave bit-identical frames, and the int8 path through the new loader is bit-identical to main. ### Tests - `tests/test_h3_te_4bit.py` (new, CPU): a tiny Qwen3-VL written in the hosted int8 layout and as a GGUF (Q8_0 projections, bf16 table, patch conv stored 4-D as the hosted file does) loaded through the real loader and compared with its own dense decode; wrong-scheme refusal both ways; unset request stays int8 on every host; env opt-in; the switch's host-RAM rule and its no-GGUF-reader guard; the resolver wiring. - `tests/test_video_h3_te_quant.py`: the request-value check skips the opt-in-only scheme. - Related H3 / encoder / companion / GGUF suites: 630 passed; `tests/test_video_backend.py -k "h3 or minimax"`: 179 passed. Red on main as well, untouched here: `tests/test_integrated_gpu_no_host_pin.py` (2 pinning-site assertions in files this branch does not change) and `tests/test_diffusion_gguf_compile.py::test_installed_dequant_survives_a_failing_compile` under xdist (passes serially). ### Not covered here - A clip against the bf16 encoder: the released dense encoder (66.7 GB) is refused on an A100-40 at generate time (68.5 GB VRAM floor), so the clip numbers are against int8; the bf16 comparison is the hidden-state check above. - H3-Image (#17453): it reuses this loader, but no H3-Image render pair ran. - The q4_k_m encode at L4 12 GiB is 19.7 s, not the ~4 s of a fully host-resident encoder: the faults are gone, the rest is the leaf-by-leaf stream itself (not investigated here). - q4_k_m loads 10-30 s slower than int8 on the A100 (the GGUF payload is copied into anonymous memory at load). - T4, ROCm, Windows, Apple: not run.
…levers (#17495) ## Summary Follow-up to #17453 (MiniMax-H3-Image, merged). Four speed levers for MiniMax-H3-Image, one commit each, each with its own switch. Where a mechanism is not specific to H3-Image it is added as a shared helper. 1. **Conditioning cache** (`Studio H3-Image: conditioning cache for repeated prompts`) - The pipeline's encoder entry point is now `encode_prompt`, so the shared in-memory prompt cache (`diffusion_prompt_cache`) wraps it. The H3-Image backend load installs the cache like every other load does. - A repeated prompt (new seed, batch) with the same reference pixels skips the 27 GB Qwen3-VL encoder. The VAE reference latents are still sampled on every render. - A test asserts that every backend method that commits a load (builds a `_LoadState`) installs the cache. - Off switch: `UNSLOTH_DIFFUSION_PROMPT_CACHE=0`. 2. **Pinned streaming with copy-stream prefetch** (`... stream blocks through pinned memory with copy-stream prefetch`) - Before this change, the streamed DiT blocks and encoder layers moved from pageable host memory with `.to(non_blocking=True)` on the compute stream. A pageable copy is synchronous, so the compute waited for every copy. - The new shared streamer for custom loaders is `diffusion_offload_prefetch.stream_module_list`. It gives each streamed member a diffusers `ModuleGroup` whose host copies are pinned and packed into slabs, on its own copy stream, and drives the groups with the existing `GroupPrefetcher`: the next member copies while the current one runs, fenced by events. - A forward that stops part way still releases what it queued. This matters for the encoder, whose read stops at layer 50. - Members are pinned only when the host pin budget holds the new locked copies. The streamed DiT is placed before the encoder loads, so the DiT blocks, which stream every step, get that budget first. Buffers return to their host copies as well (the int8 encoder keeps its weights as buffers). - The planner keeps room for the one prefetched member. The low-host tier loads the encoder for each prompt, so its layers stay pageable there. - Off switches: `UNSLOTH_H3_IMAGE_PINNED_STREAM=0` for H3-Image, `UNSLOTH_DIFFUSION_ASYNC_PREFETCH=0` for every prefetcher. 3. **H3 video speed levers on the H3-Image DiT** (`... engage the MiniMax-H3 video speed levers on the vendored DiT`) - The H3 attention levers used to gate on diffusers' MiniMax-H3 classes. They now gate on module structure: the forward and processor signatures, per-head RMSNorm q/k, `to_out`, and separate or fused QKV. The strided processor is built once per stock processor class, so the vendored H3-Image attention takes the levers unchanged. Video matches the same modules with the same class. - Every CUDA tier gets the automatic attention pick and the strided SDPA layout (both bit-exact). - The resident tiers also get the fused int8 QKV, Studio's int8 GEMM, the fused SwiGLU act quant and the fused q/k norm + RoPE. - The fused q/k norm + RoPE is not bit-exact. It stays off by default on the streamed tier, where it was the only non-exact part and landed further from the bf16 reference on both gated prompts; `UNSLOTH_H3_IMAGE_QK_ROPE=1` / `0` forces it on or off on any tier. - Regional compile is opt-in (`UNSLOTH_H3_IMAGE_COMPILE=1`). - Off switch: `UNSLOTH_H3_IMAGE_SPEED=0`. Each lever also honours its video switch. 4. **INT8 attention as the checkpoint declares** (`... INT8 attention on the DiT blocks as the checkpoint declares`) - MiniMax-H3-Image's INT8 DiT checkpoint runs INT8 attention on its 50 DiT blocks. A shared map in `diffusion_attention` (`checkpoint_attention_backend`) turns a declared attention kind into the Studio backend of the same arithmetic class; for INT8 attention that is the existing probe-gated `sage` backend. - H3-Image routes its DiT blocks to it when the DiT scheme is int8, or when a hosted file declares `attention` in its metadata. The token refiner keeps its backend. - Sage must pass its accuracy probe on the card first; otherwise every processor keeps the backend it had. - Switch: `UNSLOTH_H3_IMAGE_INT8_ATTENTION=0` keeps native attention, `=1` turns INT8 attention on for any scheme. ## Results 2048x2048, 6 steps, fixed seeds, base (#17453 on main) and head arms on the same Colab VM per tier, a second base and head pair (A2 / H2) as the A/A check. Seconds per image after the first (warm) render, split into encode / denoise / decode. LPIPS (alex, 512 px) is against bf16 renders of the same prompt and seed. **A100 40GB, INT8 DiT resident (`dit_resident`)** | arm | new prompt (s) | encode | denoise | decode | repeated prompt (s) | peak VRAM (GB) | host peak at load (GB) | |---|---|---|---|---|---|---|---| | base | 30.8 / 29.9 | 3.56 / 3.39 | 22.13 / 21.72 | 3.07 / 3.00 | 30.4 | 37.45 | 22.3 | | head | 12.6 / 12.0 | 1.29 / 1.25 | 6.15 / 5.84 | 3.12 / 3.16 | 11.1 (encode 0) | 36.92 | 46.1 | LPIPS vs bf16 (lighthouse s7 / bookshop s1234 / island s2026): base 0.034 / 0.276 / 0.064, head 0.036 / 0.278 / 0.063. **L4 24GB, FP8 DiT streamed (`stream`)** | arm | new prompt (s) | encode | denoise | decode | repeated prompt (s) | peak VRAM (GB) | host peak at load (GB) | |---|---|---|---|---|---|---|---| | base | 48.8 / 46.7 | 6.55 / 5.71 | 35.03 / 34.07 | 5.15 / 5.20 | 47.8 | 19.38 | 24.9 | | head (fused q/k norm + RoPE on) | 37.6 / 36.1 | 6.43 / 6.20 | 23.87 / 22.76 | 5.27 / 5.40 | 30.9 (encode 0) | 19.38 | 30.3 | | head, fused q/k norm + RoPE off (the shipped default) | | | 25.06 / 24.10 | | | 19.38 | | With the fused q/k norm + RoPE off, the L4 head images are byte-identical to base. With it on, LPIPS vs bf16 was 0.491 / 0.147 against base 0.415 / 0.092 on bookshop s1234 / island s2026. **Per lever** | lever | evidence | output | |---|---|---| | conditioning cache | repeated prompt encode 3.4 s to 0 (A100), 5.8 s to 0 (L4) | exact (same embeddings) | | pinned streaming + prefetch | A100: encode 3.5 s to 1.3 s per new prompt (encoder pinned, 31 layers prefetched, 0 missed). L4: denoise about 34 s to 24 s (23 DiT blocks pinned, 9.2 GB) | byte-identical to the same head with `UNSLOTH_H3_IMAGE_PINNED_STREAM=0` on both cards | | attention pick + strided SDPA | head with every other non-exact part off vs base | byte-identical (A100 and L4) | | int8 GEMM + fused SwiGLU (resident) | A100 denoise 21.0 s with them off, 6.2 s with them on | within the bf16 gate as a set | | fused int8 QKV (resident) | engaged on 45 of 50 blocks on the A100; the rest keep separate projections when the fused copy does not fit | self-checked bit for bit per block | | fused q/k norm + RoPE | A100 resident: 6.75 s to 6.15 s denoise; L4 streamed: 25.1 s to 23.9 s | not exact; on for the resident tiers, off for streamed | | INT8 attention | no prebuilt sage kernel loads on the torch builds the test VMs had, so the probe kept native attention | not measured | **Host memory.** Locked copies are made only when they fit two budgets: the host room the planner leaves after its own peak (`host_gb - host_need_gb`, less what is already locked, DiT first), and the free host RAM less max(4 GiB, 15%). Anything that does not fit streams from pageable memory as before. On the 86 GB A100 VM the room is about 55 GB, so the encoder locks and the load peak rises from 22 to 46 GB. On the 54 GB L4 VM the room is about 14 GB, so only the DiT blocks lock (9.2 GB) and the peak rises from 24.9 to 30.3 GB. A 40 GB host locks nothing and loads as before. ## Tests - `tests/test_diffusion_list_streamer.py`: prefetching streamer bit-identity and no device memory left after the forward (CUDA), buffers restored to their host copies, refusal when a stream exceeds the pin budget, the plan room cap, and a 40 GB host that loads with every member pageable. - `tests/test_diffusion_minimax_h3_image.py`: prompt cache hits and keys, every loader installs the cache, INT8 attention routing and restore. - `tests/test_diffusion_minimax_h3_image_speed.py`: structural H3 attention match, strided processor bit-identical to stock, fused int8 QKV bit-identical, kill switches, the per-tier q/k norm + RoPE default. - CPU suites: all pass. The list-streamer CUDA tests pass on an A100. ## Not covered - INT8 attention is unmeasured: no sage build loaded on torch 2.14.1+cu130 or 2.11.0+cu130, so the head kept native attention on every GPU run. - The fused q/k norm + RoPE defaults were picked from two scored prompts; changing either default needs a wider gate. - The per-tier default commit is CPU-tested only; its L4 "off" row is the earlier head run with the switch flipped at run time. - Fused int8 QKV did not fit on 5 of 50 blocks on the A100 40GB at load; those blocks keep separate projections. - GPU runs used torch 2.14.1 (Colab), not the torch Studio installs; no T4 run, and the opt-in regional compile was not run.
…izes (unslothai#17563) Fixes four problems with MiniMax-H3-Image (unslothai#17453): - On a GPU with 24 to 40 GB, picking the model downloads 135 GB, and then the load fails for lack of RAM. - On a 48 GB GPU, auto picks the bf16 DiT, and the load fails for lack of RAM. - Explicit FP8 or INT8 under Precision is always refused. - Every 16 MP size in the size menu is refused. ## Downloads The image repo bundles a bf16 text encoder (66.7 GB) and a second, converted copy of the DiT and VAE. The H3 loader reads none of them. The download plan staged all of them anyway, along with the bf16 DiT, even on cards where the load then uses the hosted INT8 DiT. The loader then found the bundled encoder in the cache and used it instead of the 27 GB INT8 one. With 64 GB of RAM, the load needs 78 GB and fails. Now the plan stages what the loader will open, using the loader's own rules: - From the image repo, only `processor`, `tokenizer`, `transformer` and `vae`, in the native layout. The converted layout gives bit-identical images, so the loader no longer fetches it. - The hosted INT8 encoder (or the H3 repo's bf16 encoder when bf16 is asked for). - The hosted INT8 or FP8 DiT when the card will run one, instead of the bf16 shards. The loader uses a `text_encoder/` folder only for a local-folder load, which also fixes caches that already hold the bundled encoder. If the plan cannot list the encoder or settle the DiT scheme, it sets `plan_failed` rather than reporting the model as fully downloaded. ## Auto on 48 GB cards Auto picked the bf16 DiT whenever it fit the card by itself (40.3 GB plus working memory). It did not count the encoder. On a 48 GB card the loader then kept the DiT in system RAM and swapped it in, which needs about 74 GB of RAM, so the load failed with 70 GB available. Auto now takes bf16 only when it stays on the card beside the encoder, and INT8 otherwise. Cards of 80 GB and up still get bf16. A 48 GB card with enough RAM used to run bf16 from system RAM; it now runs INT8 on the card, which is faster. ## Explicit FP8 and INT8 The load route checked explicit precision against the generic torchao path, which refuses any model that cannot run torch.compile. H3 never compiles and quantizes in its own loader, so FP8 and INT8 always got a 409. H3 now skips that check. It refuses only what it cannot run: other schemes, FP8 below SM 8.9, and any scheme without torchao. Before, its own resolver would quietly fall back to auto, INT8 or bf16 in those cases. ## 16 MP sizes The generate request capped each side at 2752, so H3's 16 MP sizes (up to 6272) got a 422 before H3's own size check ran. The presets and the chat image tool copied the same cap. All three now use one `MAX_REQUEST_SIDE` (6272, the largest side of any family). Each family still enforces its own limit. ## Not changed Auto still prefers bf16, as unslothai#17453 chose for quality, and falls back to INT8. So on FP8-capable cards the picker row "MiniMax-H3-Image (Fast FP8)" never loads FP8 by default. Changing auto or the label is a separate decision. ## Testing Tested live on a B200 against main, and on an RTX 6000 Ada (48 GB, about 70 GB of RAM). On the B200, smaller cards were emulated by holding the rest of the VRAM, with a 64 GB RAM budget. | Case | main | This PR | |---|---|---| | Pick the model, 24 GB card, empty cache | Downloads 148 GB, then the load fails | Downloads 47 GB, loads, generates | | Pick the model, RTX 6000 Ada | The load fails (needs 71 GB of RAM) | Loads INT8 on the card, generates | | Pick the model, full B200, empty cache | Downloads 154 GB | Downloads 90 GB | | Precision FP8 / INT8 | Refused | Loads; 3.7 s / 4.8 s per 2048 image | | 16 MP preset (4096 x 4096) | Refused | Generates in 12.5 s | | main | This PR | |---|---| | <img width="1500" height="1100" alt="h3_image_24gb_main" src="https://raw.githubusercontent.com/oobabooga/unsloth/pr-media/pr/studio-h3-image-loader-fixes/h3_image_24gb_main-c813a8ff780c.png" /> | <img width="1500" height="1100" alt="h3_image_24gb_this_pr" src="https://raw.githubusercontent.com/oobabooga/unsloth/pr-media/pr/studio-h3-image-loader-fixes/h3_image_24gb_this_pr-177fb63fa528.png" /> | New tests cover the plan, the cached bundled encoder, the auto choice on 48 GB cards, the precision check, `plan_failed` and the size limit. The plan, cached-encoder and precision-check tests fail on main. The diffusion and H3 backend suites pass, except three tests that also fail on main or pass when run alone. ## Colab verification (base vs head) Real Studio routes (download plan, load, generate) on an empty HF cache per tree, then `DiffusionBackend` loads from exactly the files the plan listed. Base is the merge base `5d5c1381b0`, head is `49eaddbeae` (later commits change comments only). | Case | Base | This PR | |---|---|---| | L4 (24 GB, 57 GB RAM): plan, auto | 135.37 GB (bundled bf16 encoder 66.73 + bf16 DiT 66.28 + VAE) | 49.77 GB (hosted INT8 encoder 27.14 + hosted INT8 DiT 20.27 + processor / tokenizer / VAE) | | L4: auto load with the bundled encoder in the cache | Refused: needs about 78 GB of free system memory, 53.7 GB available | Loads in 44.6 s on the INT8 encoder; the bundled copy is ignored | | L4: auto, 2048 image | not reachable | 149.3 s, peak VRAM 19.4 GB, system RAM 14.1 GB; 0.03 GB fetched beyond the plan | | L4: explicit FP8 / INT8 | 409 on the plan and load routes | FP8 99.7 s per 2048 image, INT8 144.3 s, VRAM 19.4 GB | | 4096 x 4096 generate request | 422 (`less than or equal to 2752`) | Passes validation; the L4 then refuses it in H3-Image's own memory check (needs about 18 GB of working memory) | | A100 40 GB: auto | plan 135.37 GB; FP8 / INT8 409 | INT8 resident, load 164.6 s, 13.33 s per 2048 image, VRAM 36.9 GB; explicit FP8 refused (needs compute capability 8.9) | One render per cell, no repeats. Not run here: the 48 GB card rule, a 4096 render, Windows / macOS / AMD. --------- Co-authored-by: danielhanchen <[email protected]>
Summary
Adds MiniMax-H3-Image (
MiniMaxAI/MiniMax-H3-Image) to the Studio Images page: text to image, and editing with 1 to 16 reference images referred to as<Picture N>in the prompt.Pipeline source. The transformer and VAE classes come from diffusers when the installed version has them. Otherwise they come from a vendored copy of the two model files from diffusers PR 15230, pinned to its merge commit
875373ac7f. The files are byte-identical to the PR head; they are Apache-2.0 with the header kept, and the commit and file hashes are recorded instudio/backend/vendor/diffusers_minimax_h3_image.json. The CPU tests pass with both the vendored copy and diffusersmainat that commit (whose own classes are then used).transformer_diffusers/+vae_diffusers/layout both load.[gate; value]is swapped to diffusers'[value; gate], keys are renamed, and the video-only head plusrope.inv_freqare dropped.Recipe from the model card.
pdd_fused_heads.safetensors).Family registration.
<Picture N>convention.Fixed-grid AdaLN. The model only ever runs at 7 timesteps (6 steps plus the reference rows' 0.999). Each block's 2688 to 96768 AdaLN projection is therefore folded into a 7-row table at load. This is exact: the rows are computed from the dense projection, and a test asserts equality. It removes 13.0B of the 33.1B DiT parameters, taking bf16 from 66 GB to 40.3 GB and int8 to about 21.9 GB. An off-grid timestep raises an error instead of silently interpolating.
Quantization at load. Each block streams from the safetensors shards onto the GPU and is quantized there, then parked. No second full copy is materialised on the host.
int8: ConvRot (block Hadamard, group 256) plus torchao W8A8 dynamic.fp8: row-wise, SM 8.9+ only; elsewhere it falls back to int8.bf16when it fits.Text encoder. By default the hosted int8 ConvRot encoder from
unsloth/MiniMax-H3-FP8is used, the same artifact as H3 video. The released bf16 encoder is used on request or as the fallback.Memory planner. It picks one of four tiers from free VRAM and host RAM:
resident,dit_resident(A100 40GB),sequential, orstream(L4 24GB; DiT blocks and encoder layers stream through the card, with a planned number kept resident). When the host cannot hold the encoder next to the DiT, the encoder loads per prompt. Overrides:UNSLOTH_H3_IMAGE_PLACEMENT,UNSLOTH_H3_IMAGE_VRAM_GB,UNSLOTH_H3_IMAGE_HOST_GB.text_encoder/folder), the plan is made again with its real size, and a DiT already loaded onto the card for a resident tier moves back to the host if the new tier needs it. When no tier fits, the load fails with an error that names the int8 encoder. The per-prompt tier refuses a bf16 fallback outright.Hosted pre-quantized DiT. The family declares
unsloth/MiniMax-H3-Image-FP8:MiniMax-H3-Image-INT8-ConvRot.safetensorsandMiniMax-H3-Image-FP8.safetensors, 20.3 GB each, with curve-form AdaLN as in the hosted H3 video files.load_prequantized_transformerwith the curve hook. The fingerprint check passed on 313 of 313 quantized weights.context_embedderand the twotoken_refinerblocks, 13 Linears), which the on-the-fly path keeps bf16. The loader dequantizes those at load, so the prompt embeddings are never activation-quantized. This costs about 0.8 GB of VRAM.UNSLOTH_H3_IMAGE_QUANT_CONDITIONING=1keeps them quantized for A/B tests.Desktop / Studio UI.
*MiniMax-H3-Image*as an image model; MiniMax-H3 stays a video model.<Picture N>prompt convention, through the page's existing crop editor.Nothing changes for existing families. The only shared-file changes are additive registry entries, plus the frozen family-data fixture (additive lines only).
Results
Real weights, streamed on the VM (nothing local). Prompts and reference are the repo's
examples/; seed 42 (t2i) and 1234 (edit); 2048x2048.A100 t2i at 1024 (4 MP canvas floor relaxed for the comparison): 12.5 s. The bf16 DiT streamed on the A100: 69.7 s at 2048. Before the row padding, int8 t2i on the A100 took 70.7 s (64.2 s denoise): every quantized GEMM fell back to fp32. First load on a fresh VM includes the 66 GB download (A100 649 s, L4 768 s); a reload from disk took 222 s on the L4. After an unload the card is back to 0.02 GB allocated, and an fp8 load right after an int8 unload in the same process renders normally.
LPIPS (alex), same seed: int8 vs bf16 0.088 at 1024 and 0.123 at 2048; fp8 vs int8 0.212 at 2048 (same composition, different fine detail); cold vs warm 0.0 (deterministic).
Tests
studio/backend/tests/test_diffusion_minimax_h3_image.py: 59 CPU tests on a tiny random copy in the native release layout.-o addopts= -m "not server and not native_mxc". The failing IDs at the merge base and at head are identical apart from the family-invariant tests this PR updates, which now pass.studio/frontend/tests/minimax-h3-image-ui.test.ts(8 tests). The fullnpm testrun passes (15,644 pass, 0 fail), andnpm run build(typecheck plus vite) andcatalog:checkpass.prepush_gate.pypasses on the merged head (vendored Apache-2.0 files keep their upstream header, likevendor/laya).Not covered
supports_torch_compile=False).mainat the merge commit was tested, on CPU).