Skip to content

MiniMax H3 / FastH3 transformer blocks on CUDA in int8, as a library beside the engine (non-lane; proposal) - #585

Closed
drowzeys wants to merge 1 commit into
ashhart:mainfrom
drowzeys:h3-cuda-family
Closed

drowzeys wants to merge 1 commit into
ashhart:mainfrom
drowzeys:h3-cuda-family

Conversation

@drowzeys

Copy link
Copy Markdown
Contributor

Thank you, Ash, for TensorFold and for the CUDA runtime this builds on. This is offered as a proposal, and I want to be plain about where it sits outside the rules before anything else.

Where it sits outside the rules

If the answer is still no, that is a fine answer; it will keep living on the fork.

What it is

A library, zig build tf-h3 -Dnvcc=... → libtf_h3.so, that runs the 50 transformer blocks of MiniMax H3 / FastH3 for a host pipeline which owns everything else (text encoder, sampler, patch projections, final layer, decoders) and shares its CUDA context.

  • zig/kernels/cuda/h3_products.cuh: an int8 product on mma.sync m16n8k32 (plain, SwiGLU and group-scaled epilogues) and tile-routed int8 attention with an online softmax.
  • zig/kernels/cuda/h3.cu: the row kernels (modulated RMSNorm to int8, head layout with rotary, pooling, top-k routing, gate mix) and the entry points.
  • zig/src/families/h3/: checkpoint.zig (safetensors by name, with host tests), cuda_weights.zig (quantize on the GPU, or read the saved int8 copy), cuda.zig (the forward), cuda_lib.zig (the C entry points).
  • zig/build/cuda.zig: the tf-h3 step, which builds only this family's kernel image, and the checkpoint tests in test-cuda-host.
  • docs/recipes/minimax-h3-cuda.md: the receipt.

Receipt

One DGX Spark (GB10, compute capability 12.1, CUDA 13.0 toolkit), checkpoint FastVideo/FastVideo-FastH3-Comfy fastvideo_fasth3_8step_v2_pruned_bf16.safetensors, host ComfyUI at a4b5a045, 124 frames, 8 passes, measured 2026-10-09. The kernels are the ones in this change; the Zig around them was split into smaller files afterwards and renders a bit-identical clip (two seeds).

Size Rows This family, a pass The host's own blocks in bf16, a pass
864x480 15,452 7.1 s 10.5 s (dense attention)
1280x736 34,507 18 s not measured
1344x768 37,763 20.5 s 29.4 s (its block-sparse attention)
Check, same input on both sides Result
int8 product kernel against a float64 host sum, sampled outputs, four shapes worst relative difference 0.004
Tile attention kernel against exact float64 attention over the same int8 inputs relative error 0.002
One block, dense attention, against the host's bf16 block cosine 0.9999, relative error 0.015
All 50 blocks, dense attention, 864x480 cosine 0.998, relative error 0.065
All 50 blocks, dense attention, 1344x768 cosine 0.996, relative error 0.090
Same seed twice bit-identical clip

Raw tensor-core rate on the GB10 measured on registers: int8 245 TOPS, bf16 122 TFLOPS; the product kernel reaches 150 to 175 TOPS on these shapes.

Checks run on this branch

Check Result
zig fmt --check on the changed Zig files clean
python3 tools/zig/lean_check.py 510 problems on main (4ebf52a), 510 with this change: zero added
zig build test-cuda-host all steps succeed
zig build tf-h3 on a GB10 builds; the library renders the clips above

Not done, and not claimed

  • No FP64 reference per projection class is in the tree. The kernel checks above were run from a bench harness and a host plug-in that are not part of this change; I can add them as tf-cuda-test commands if that is the gate you want.
  • One GPU model (GB10) and one checkpoint (FastH3 8-Step V2).
  • The 50-block error is 6.5% against bf16. I measured where it comes from: about three quarters is the 8-bit rounding of activations; giving the 128 largest channels their own scale would take it to about 5.9%, and clipping the scale is much worse. That is the floor for this design.
  • A Metal family for the same model exists on the fork (drowzeys/TensorFold, branch h3-1.0.4) and is not in this change, to keep it to one thing.

It is used today by keys-TensorFold Studio on a DGX Spark.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CPyz4HarJ7ZubrPWPjtSdX

…for a host pipeline

A video model's denoising transformer: no lane round, and int8 products and attention on mma.sync m16n8k32. It is
a library (zig build tf-h3) beside the engine; the lane core and the server are untouched. The recipe holds the
receipt: 7.1 s a pass at 864x480 on a GB10 against 10.5 s for the host's bf16 blocks, cosine 0.998 after 50 blocks.
@drowzeys

Copy link
Copy Markdown
Contributor Author

The Mac half of this work is now #586 (the same model's transformer on Metal), kept as its own pull request so each is one change. Both add files under zig/src/families/h3/ with no file in common, so they merge in either order.

@ashhart

ashhart commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Thank you, @drowzeys, for the careful write-up, and for saying plainly where this sits against the rules. The answer is still no, for the reasons you named. TensorFold is one kind of engine: every token goes through lane rounds and drafted output is checked against plain decoding, and H3 has neither a token stream nor drafts to check. The int8 projections and attention are also a precision trade we don't make anywhere in the engine. Those hold however good the code is, and it is good: nothing in the lane core or the server, host tests, and a receipt with its error measured. It belongs in its own repository on top of the runtime, the way you run it on the fork today. If the fork needs something from the runtime to stay a clean dependency, such as a stable way to share the CUDA context, a small PR for that hook would be welcome. I'll close this one. Thanks again.

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.

2 participants