Repository navigation
Studio: composited-canvas tiled VAE decode for MiniMax-H3 / H3-Image (batched tiles, tile CUDA graphs, fp16 decoder) - #17595
Conversation
…(corner-correct overlap-add, batched tiles, tile CUDA graphs race, probed fp16 decoder)
…r call first for the exactness reference)
…pped replicas undercounted per call), cap kept graph pools at 1 GiB / 4% of the card
…ecided arm whose re-record passes the pool cap goes eager
…cap skip, refused captures retry, OOM drops cut race runs, graphs only for equal tiles, sync before dropping graphs, steady batch per tile shape, per-decode stats, flat images re-checked in fp32 before leaving fp16
|
@codex review |
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. |
Codex Review Summary: ❌ FailedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b55eadf57
ℹ️ 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".
| for j, (xs, xl) in enumerate(zip(x[0], x[1])) | ||
| ] | ||
| equal = len({t[2].shape for t in tiles}) == 1 | ||
| batch = tile_batch_size(vae, tiles[0][2], len(tiles)) if equal else 1 |
There was a problem hiding this comment.
Honor the speed switch when selecting tile batches
With UNSLOTH_H3_IMAGE_SPEED=0, install_h3_image_vae_canvas() passes speed=False to install(), but this decode path still calls tile_batch_size() unconditionally for equal-sized tiles. On CUDA, that automatically batches up to 16 tiles despite the disabled speed levers, increasing peak decoder memory and changing numerical results relative to one-tile decoding. Persist the batching permission from install() and use a batch size of one when speed optimizations are disabled, while retaining the canvas seam correction.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4419057. install() now records whether batching is allowed (speed on and CUDA), and tile_batch_size returns 1 when it is not, so UNSLOTH_H3_IMAGE_SPEED=0 decodes one tile per call while keeping the canvas seam fix. An explicit UNSLOTH_DIFFUSION_VAE_TILE_BATCH still wins. Added test_speed_off_keeps_one_tile_per_call.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4419057f92
ℹ️ 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".
| forced = tile_graphs_setting() | ||
| if forced == 0 or device.type != "cuda" or not vae.__dict__.get("_unsloth_canvas_graphs"): | ||
| return () |
There was a problem hiding this comment.
Honor the global CUDA graph kill switches for tile decoding
On CUDA, setting UNSLOTH_DIFFUSION_CUDA_GRAPHS=0 or UNSLOTH_DISABLE_CUDA_GRAPH=1 still enables the tile-graph race because this guard checks only the tile-specific switch. diffusion_cuda_graph.cuda_graph_disabled() implements these global kill switches, but neither this path nor TileGraphs.grow() calls it. Consequently, H3-Image decoding still captures and replays CUDA graphs when users explicitly disable them to avoid capture failures or graph-pool memory overhead. Check the shared helper before selecting graph arms so the global switches also disable this new capture path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 75e27b3. Tile graph arms now check diffusion_cuda_graph.cuda_graph_disabled(), so UNSLOTH_DIFFUSION_CUDA_GRAPHS=0 or UNSLOTH_DISABLE_CUDA_GRAPH=1 turns the race and every capture off (TileGraphs.grow is only reached through those arms), and the lever is not reported. The global switch also wins over a forced UNSLOTH_DIFFUSION_VAE_TILE_GRAPHS. Added test_global_cuda_graph_kill_switches_turn_tile_graphs_off.
|
@codex review |
|
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". |
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
MiniMaxH3ImagePipeline.release() empties the VAE weights in place so an unload frees the card even while something outside still references the VAE. The tile graphs' private pools lived in the VAE's __dict__ and stayed reserved in that case (912 MiB on a B200 with two replicas at 2048 px). Drop them in release().
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
…d VAE canvas gates (#17681) ## Summary Two checks fail on main (`7bf13f2`) and on every PR based on it. The `(Python 3.13, a-f)` and `(Python 3.13, rest)` shards show them on staging runs: ``` studio/backend/tests/test_diffusion_rocm_tag_detect.py::test_no_diffusion_or_video_gate_reads_version_hip_directly E AssertionError: use core.inference.rocm_bf16.is_rocm_torch(torch): AMD SDK / Radeon wheels leave torch.version.hip unset. Raw reads: {'diffusion_torchao_patches.py': [66], 'diffusion_vae_canvas.py': [296]} studio/backend/tests/test_small_host_dense_denoiser.py::test_qkv_fusion_skips_a_mapped_denoiser[True] core/inference/diffusion_small_host.py:863: in prepare_streamed_encoder_ E ModuleNotFoundError: No module named 'diffusers' ``` Both reproduce locally on main (the second with `diffusers` blocked). ### ROCm gates (#17613, #17595) The lint is right, and both reads are real bugs on AMD SDK / Radeon wheels, which leave `torch.version.hip` unset and carry the ROCm tag only in `torch.__version__`: - #17613 gates the int8 GEMM's transposed-weight path with `getattr(torch.version, "hip", None) is None`. On a tag-only ROCm wheel that is true, so the cuBLASLt-only TN layout would be sent to hipBLASLt. The comment above it says ROCm should keep the row-major copy. - #17595's `diffusion_vae_canvas._is_rocm()` calls `is_rocm_torch()` with no argument. That raises `TypeError`, which the `except` swallows. The fallback then reads `torch.version.hip`, so every call took the raw read, and a tag-only ROCm wheel got the NVIDIA tile-graph replica count. ### Mapped denoiser test (#17667) `test_qkv_fusion_skips_a_mapped_denoiser[True]` maps the denoiser through `prepare_streamed_encoder_`, which uses `diffusers.hooks.apply_layerwise_casting`. The backend test shards do not install `diffusers`. The bit-for-bit test in the same file already guards on it with `pytest.importorskip("diffusers.hooks")`. ## Change - `diffusion_torchao_patches.py`: `keep_transposed` now uses `_is_rocm_torch(torch)`, a small helper that calls `rocm_bf16.is_rocm_torch`. - `unsloth/import_fixes.py`: `_make_safe_int_mm` must stay AST-identical to the Studio copy (`test_studio_copy_matches_unsloth_import_fixes`). It gets the same call, plus its own `_is_rocm_torch` with the same tag-aware check, so whichever copy patches torchao first behaves the same. - `diffusion_vae_canvas._is_rocm()`: calls `is_rocm_torch(torch)`, with no raw fallback. - `test_small_host_dense_denoiser.py`: the mapped case calls `pytest.importorskip("diffusers.hooks")`, like its sibling. The unmapped case still runs everywhere. ## Guards - `test_vae_canvas_graph_replicas_see_a_tag_only_rocm_wheel` and `test_vae_canvas_rocm_check_does_not_fall_back_on_a_cuda_build` in `test_diffusion_rocm_tag_detect.py`. - `test_a_tag_only_rocm_wheel_keeps_the_row_major_copy` in `test_torchao_int_mm_transposed.py`, next to the existing `torch.version.hip` case. ## Testing - `test_diffusion_rocm_tag_detect.py`, `test_torchao_int_mm_transposed.py`, `test_torchao_intmm_patch_wiring.py`, `test_small_host_dense_denoiser.py`: 33 passed, 4 skipped (CUDA-only cases). - Sabotage: with main's three source files and these tests, 3 fail (the lint, the VAE canvas tag-only case, the int8 tag-only case). - With `diffusers` blocked: main's `test_qkv_fusion_skips_a_mapped_denoiser[True]` fails with the CI error; here it skips and `[False]` passes.
…iffusers is missing (#17685) ## Summary `(Python 3.13, a-f)` fails on main and on every PR based on it since #17595 (seen on the staging runs for #15275 and #16707): 25 tests in `studio/backend/tests/test_diffusion_vae_canvas.py`, for example ``` tests/test_diffusion_vae_canvas.py:126: in test_constant_grid_matches_the_overlap_add_and_stock_does_not tests/test_diffusion_vae_canvas.py:25: in _image_vae_cls core/inference/diffusion_minimax_h3_image.py:211: in vae_class core/inference/diffusion_minimax_h3_image.py:178: in _load_vendored E ModuleNotFoundError: No module named 'diffusers' ``` `vae_class()` returns diffusers' `AutoencoderKLMiniMaxH3Image` or, failing that, the vendored copy in `studio/backend/vendor/diffusers_minimax_h3_image/`. The vendored file builds on diffusers' own base classes (`from diffusers.configuration_utils import ConfigMixin`, `diffusers.models.attention`, ...), so without diffusers both paths fail. The Studio backend CI shards do not install diffusers. The product code is fine: Studio only reaches this VAE when diffusers is installed. Only the test assumed diffusers was there. One test in the file already guards on it (`pytest.importorskip("diffusers")` at line 439). Reproduced on main with `diffusers` blocked: 25 failed, 3 passed, 2 skipped. ## Change `_image_vae_cls()`, the helper every VAE-building test goes through, calls `pytest.importorskip("diffusers")` first. The tests that do not build the VAE (the bad-output probe and the graph race bookkeeping) still run without diffusers. Test-only change. ## Testing - `diffusers` blocked: 3 passed, 27 skipped. main: 25 failed. - With diffusers installed: 30 passed, same as main.
Summary
Tiled VAE decode for MiniMax-H3-Image (and the MiniMax-H3 video VAE) now composites tiles into one preallocated canvas, decodes many tiles per call, can replay the tile decoder as CUDA graphs, and runs the H3-Image decoder Linears in fp16. At 2048 px the H3-Image decode goes from 2.82 s to 0.280 s on an A100 80GB, and the corner seams of the stock stitch are fixed.
New module
studio/backend/core/inference/diffusion_vae_canvas.py. It engages on any VAE whose class carries the stock MiniMax tile loop (matched by a hash of the_blend/_stitch_tilessource); an edited or overridden stitch keeps the stock path.The levers, each with its own switch (
0turns it off)UNSLOTH_DIFFUSION_VAE_CANVAS): each tile is added once into one output buffer, using the stock ramps in the same dtype, with no finaltorch.cat. The stock stitch blends each tile against its neighbours' raw edges, so where four tiles meet one tile drops out of the blend: with four constant tiles 0 / 1 / 2 / 3 and a 2 pixel overlap an interior corner pixel comes out 2.0 where a normalized overlap-add gives 0. The canvas blends against the already composited strips. Outside the corners the result is bit-identical to stock.UNSLOTH_DIFFUSION_VAE_TILE_BATCH): batch size from free VRAM, capped at 16, kept steady per tile shape.UNSLOTH_DIFFUSION_VAE_TILE_GRAPHS): one graph per tile-batch shape with 1, 2 or 4 replicas, each on its own stream and memory pool (one replica on ROCm). Each replica must match eager bit for bit before use, the arms are raced in place against eager on the real tiles, and eager is kept unless a graph arm is more than 2% faster. Pools are capped at 1 GiB or 4% of the card, only one tile shape keeps graphs at a time, and graphs turn off if the decoder weights move.UNSLOTH_DIFFUSION_VAE_HALF, H3-Image only): only the block Linears are cast; norms, layer scales and the residual stream stay fp32. A probe after every decode re-decodes in fp32 on non-finite output and keeps fp32 for the rest of the load.Results (decode only, real weights and latents, base and head interleaved in fresh processes)
Where the A100 time goes at 2048 px: canvas alone 2.75 s, plus batch 16 in fp32 1.67 s, plus fp16 0.295 s, plus graphs 0.280 s.
Exactness:
Seam fix on real images. An untiled 2048 px decode is not a usable reference for this decoder (it is shipped with 256 px tiling, and untiled output breaks visibly), so four real 2048 px H3-Image renders were encoded with the VAE's own encoder and decoded back, scored against the original render:
Memory on the A100: the decode working set is 0.11 GiB larger, the fp16 decoder weights are 0.75 GiB smaller, and up to 1.0 GiB is reserved for graph pools.
Tests
tests/test_diffusion_vae_canvas.py(26 tests): the corner oracle, canvas equal to stock outside corners at five layouts, kill switches and fallbacks, batching, the fp16 non-finite and flat-image checks, race decisions, the video clip loop.Not covered