Skip to content

MiniMax-H3 VAE: fold frames into one GroupNorm only on backends that normalise every dim-3 slice - #111

Merged
danielhanchen merged 3 commits into
masterfrom
sd110-recheck-fixes
Dec 2, 2026
Merged

danielhanchen merged 3 commits into
masterfrom
sd110-recheck-fixes

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

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 batch into ggml dim 3 and normalises the whole clip with one GROUP_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:

Backend GroupNorm launch for [W, H, C, N] Folded clip
CPU loops over ne03 correct
CUDA / ROCm / MUSA num_groups * ne[3] blocks (stock and group-norm-par) correct
Vulkan num_groups * ne[3] workgroups correct
Metal (ngrp, ne03) threadgroups (since leejet/ggml a70d9e12) correct
SYCL (-DSD_SYCL=ON) num_groups workgroups over ne0*ne1*ne2 elements frames 2..N unwritten
OpenCL (-DSD_OPENCL=ON) n_groups workgroups over ne0*ne1*ne2; the GroupNorm+mul+add fusion uses nelements / groups as its group size frames 2..N unwritten or mixed across frames

Reference video is encoded in 17-frame chunks, so any Ref2VA request on a SYCL or OpenCL build hit this.

Change

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 TemporalGroupNorm graph against backends named like each ggml registry, checks the GROUP_NORM node 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.

Build Result
master (367b615) 18 checks fail: SYCL / OpenCL / unknown backends get one folded GROUP_NORM with ne3 = frames * batch; the replayed single-slice launch leaves 12288 of 15360 elements unwritten
this branch all checks pass

CPU 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.

…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.
@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-02T05:49:15.923251Z aa0bb15 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1 to +7
// 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 \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 43ebb25: the test stays local per CONTRIBUTING; results are in the PR description.

@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. What shall we delve into next?

Reviewed commit: aa0bb1554e

ℹ️ 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 c4b0713 into master Dec 2, 2026
7 checks passed
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