Skip to content

MiniMax-H3 VAE: reference padding in one allocation and encoder norm fusion (from upstream #2476) - #110

Merged
danielhanchen merged 3 commits into
masterfrom
r17-h3-vae-2476
Dec 2, 2026
Merged

danielhanchen merged 3 commits into
masterfrom
r17-h3-vae-2476

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Ports two pieces of leejet/stable-diffusion.cpp leejet#2476 (MIT) to the fork's MiniMax-H3 video VAE.

Changes

  1. Last-frame padding allocates the padded clip once and copies each plane, instead of one full-clip concat per padded frame. A Ref2VA reference video always pads 12 frames (normalized length = 5 mod 17).
  2. Encoder: CausalConv3d does its spatial reflection, the downsample end padding and the causal zero frames in one padding op, and TemporalGroupNorm runs GroupNorm + affine + SiLU as one frame-norm op on CUDA / HIP (vae_frame_norm_hip.cu built with -fno-fast-math, as upstream). Backends without the ops (CPU, Metal, Vulkan) build one batched GroupNorm over all frames instead of a slice, norm and concat per frame.

The fork's decoder already has its own fused QKV / RoPE path, so the upstream decoder changes are not part of this PR. The upstream Vulkan shaders and leejet#2479 (upload / compute overlap, which needs leejet#2470's weight transfer files) are not included. ggml is untouched; all fork ggml patches still apply.

Results

  • Padding microbench, 124 -> 136 frames at 864x480, 1 thread, ABBA x2: 4.78 s -> 0.36 s, peak 1885 -> 1242 MiB, output identical.
  • CPU VAE encode of a 20-frame reference (padded to 34): latents byte-identical before and after both commits.
  • L4 (CUDA sm_89), MiniMax-H3 Ref2VA 864x480, 124-frame reference video, 8 steps, plain decode, unsloth/MiniMax-H3-GGUF ref2va Q4_K:
build request (s) decode (s) output md5
master 848.3 48.5 2da16326
+ padding 846.2, 847.4 48.5, 51.5 2da16326
+ encoder fusion 790.3, 794.0 48.5, 51.5 2da16326

The encoder fusion cuts the request by 6.5% and the output video is byte-identical to master.

  • Linux RADV (gfx1151, Vulkan): the padding before the VAE goes from 2.3 s to 0.6 s.

Not covered

  • Metal and ROCm were not run. Metal and Vulkan take the batched GroupNorm fallback.
  • Windows Vulkan (AMD) result is still pending.
  • On Linux RADV every render, master included, hits ErrorDeviceLost in DiT sampling at this size, so Vulkan request time and quality were not measured end to end.

…of one full-clip concat per padded frame (from upstream leejet#2476)
…+ affine + SiLU on CUDA / HIP, one batched GroupNorm elsewhere (from upstream leejet#2476)
@danielhanchen danielhanchen self-assigned this Dec 2, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 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-12-02T04:14:42.395494Z 239d142 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 239d1425c3

ℹ️ 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 367b615 into master Dec 2, 2026
7 checks passed
danielhanchen added a commit to unslothai/unsloth that referenced this pull request Dec 2, 2026
…GroupNorm fallback fix) (#20791)

## Summary

Moves the Studio sd.cpp prebuilt pin from `master-982-0518b34-uf22ff38`
to `master-982-0518b34-u0c69df2` (unslothai/stable-diffusion.cpp at
`0c69df28`). The new build adds three fork changes:

- unslothai/stable-diffusion.cpp#110 (from upstream #2476): the
MiniMax-H3 video VAE pads the last frames into one allocation instead of
one full-clip concat per padded frame. In the encoder, CausalConv3d does
its reflection, downsample end padding and causal zero frames in one
padding op. On CUDA / HIP, TemporalGroupNorm runs GroupNorm + affine +
SiLU as one frame-norm op. CPU, Metal and Vulkan build one batched
GroupNorm over all frames instead of a slice, norm and concat per frame.
- unslothai/stable-diffusion.cpp#111: SYCL and OpenCL keep the per-frame
GroupNorm fallback. The CPU, CUDA, Vulkan and Metal graphs are the same
as in #110.
- unslothai/stable-diffusion.cpp#112: CI only. The Windows CUDA 13
toolkit install no longer fails when it cleans up an extracted redist
folder that is not yet empty. That failure is why the `c4b0713` build
published without its three Windows CUDA 13 bundles, so this build is
the one to pin.

`0c69df28` is three commits ahead of `f22ff38d31`. The source changes
are in `src/model/vae/minimax_h3_vae.hpp`, `src/core/ggml_extensions.*`,
`src/core/ggml_extend.*` and two new CUDA files (`vae_frame_norm.cu`,
`vae_pad.cu`); #112 only touches
`.github/workflows/unsloth-sd-prebuilt.yml`. ggml and the fork's ggml
patch list are unchanged.

## Changes

- `install_sd_cpp_prebuilt.py`: `DEFAULT_TAG` and
`PINNED_RELEASE_ASSETS` move to the new tag, with all 22 assets and
their sha256. The digests come from the release's
`sd-prebuilt-sha256.json`. The two JSON files were hashed after
download. All 22 match the digests the GitHub releases API reports.
- `sd_cpp_args.py`: the new tag joins `METAL_IMPLICIT_GEMM_CONV_TAGS`
and `VULKAN_PAGEABLE_OFFLOAD_TAGS`. `0c69df28` descends from
`f22ff38d31`, so it still carries #103 (implicit GEMM Metal CONV_2D) and
#106 (Vulkan offload in pageable RAM).
- Tests that name the pin move with it:
`test_diffusion_more_families.py`, `test_sd_cpp_args.py` (new row;
`uf22ff38` stays as the previous pin), `test_sd_cpp_cuda_cpu_torch.py`,
`test_sd_cpp_vulkan_cpu_torch.py`,
`test_sd_cpp_metal_vae_conv_default.py`,
`test_sd_cpp_metal_vae_conv_direct.py`,
`test_sd_cpp_metal_vae_conv_status_argv.py` and
`test_h3_native_pageable_offload.py`. The last one now also checks that
`u9213d05` and `ub6ed0ee` stay pageable.

## Tests

Release check: the release is published (not a draft, not a prerelease)
with the same 22 asset names as `uf22ff38`. Apart from the tag, source
commit, timestamp and hashes, `sd-prebuilt-manifest.json` is the same as
the old one, including the asset and CUDA coverage rows.

Linux x86_64 CPU, `uf22ff38` vs `uc4b0713` (the build of #110 + #111;
`u0c69df2` adds only the CI change of #112), using the release zips:
FLUX.2 klein 4B Q4_K_M (4 steps) and Z-Image-Turbo Q4_K_M (8 steps),
256x256, seed 42, `--rng cpu`, Studio's `--flash-attn
off,diffusion=on,te=auto`, 8 threads, A B B A, each render in a fresh
process. For each model all four PNGs are byte-identical. Each log
reports its own tag and commit.

MiniMax-H3 on CUDA, from the fork PR #110 run on an L4 (sm_89): Ref2VA
at 864x480, 124-frame reference video, 8 steps, plain decode,
unsloth/MiniMax-H3-GGUF ref2va Q4_K.

| build | request (s) | decode (s) | output md5 |
| --- | --- | --- | --- |
| before #110 | 848.3 | 48.5 | 2da16326 |
| #110 | 790.3, 794.0 | 48.5, 51.5 | 2da16326 |

The request is 6.5% faster and the output video is byte-identical. The
fork PR also reports the padding step at 124 -> 136 frames, 864x480,
going from 4.78 s to 0.36 s with peak memory 1885 -> 1242 MiB, and CPU
VAE encode latents byte-identical before and after.

Unit tests: the sd.cpp, installer and H3 suites (136 files) give 4639
passed on this branch and 4638 on main. The extra case is the new
previous-pin row. The same 57 failed and 64 errored test IDs show up on
both sides; they are mostly in the H3 image suites, fail the same way on
main, and do not touch the pin. `test_sd_cpp_pinned_prebuilt.py` and
`test_sd_cpp_install_ratelimit.py` pass on this branch. With the pin on
the incomplete `uc4b0713` release (19 assets),
`test_sd_cpp_pinned_prebuilt.py` fails 9 tests (the Windows CUDA 13
routing cases and
`test_the_shipped_asset_list_carries_every_cuda_family_bundle`), so the
suite catches a release that is missing bundles.

## Not covered

- The CPU renders used the `uc4b0713` zips, not `u0c69df2`. The only
change between them is the CI workflow.
- The L4 numbers come from the fork PR's build, not from this release's
CUDA bundle. No new GPU render was made for this pin.
- No Metal, Vulkan, ROCm or Windows render was run for this pin. Metal
and Vulkan take the batched GroupNorm path. In the fork PR, Linux RADV
only measured the padding step (2.3 s to 0.6 s), because every render at
that size, master included, hit `ErrorDeviceLost` in DiT sampling.
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