Skip to content

MiniMax H3 on CUDA: tf-h3-dit-cuda runs the denoising loop around the block library - #3853

Open
ashhart wants to merge 1 commit into
mainfrom
lead/h3-dit-cuda
Open

ashhart wants to merge 1 commit into
mainfrom
lead/h3-dit-cuda

Conversation

@ashhart

@ashhart ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Adds tf-h3-dit-cuda, the CUDA counterpart of the Metal tf-h3-dit tool for MiniMax H3 / FastH3. On CUDA the bf16 block library has only one forward entry, and the host was expected to do the rest. This tool is that host.

From the same case file the Metal tool reads, it:

  • puts the text, first-frame, audio and video rows into the stream;
  • runs every block through tf_h3_forward_host each step, with that step's AdaLN lines;
  • applies the final norm, the output heads and the reference's Euler steps on the host;
  • writes the same float32 rows the Metal tool writes.

The Euler step moves from zig/tests/h3_dit.zig into zig/src/families/h3/euler.zig and is shared by both tools, so the Metal tool's arithmetic is unchanged.

zig build compile-h3-dit-cuda cross-compiles it for x86_64 Linux without NVCC. zig build test-h3-dit-cuda runs a synthetic 2-block case on the CUDA runtime fake against a float64 reference of the same steps. A single step equals one forward plus one Euler update exactly.

No MiniMax H3 weights are included or were used. The CUDA numbers still need a GPU run once the weights can be used.

Checked on this head: test-h3-dit-cuda and compile-h3-dit-cuda on Linux, zig build check-release-paths, zig fmt --check, and the lean check (no new problems). On macOS, an existing h3 ownership test on main hangs in Zig's debug stack capture; that is tracked separately.

  • Synthena

@plotarmordev

Copy link
Copy Markdown
Contributor

Hi Ash, before I open anything: my fork has the same piece, the CUDA host loop around the block library (cuda_lib.zig, h3.zig), with the transformer's AdaLN on the GPU, --serve, and the Metal tool's latent format written so the stages can swap. On a 2048 render it comes out at 29.2 dB PSNR against the Mac's. Which PR do you want to carry the loop? I can fold my changes into yours, rebase onto yours, or open a separate PR. I'll go with whichever you pick, and I won't open a competing PR until you answer. My PR stacks on #3733, so it waits for that one to merge either way.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Thank you @plotarmordev for asking before opening a competing change.

This PR carries the CUDA tool only: tf-h3-dit-cuda and the shared Euler step. Please keep your server loop, GPU AdaLN and --serve work in a separate PR stacked on #3733, reusing euler.zig and the tool's latent format so the stages can swap. Do not fold that serving work into this tool PR.

A CUDA run with the real MiniMax H3 weights is still needed. We were unable to run it here because the weights are not available. Please run tf-h3-dit-cuda transformer.safetensors case.safetensors out_prefix on a 2048 render and post the float32 rows or their hash with the PSNR against the Metal tool; the rows must match the Metal tool's output at the same case and step count.

  • Synthena

@ashhart
ashhart force-pushed the lead/h3-dit-cuda branch 2 times, most recently from baaa44e to 520e86a Compare November 21, 2026 09:46
…lock library

The CUDA library runs MiniMax H3's blocks (tf_h3_forward / tf_h3_forward_host) and leaves the rest to its host. For a
case file of the shape tf-h3-dit reads, tf-h3-dit-cuda (h3/cuda_loop.zig, zig/tests/h3_dit_cuda.zig) does that rest:

- reads and checks the case with the Metal tool's geometry.read, and copies the block tables into the library's
  (blocks, lines, 6, hidden) float layout from the case's (6, lines, hidden) bf16;
- each step: the text rows, then the first frame's, audio and video latent rows into the bf16 stream (Metal's
  h3_rows_in), every block through the library with the step's lines, the final modulated RMSNorm with the step's
  times (h3_final_norm, rounding where h3_mod rounds) and the output heads (h3_rows_out), all on the host;
- the reference's Euler step of the video rows and of the audio rows not held, now one function (h3/euler.zig) that
  tf-h3-dit calls too, unchanged;
- writes .first-video/.first-audio and .video/.audio float32 files as tf-h3-dit does (options dense, from=K, once;
  the Metal tool's GPU rescheduling is not offered).

compile-h3-dit-cuda cross-compiles it for x86_64-linux-gnu without NVCC; tf-h3-dit-cuda builds it beside tf-h3 with
-Dnvcc. test-h3-dit-cuda runs the loop over a synthetic 2-block case on the runtime fake, whose kernels do nothing:
two steps equal a float64 reference of the same host arithmetic within one bf16 ulp (4.4e-5 relative seen), and one
step equals one forward plus one Euler update exactly.
@mikolaj92

Copy link
Copy Markdown
Contributor

Rebased the branch onto current main (9fa8863). The h3_dit.zig conflict is resolved keeping for audio (shared euler module) together with main's timing print ().\n\nLocal checks all pass on the rebased commit: , , , , , (linux cross).\n\nThe rebased head is , pushed to branch , so the PR head can be fast-forwarded from there.

This branch has not been deployed

No deployments
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.

3 participants