Repository navigation
Upstream PR: H3 Metal products on h3_gemm_32x64 in 64-row bands, 64-tile decoder pass - #4641
Merged
ashhart merged 13 commits intoNov 24, 2026
Conversation
ashhart
force-pushed
the
feat/108-upstream-pr-h3-metal-products-on-h3-gemm
branch
from
November 24, 2026 00:03
7f19914 to
21fd564
Compare
ashhart
force-pushed
the
feat/108-upstream-pr-h3-metal-products-on-h3-gemm
branch
from
November 24, 2026 06:43
6334933 to
89d0050
Compare
(cherry picked from commit cf06d04)
…d edge and a ragged tile (cherry picked from commit 0470bc0)
Each threadgroup is 64 x 128 with four warps of 32 x 64, so a loaded fragment feeds two MMAs where MLX's 32 x 32 warp feeds one, and the K chain is MLX's own: 32-deep steps in order. Every output's sums, the latent and the PNG are unchanged; test-h3-gemm holds the new kernel against MLX's bit for bit across a band edge, a whole band and a ragged tail. At 4,120 rows the shapes run at 116, 116, 108 and 103 TFLOP/s against MLX's 118, 118, 113 and 89, so the products sit at the tensor units' rate and only the 14,336-deep fc2 gains (0.3 s of the six steps); warm 2048 pictures took 12.12 and 12.13 s against 12.30 s. (cherry picked from commit 8d6f94c)
The image decoder decodes up to its scratch's 64 tiles a pass instead of 16, two passes at 2048x2048 instead of eight; every tile's pixels are independent, so the latent and PNG are byte-identical. (cherry picked from commit b6b209f, decoder part only)
…es it after gemm_nax's fragments
…FastH3's and the picture model's shapes
…ecoder tool reads
ashhart
force-pushed
the
feat/108-upstream-pr-h3-metal-products-on-h3-gemm
branch
from
November 24, 2026 13:43
89d0050 to
cbd2211
Compare
Owner
|
Thank you @plotarmordev. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
H3's transformer products move from MLX's
gemm_nax(swizzle 2) to H3's ownh3_gemm_32x64kernel, whose threadgroups walk 64 row tiles under each weight tile, so a 2048x2048 picture reads each weight tile once while it is cached. The decoder decodes 64 tiles a pass instead of 16. Sums are unchanged: the pictures are byte-identical, and a warm 2048 picture goes from 13.03 s to 12.12 s on my M5 Ultra.-xcherry-picks.main; h3: MiniMax-H3-Image's prompt encoder, transformer and decoder resident across pictures #3718 (MiniMax-H3-Image resident across pictures) has merged into it.atc overlap --json: no conflict; the PR merges clean on currentmain.How to check
11b815e376ce122026f3c4011029ada2a56da53c(Ash'smain). Head commit:7f199148ea47c1fb71b1ee6e8eac5895cf88a4d2.zig build test-h3-gemm: exit 0, 1 passed, 0 failed, 0 skipped. It runsh3_gemm_32x64(whole and ragged) and MLX'sgemm_naxband of 4 on the same inputs and requires every output bit equal, across a band edge, a ragged tile and an untouched guard row tile.zig build tf-kernel-contract -Dcpu=apple_m1 -Doptimize=ReleaseFast && zig-out/bin/tf-kernel-contract --only "h3 product": exit 0,SUMMARY 2 kernels: 2 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems. Each product carries a planted control, its 32-deep K steps reversed, and both go red at the shapes gate.zig build dev-tools -Doptimize=Debug: exit 0; it buildstf-h3-image-server, whose decoder tool readsmost_batchthroughimage.zig.zig build test test-golden: 1910 passed, 4 failed, 30 skipped; 979/986 steps; the fifth failed step is thetensorfold-nativememcpy link check. The failures are the same set as on basemain11b815e37and none is in h3: the two deepseek_v41vision_configtests, the net DNS test (.invalidresolves on my Mac), andpersistence_identity. On base,serve_steps_test:278failed once and passed on rerun; here it passed.tf-h3-image-server, card 34'sprompt.txt(sha256cc969bca…), seed 42, six steps, 2048x2048, one cold request and then warm requests in the same resident server. Timings are from my fork receipts, not a new run on this base: before is 13.03 s (my recorded baseline in the fork'sdocs/recipes/minimax-h3-image-metal.md, forkdfa6d9da2), after is 12.12 and 12.13 s (fork8d6f94ca4, the same kernel as this head). Every PNG before and after is sha1904814d66e7d…, byte for byte.Checks on this head
7f199148ea47c1fb71b1ee6e8eac5895cf88a4d2python3 tools/zig/lean_check.py, on the base and on this head: 165 on base11b815e37, 165 on this head, 0 new (lean_new.py). The 165 are inherited frommain.5bd056431,zig-macos-dev-toolsfailed compilingtf-h3-image-server:zig/tests/h3_image_decoder.zig:22: root source file struct 'image' has no member named 'most_batch'(job). The server mapsh3_image_decodertoimage.zig, and I had dropped itsmost_batchre-export as unused;3378466a8restores it. CI on7f199148eis running.Receipt
8d6f94ca4for the after timing, Zig 0.17.0, macOS 27.0 Metal, M5 Ultra 256 GB, MiniMax-H3-Image bf16 weights (117.6 GiB resident).f3563c56…latent,904814d66e7d…PNG);test-h3-gemmbit for bit against MLX.tools/bench_openai.py: n/a, an image model with no token decode.Kernel contract, only when a GPU kernel is new or changed
h3_gemm_32x64andh3_gemm_32x64_raggedinzig/src/core/contract/registry.zig, replacing MLX'sgemm_naxfor H3's products.zig/tests/contract/metal_h3.zig: each product's 32-deep K steps run in reverse, so its sums round differently fromgemm_nax's. Both are red at the shapes gate, as planted:test-h3-gemmalso checks both againstgemm_naxbit for bit and that the guard row tile past the product stays untouched.SUMMARYline and exit status: Metal only.tf-kernel-contract --only "h3 product"on the M5 Ultra at5bd056431(the kernels and the contract are unchanged since) exits 0:Both
h3_gemm_32x64andh3_gemm_32x64_raggedpass gates 1-4 and launch 128 threads with 0 threadgroup bytes.test-h3-gemmexits 0.Checklist
How to check
7bd4b6815acc107a486b88ec0cb98afd8f0e4c686334933bab5671ea2b4e53db3879941c3cd08cb7Test results:
zig build test-h3-gemmat5bd056431b17(older head): 1 passed, 0 failed, 0 skippedzig build test test-goldenat7f199148ea47(older head): 1910 passed, 4 failed, 30 skipped./.zig-cache/o/df7000222636bb896dd27c6a9f9914fe/test (the test-h3-gemm binary, run directly after zig build test-h3-gemm --summary all was a cache hit)at8a6c776cb9c0(older head): 1 passed, 0 failed, 0 skippednice -n 10 zig build test test-golden --summary failuresatd2af92294558(older head): 1912 passed, 4 failed, 30 skipped./.zig-cache/o/ab48407ae88445c88db672e9ad084642/test (the test-h3-gemm binary, run directly after zig build test-h3-gemm --summary all was a cache hit)atd2af92294558(older head): 1 passed, 0 failed, 0 skippedzig build test test-golden --summary allateaf1613e92ee(older head): 1905 passed, 4 failed, 30 skippedzig build test-h3-gemm test-metal-runtime-source-modes-host test-h3-geometry compile-h3-host test-kernel-contract --summary allatbbb8e7b91665(older head): 293 passed, 0 failed, 0 skippedzig build tf-kernel-contract && zig-out/bin/tf-kernel-contract --only "h3 "atbbb8e7b91665(older head): 15 passed, 0 failed, 0 skippedzig build test-h3-gemm --summary allat5bd056431b17(older head): 1 passed, 0 failed, 0 skippedzig build tf-kernel-contract -Dcpu=apple_m1 -Doptimize=ReleaseFast && zig-out/bin/tf-kernel-contract --only "h3 product"at5bd056431b17(older head): 2 passed, 0 failed, 0 skippedzig-out/bin/tf-kernel-contract --only h3ateaf1613e92ee(older head): 19 passed, 0 failed, 0 skippedzig-out/bin/tf-kernel-contract --only "h3 product"at886ff8fd0b4f(older head): 2 passed, 0 failed, 0 skipped./zig-out/bin/tf-kernel-contract --only "h3 product"at886ff8fd0b4f(older head): 2 passed, 0 failed, 0 skippedzig build test test-golden --summary failuresat886ff8fd0b4f(older head): 1905 passed, 4 failed, 30 skippedzig build test test-golden --summary lineat5bd056431b17(older head): 1918 passed, 4 failed, 30 skippedzig build tf-kernel-contract && ./zig-out/bin/tf-kernel-contract --only h3_gemm_32x64at5bd056431b17(older head): 2 passed, 0 failed, 0 skippedzig build dev-tools -Doptimize=Debugat3378466a8809(older head): 1 passed, 0 failed, 0 skippedzig build compile-h3-host test-h3-geometry test-h3-modulation-bf16 -Dcpu=apple_m1 --summary allat6334933bab56: 79 passed, 0 failed, 0 skippedzig build test-h3-gemm -Dcpu=apple_m1 --summary allat6334933bab56: 1 passed, 0 failed, 0 skippedzig build dev-tools -Dcpu=apple_m1 --summary allat6334933bab56: 307 passed, 0 failed, 0 skipped