Skip to content

h3: MiniMax-H3-Image's prompt path and image decoder on CUDA, with their selftests and timings - #3733

Merged
ashhart merged 16 commits into
ashhart:mainfrom
plotarmordev:feat/70-upstream-pr-minimax-h3-image-spark-speed
Nov 24, 2026
Merged

ashhart merged 16 commits into
ashhart:mainfrom
plotarmordev:feat/70-upstream-pr-minimax-h3-image-spark-speed

Conversation

@plotarmordev

@plotarmordev plotarmordev commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

MiniMax-H3-Image's prompt path and VAE image decoder run on the H3 CUDA blocks, so a Spark with no Metal and no PyTorch can run both stages:

  • tf-h3-image-prompt-cuda runs Qwen3-VL to layer 50 and the token refiner, one layer's weights uploaded at a time.
  • tf-h3-image-decoder-cuda runs the VAE in bf16 over batched tiles.
  • Each writes the file its Metal sibling writes, so any stage swaps. The CPU tools (tf-h3-image-prompt-host, tf-h3-image-decoder-host) are independent reference implementations.
  • Both GPU tools carry a synthetic selftest against the host's float64 reference. The decoder's selftest gates each of the 24 blocks, on the GPU's own input, at 90% of values identical to the float64 reference, and the picture at the Metal decoder's 80% identical / at most 2 apart bound. The prompt's selftest gates its text, refiner and vision rows against the same float32-noise bounds.
  • The decoder's RMS norm sums the row's squares in f64, so its mean rounds as the reference's does.

Same prompt, seed 42, six distilled steps, BF16 throughout, one GB10:

Stage CPU reference CUDA Gate
Prompt, 2048² 88 s 18.0 s cold, 20.1 s warm mean selftest passes
Prompt, 4096² 98 s 18.3 s cold, 18.5 s warm mean selftest passes
Decoder, 2048² 218 s 5.6 s (5.25 s on the GPU) selftest passes
Decoder, 4096² 771 s 20.4 s (20.3 s warm mean) selftest passes

The GB10 run's lines, each of the 24 blocks and every prompt gate, are in docs/receipts/h3-image-cuda-gb10-0bfee52e, built at 0bfee52e.

Checks on this head

  • Head commit: 5855d56a3; the code is 5ef2a963b plus the limits receipt line.
  • Lean checker, python3 tools/zig/lean_check.py: 221 problems on this head against 221 on main, zero new; all 221 are inherited.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test test-golden: 902 of 905 steps, 7,182 of 7,247 tests passed, 64 skipped, 1 failed. The failure is stage net's unknown-host test, which expects AddressUnresolved and gets AddressInUse because this Mac's resolver answers .invalid; it fails identically on main here and is unchanged by this branch. test-golden has 55 of 55 equal to the server goldens.
    • zig build compile-cuda-tests -Dtarget=x86_64-linux-gnu: pass.
    • zig build test-contract-images-host: pass.
    • zig fmt --check on every changed Zig file and git diff --check: clean.
  • CI: runs on this head; at 0bfee52e every job passed but zig, whose lean step found the seven comments this head makes one line; every job passed at 5ef2a963, the code head.
  • GB10 (sm_121, driver 580.173.02), 0bfee52e plus the job script: both selftests pass. zig build kernel-contract passes gates 1 to 4 for all 685 kernels but exits 1 (TestFailed) on 188 limit problems; see the SUMMARY below. kernel-contract-limits exited 1 with 28 stale records, every kernel within its bounds: 10 were h3p_norm and h3p_heads, whose records this head replaces with that run's measurements; the other 18 (fn_row_topk, tf_exl3_prompt_gu, tf_exl3_prompt_down, tf_q35_gdn_slots_*) are inherited from main.
  • Limits-only run at 5ef2a963 (that commit plus the job script), GB10: tf-cuda-test kernel-contract-limits zig-out/fatbin checks every record against the fatbins and exits 1 only on the 18 stale records inherited from main; h3p_norm and h3p_heads are current on all five SMs, and no h3p_* or h3d_* entry is stale:
    INFO limits fatbins: images built by nvcc 13.0, checked against nvcc 13.0's records
    FAIL kernel-contract-limits: 18 problems
    FAIL kernel-contract-limits: TestFailed
    
  • Not run, and why: kernel-contract's live gate 5 against the updated records needs another GB10 run.

Receipt

  • Main against branch: the timings above, from the same case and settings.
  • Boxes it reaches: CUDA on a GB10, through the two tools. No token path changes.
  • New switch? None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: 0bfee52e, Zig 0.17.0, nvcc 13.0, an NVIDIA GB10 (sm_121, driver 580.173.02); synthetic weights, no checkpoint.
  • Paths and platforms the change reaches, which I ran and which I could not: CUDA (ran on a GB10); Metal and HIP are not reached.
  • Exactness, decode and prompt speed: n/a, this is a tool beside the engine.
  • Licence of any new weights or drafter: n/a, no weights.
Kernel contract
  • Kernels registered with the contract, and the kernel each one replaces: the decoder's nine (h3d_post_quant, h3d_embed, h3d_rms_norm, h3d_layer_norm, h3d_linear, h3d_finish, h3d_heads, h3d_attention, h3d_swiglu) and the prompt's ten (h3p_norm, h3p_heads, h3p_attention, h3p_glu, h3p_add, h3p_scatter_add, h3p_embed, h3p_splice, h3p_linear, h3p_round); none replaces an engine kernel.
  • A planted control for each new kernel, and each one fails as planted: the CUDA contract's own planted controls run with the contract image, as they do for every registered CUDA kernel.
  • Each backend's SUMMARY line and exit status, GB10 at 0bfee52e, exit 1 on limits:
    SUMMARY 685 kernels: 685 pass gates 1-4, 0 fail, 8 known findings; 422 controls: 422 red as planted, 0 missed; 188 limit problems; gates 3449547 ms, limits 765095 ms
    FAIL kernel-contract: 0 gate failures, 0 controls missed, 188 limit problems
    FAIL kernel-contract: TestFailed
    
    The 8 known findings are the existing qwen35 and glm NaN-key ones. Of the 188 limit problems, 183 are main kernels with no compiled usage recorded (qwen4_*, qwen35*, nvfp4_experts_tile, exl3_experts, flashnext_mtp) and 3 are live launches of main kernels recorded as 0 (fn_row_topk, tf_exl3_prompt_gu, tf_exl3_prompt_down). The other 2 are h3p_norm and h3p_heads on sm_121, measured at 27 and 40 registers against stale records of 25 and 38; this head sets both records to that run's RECORD lines, and the limits-only run at 5ef2a963 checks them current on all five SMs (see Checks).
  • Chips I could not run: sm_80, sm_86, sm_89 and sm_120 compile and are recorded but were not run.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

The inference checklist does not apply: these are tools beside the engine, and no token path changes.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev. The CUDA prompt and decoder tools are clearly scoped, and the GB10 selftest receipts are useful. I read the diff against current main. Here is what we need before it can land:

  1. Stack and overlap with h3: MiniMax-H3-Image's prompt encoder, transformer and decoder resident across pictures #3718. This diff still carries the h3: MiniMax-H3-Image's transformer on Metal from a picture case (tf-h3-image) #2766 to h3: MiniMax-H3-Image's text to image end to end: the prompt tool writes the canvas and the seed's starting rows #2781 picture stack: the Metal image tools and kernels, docs/recipes/minimax-h3-image-metal.md, and the h3.zig and geometry.zig changes. That is about 45 files, and h3: MiniMax-H3-Image's prompt encoder, transformer and decoder resident across pictures #3718 carries its own, different copy of the same files. Both PRs add zig/tests/h3_image.zig, zig/tests/h3_image_prompt.zig and docs/recipes/minimax-h3-image-metal.md as new files with different contents, so whichever lands second will not apply. Once the stack is on main, please rebase so this diff holds only the CUDA commits. Please also say which version of zig/build/h3_image_prompt.zig you expect to land: zig/build/h3_image_prompt_cuda.zig:13 calls its rope(), which h3: MiniMax-H3-Image's prompt encoder, transformer and decoder resident across pictures #3718's version does not have.
  2. zig/src/core/h3_core.zig:1-4 and zig/build/h3_host.zig:94-101. Main's coreModule builds from zig/src/core/root.zig, which already exports safetensors, checkpoint_read_ahead and checkpoint_fixture. h3: MiniMax-H3-Image's prompt encoder, transformer and decoder resident across pictures #3718 keeps root.zig. Is the separate module needed? If not, please drop it so both branches use main's module.
  3. Limits on the updated records. zig/src/core/contract/h3_image_cuda_records.zig:21-22 sets h3p_norm and h3p_heads from the last run, and no limits run has checked them yet. Please post the kernel-contract-limits output at this head. Only the 18 records inherited from main should be stale, with no h3p_* or h3d_* entries.
  4. Existing H3 paths. The diff changes code that main's clip transformer already uses: checkpoint.zig:33,70 now keeps the file descriptor open until deinit, and main's CUDA cuda_weights.zig reads through it. It also changes h3.zig:186,337,357,380 and geometry.zig on Metal for audio-free cases and per-step heads. Reading the code, the clip path looks unchanged. Could you post a main-against-branch run of one existing clip case that shows identical velocities? If that run isn't possible, please say why.
  5. CI. Please confirm that every CI job is green at 5ef2a963. The description gives the result at 0bfee52e.
  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @plotarmordev. The CUDA prompt and decoder selftests and their GB10 receipts are useful, and the description now records the limits run and green CI at the code head.

Three things remain. The diff still carries the Metal image stack and the h3_image test files that #3718 also adds, so please rebase to the CUDA-only commits and tell us which h3_image_prompt.zig version should land given the rope() call. Please also confirm whether the separate h3_core module is still needed now that main's root exports the same files. Last, post a main-against-branch run of one existing clip case showing identical velocities, or say why that is not possible.

  • Synthena

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

I checked the separate h3_core question on M5 Max with Zig 0.17.0 at 5855d56a. zig build test-h3-image-prompt test-h3-image-prompt-host test-h3-image-decoder-host test-h3-geometry -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary all passed 96/96.

In scratch, pointing coreModule in h3_host.zig to core/root.zig compiled the H3 libraries but broke the decoder host test: Zig assigned the same picture sources to both core and picture_writer. Sharing one core module with the decoder's host-test writer, then routing its resample import and the MOSS PNG test through core.picture, made the command pass with test-h3-boundaries compile-h3-library added. All 27 steps succeeded, with 38 newly run tests passing and unchanged tests cached. That makes the shared root viable for those host checks if the picture module ownership changes with it.

The trial merge against 46c6ee22 had two conflicts. Pairing this head with #3718 had 21, with both CUDA and CPU prompt tools calling h3_image_prompt.zig's rope(). Keep that helper in the selected build module when splitting the stack. The clip velocity comparison still needs a checkpoint run.

Rechecked 8c4435d63 against 37fa51d23. The trial merge was clean and the same M5 host command, with test-h3-boundaries compile-h3-library added, passed all 132 tests and 29 steps. The new head still uses h3_core.zig. It conflicts with the new #4287 resident H3 train in 20 paths, including the shared prompt, decoder and encoder build modules. The Metal-only #4283 foundation also overlaps in eight paths. This run did not repeat the CUDA model checks.

After #2766 landed at 5f53c445e, I reran the merge check on unchanged head 8c4435d63. It now has eight conflicts against main, in the shared H3 picture reader, its fixtures, the Metal build wiring and the picture recipe. These are the same eight paths that overlapped #4283. The earlier 132 host passes apply to the pre-landing trial tree.

Igor Lessio - AIFLOW LABS

ashhart pushed a commit to plotarmordev/TensorFold that referenced this pull request Nov 21, 2026
…eir selftests and timings

The net change of ashhart#3733 at 5855d56 over its merge base 6d0a128, as one commit: the branch's merge commits hold changes of their own.
@ashhart
ashhart force-pushed the feat/70-upstream-pr-minimax-h3-image-spark-speed branch from 5855d56 to 8c4435d Compare November 21, 2026 02:35
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev. The CUDA prompt and image-decoder tools still add real functionality over main, and the updated limits output answers our earlier record question. Main has since gained H3's Metal side, so this branch now overlaps it and conflicts in ten paths.

Before we can review it for landing:

  1. Rebase to the CUDA files and the shared helpers they need. Drop the copies of what main already has, keep main's H3 changes, keep CUDA's picture.startRows and its test, and keep one h3_image_prompt.zig exposing the rope() both prompt tools use.
  2. Remove zig/src/core/h3_core.zig and its separate wiring in zig/build/h3_host.zig; use core/root.zig, with picture, picture_writer and resample owned there.
  3. The contract factories register no planted control for any of the 19 new kernels (contract_h3_image_decoder.zig, contract_h3_image_prompt.zig). Please add one per kernel, each with the gate it must fail, and show them red. The global control count can't show these.
  4. Run one existing H3 clip checkpoint on main and on the integrated head and post identical velocities, or say concretely why that comparison can't be run.
  5. Then post green CI on the integrated head, refreshed CUDA selftests, and the full kernel contract (gates, controls and limits) on GB10 with no stale H3 records.
  • Synthena

@ashhart
ashhart force-pushed the feat/70-upstream-pr-minimax-h3-image-spark-speed branch from 8c4435d to 096c2f4 Compare November 22, 2026 00:43
ashhart pushed a commit to plotarmordev/TensorFold that referenced this pull request Nov 22, 2026
…eir selftests and timings

The net change of ashhart#3733 at 5855d56 over its merge base 6d0a128, as one commit: the branch's merge commits hold changes of their own.
@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the new 096c2f46 head against main 25586070b. The trial merge now applies cleanly. On M5 Max with Zig 0.17.0, all 96 host checks passed, and both Linux ARM64 CUDA tools compiled in 11/11 steps:

zig build test-h3-image-prompt test-h3-image-prompt-host test-h3-image-decoder-host test-h3-geometry -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary all
zig build tf-h3-image-prompt-cuda tf-h3-image-decoder-cuda -Dtarget=aarch64-linux-gnu -Dcpu=baseline -Doptimize=ReleaseSafe -j3 --summary all

The merged diff still carries core/h3_core.zig and the Metal image recipe and kernels. In contract_h3_register.zig, the new decoder and prompt loops only append the production kernels. There are still no per-kernel planted controls there. This clears the apply and build checks. The shared-core and control work, GB10 selftests, and clip velocity comparison remain open.

Igor Lessio - AIFLOW LABS

@plotarmordev

Copy link
Copy Markdown
Contributor Author

Merged current main into the branch in 6e0c1f3 (a merge commit; I don't rebase or force-push this branch).

  1. Scope: main's copy wins every overlapping file: the Metal image tools and kernels, docs/recipes/minimax-h3-image-metal.md, h3_image_prompt.zig, and the h3_image* tests. Main's h3_image_prompt.zig stays as it is. Both prompt tools now take rope from core.qwen_vl.rope, so no second rope() builder is needed. The diff against main now holds only the CUDA prompt and decoder, their CPU reference tools, contract files and receipts, and the helpers they share. Those helpers are the decoder's weights/read/synthetic, which now exist once in image_decoder.zig, with Metal calling them too; prompt_reference's Scratch/encodeLayer; and span read-ahead.
  2. I removed zig/src/core/h3_core.zig and its wiring in h3_host.zig. Every H3 tool now builds against core/root.zig, which owns picture and the resampler. picture_writer imports core, and checkpoint_fixture comes from core too.

Checked at this head: macOS host checks pass (test-h3-image-prompt, test-h3-image-prompt-host, test-h3-image-decoder-host, test-h3-geometry, test-h3-read-ahead, compile-h3-*, test-contract-images-host: 35/35 steps). The four H3 image tools and compile-cuda-contract-consumers cross-compile for aarch64-linux.

Asks 3 to 5 are still to come. Those are planted controls for the 19 kernels, the clip-velocity comparison against main, and the GB10 selftests, contract and CI results. I'll post them when they've run.

@plotarmordev

Copy link
Copy Markdown
Contributor Author

Follow-up on asks 3-5 (1 and 2 are in my previous comment). Head 1ceaab3de is pushed normally, with no force-push or rebase, and merges cleanly with main at a6cde902d.

3. Planted controls. contract_h3_register.zig now registers every decoder and prompt rig twice. The second copy has planted = true, which cuts the launch to its first block, so the output past that block keeps its 0xff poison or misses its update. Each copy is registered with .control = .shapes under the name <kernel> control: first block only. That gives 24 controls: all 19 symbols, plus the extra modes of h3d_finish, h3p_norm, h3p_heads, h3p_attention and h3p_glu. On a GB10 (sm_121), tf-cuda-test kernel-contract h3 gives:

(filtered) SUMMARY 34 kernels: 34 pass gates 1-4, 0 fail, 0 known findings; 24 controls: 24 red as planted, 0 missed; 0 limit problems

Each control fails gate 3, for example h3d_swiglu control: first block only: at 8x4096x8192 output 32 is -nan and h3p_scatter_add control: ... output 0 is -5.94e-1 where float64 gives 3.75e-1: 661.32 of its bound.

4. Clip velocities. I can't run this here. The only clip-velocity tool is tf-h3-dit, which is Metal-only and needs a FastH3 video transformer plus a case.safetensors exported with h3_case.py, which lives on the fork. I don't have that checkpoint or a case on either the Mac or the Spark. Against main, the merged diff no longer touches h3.zig or geometry.zig. In checkpoint.zig, Checkpoint.open maps the same bytes with the same flags. The only change on that path is that the fd stays open until deinit (closed there and on error), and evict/at/floats/Shards are new methods that the clip path doesn't call. The h3_checkpoint host test passes.

5. Same run on the GB10. The job script was committed on top of 1ceaab3de on a side branch, not in this PR. Results:

  • tf-h3-image-decoder-cuda selftest: selftest: pass
  • tf-h3-image-prompt-cuda selftest: PASS every gate
  • kernel-contract-limits over sm_80/86/89/120/121 exits 1 with 105 stale-record lines, and none is h3d_*, h3p_* or h3_image (every h3_image record prints record current). The stale ones belong to drama3, exl3, flashnext, GLM, muse, nemo_audio, qmm and qwen35, all inherited from main. The 10 limits controls are red.

CI at 1ceaab3de is queued and needs a maintainer's approval to run for a fork. The earlier red runs were on 096c2f46, before the merge.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @plotarmordev. The code asks are met, and we'll handle the rebase. One small thing blocks our push check: line 26 of docs/receipts/h3-image-cuda-gb10-0bfee52e/asks-3-5.md quotes a local path from your machine. Could you reword that line without the path?

  • Synthena

ashhart pushed a commit to plotarmordev/TensorFold that referenced this pull request Nov 24, 2026
…eir selftests and timings

The net change of ashhart#3733 at 5855d56 over its merge base 6d0a128, as one commit: the branch's merge commits hold changes of their own.
@ashhart
ashhart force-pushed the feat/70-upstream-pr-minimax-h3-image-spark-speed branch from 2f5e1ca to c433b79 Compare November 24, 2026 13:23
plotarmordev and others added 12 commits November 24, 2026 18:05
…eir selftests and timings

The net change of ashhart#3733 at 5855d56 over its merge base 6d0a128, as one commit: the branch's merge commits hold changes of their own.
… decoder on core/root.zig

Main's Metal image tools, recipe, h3_image_prompt.zig and tests win every add/add conflict.
The separate h3_core module is gone: every H3 tool takes core/root.zig, which owns picture,
picture_writer's resample and qwen_vl.rope; checkpoint_fixture comes from core too.
The decoder's weights/read/synthetic helpers live once in image_decoder.zig, shared by
Metal, CPU and CUDA. Unused qwen_copy.zig, h3_image_metal.zig and Tensors.span dropped.
The full GB10 contract never finishes on TOP: moss's tf_md_conv3x3 float64 shapes reference runs past 75 min.
kernel-contract -tf_md_conv3x3 runs every other kernel's gates and controls, the back and after suites and every
limit record.
@ashhart
ashhart force-pushed the feat/70-upstream-pr-minimax-h3-image-spark-speed branch from c433b79 to 87fa691 Compare November 24, 2026 18:05
@ashhart
ashhart merged commit fb6591d into ashhart:main Nov 24, 2026
1 check passed
ashhart pushed a commit that referenced this pull request Nov 24, 2026
…eir selftests and timings

The net change of #3733 at 5855d56 over its merge base 6d0a128, as one commit: the branch's merge commits hold changes of their own.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
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.

ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
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