Repository navigation
MiniMax-H3 VAE: fold frames into one GroupNorm only on backends that normalise every dim-3 slice - #111
Conversation
…rm covers one dim-3 slice The batched encoder fallback from #110 folds frames x batch into ggml dim 3 and issues one GROUP_NORM. The pinned ggml SYCL and OpenCL GroupNorm kernels launch num_groups work groups over ne0*ne1*ne2 elements, so every frame after the first is left unwritten (the OpenCL GroupNorm+mul+add fusion also takes its group size from the whole tensor). Fold only on backends whose GroupNorm handles every dim-3 slice (CPU, CUDA, ROCm, MUSA, Metal, Vulkan); elsewhere issue one GROUP_NORM per frame and batch item. The CPU / CUDA / ROCm / Metal / Vulkan graphs are unchanged.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65daec54ce
ℹ️ 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".
| // MiniMax-H3 VAE encoder TemporalGroupNorm: every frame must be its own GroupNorm item on every backend. | ||
| // | ||
| // Build (after `cmake -B build-cpu -DSD_WEBP=OFF -DSD_WEBM=OFF && cmake --build build-cpu`), then run the binary: | ||
| // g++ -std=c++17 -O1 -DGGML_MAX_NAME=160 -DGGML_USE_CPU -DSD_GGML_FUSED_ROPE_ATTN -DSD_GGML_H3_FUSED_OPS \ | ||
| // -DSD_GGML_H3_FUSED_QK_NORM -I src -I include -I ggml/include -I ggml/src -I thirdparty \ | ||
| // scripts/minimax_h3_frame_group_norm_test.cpp build-cpu/libstable-diffusion.a build-cpu/ggml/src/libggml.a \ | ||
| // build-cpu/ggml/src/libggml-cpu.a build-cpu/ggml/src/libggml-base.a -fopenmp -lpthread -ldl \ |
There was a problem hiding this comment.
Keep the regression test local rather than committing it
The newly committed regression test violates CONTRIBUTING.md:21, which explicitly prohibits including test code or test scripts in commits and requires keeping them local while reporting verification results in the PR description. Remove this file from the committed change and retain the verification evidence in the change description instead. Root AGENTS.md explicitly requires following these contribution expectations.
AGENTS.md reference: AGENTS.md:L122-L124
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 43ebb25: the test stays local per CONTRIBUTING; results are in the PR description.
|
@codex review |
1 similar comment
|
@codex review |
|
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". |
…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.
Summary
Follow-up to #110. The MiniMax-H3 VAE encoder fallback (used wherever the fused CUDA / HIP frame norm is not available) folds
frames x batchinto ggml dim 3 and normalises the whole clip with oneGROUP_NORM. That is only correct on backends whose GroupNorm normalises every dim-3 slice on its own. On the pinned ggml (leejet/ggml d803c238 plus the 55 fork patches) two buildable backends do not:[W, H, C, N]ne03num_groups * ne[3]blocks (stock andgroup-norm-par)num_groups * ne[3]workgroups(ngrp, ne03)threadgroups (since leejet/ggml a70d9e12)-DSD_SYCL=ON)num_groupsworkgroups overne0*ne1*ne2elements-DSD_OPENCL=ON)n_groupsworkgroups overne0*ne1*ne2; the GroupNorm+mul+add fusion usesnelements / groupsas its group sizeReference video is encoded in 17-frame chunks, so any Ref2VA request on a SYCL or OpenCL build hit this.
Change
ggml_ext_group_norm_batches_dim3(backend): true only for the backends verified above (CPU,CUDA,ROCm,MUSA,MTL,Vulkan, by ggml registry name).TemporalGroupNorm::forwardkeeps the MiniMax-H3 VAE: reference padding in one allocation and encoder norm fusion (from upstream #2476) #110 folded graph on those backends and otherwise issues oneGROUP_NORMper frame and per batch item (the pre-MiniMax-H3 VAE: reference padding in one allocation and encoder norm fusion (from upstream #2476) #110 per-frame graph, with batch items split as well so a batch above one is also correct there).The CPU / CUDA / ROCm / Metal / Vulkan graphs are unchanged, and the fused CUDA / HIP frame norm path is untouched.
Testing
A local test (kept out of the PR per CONTRIBUTING) builds the real
TemporalGroupNormgraph against backends named like each ggml registry, checks theGROUP_NORMnode shapes, replays the SYCL / OpenCL single-slice launch on the host, and runs the graph on CPU against an FP64 per-frame oracle. Shapes: 5 frames batch 1, 3 frames batch 2, 1 frame batch 1.GROUP_NORMwithne3 = frames * batch; the replayed single-slice launch leaves 12288 of 15360 elements unwrittenCPU output is byte-identical (FNV-1a of the output bytes) between the pre-#110 parent, master and this branch on every shape, and the per-item graph matches the FP64 oracle to 4.8e-7. CPU and Vulkan builds compile.
Not covered here: no Intel SYCL or OpenCL device was available, so the defect is shown from the kernel launch bounds and the host replay rather than on hardware. A system ggml (
SD_USE_SYSTEM_GGML) older than leejet/ggml a70d9e12 would still mis-handle the folded clip on Metal.Note on #110 timing
The 6.5% L4 request-time figure in #110 came from one base request against two head requests, so it has no base A/A spread behind it. The isolated padding and norm kernel gains were measured separately; the end-to-end number should be read as indicative until a base A/A plus interleaved A/B run is recorded.