Skip to content

kernel contract: MiniMax-H3-Image's 19 Metal kernels, 31 registrations and 34 planted controls; the prompt path's attention keeps an infinite last value - #2808

Merged
ashhart merged 12 commits into
mainfrom
lead/h3-image-contract
Nov 24, 2026
Merged

ashhart merged 12 commits into
mainfrom
lead/h3-image-contract

Conversation

@ashhart

@ashhart ashhart commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

What this changes

MiniMax-H3-Image's 19 Metal kernels now register with the kernel contract, so they meet the rule every GPU kernel meets before it lands. Before, they were gated only by each tool's own selftest. After:

  • The edit encoder (h3_image_encoder.metal, fp32 with precise functions). Four kernels in eight registrations, with nine controls:
    • the convolution at every layer geometry of the released encoder: 3x3, 3x3 adding its residual in place, 3x3 downsampling, and 1x1;
    • GroupNorm's partial sums, plain and centred, and their finish;
    • the norm's SiLU.
  • The prompt path (h3_prompt.metal). Seven kernels in fourteen registrations, with fifteen controls:
    • the bf16 product at every projection of Qwen3-VL to layer 50 and of the token refiner, with and without a bias;
    • both norms and both head layouts, in the Qwen and H3 rounding orders;
    • causal and full attention, within attention_range's bound;
    • both gates, the residual add, and the vision rows' scatter.
  • The image decoder (image_decoder.metal, bf16). Eight kernels in nine registrations, with ten controls:
    • post_quant, and the embedding with its registers;
    • both norms;
    • the product, plain and with LayerScale in place;
    • the heads with their half-width rotary;
    • attention over a 261-token tile and over a batch of 16 tiles;
    • SwiGLU.

Each output is checked against float64 at the kernel's own rounding points. Gate 4 uses integer stress inputs wherever a kernel sums. Every control is a one-place edit of the source that a named gate must catch.

Other changes:

Checks on this head

  • Head commit: 8e31db2282.
  • Lean checker: 386 on the base and 386 on this head, 0 new. tools/pr_check.py --base lead/h3-image-t2i: 0 errors. Its one advisory warning is the Unreleased line, which the lead adds.
  • Tests run, with the command and pass, fail and skip counts:
    • tf-h3-image-contract on an M3 Ultra: H3_IMAGE_SUMMARY 31 kernels: 31 pass gates 1-4, 0 fail, 0 known findings; 34 controls: 34 red as planted, 0 missed; 0 limit problems.
    • zig build test-kernel-contract: exit 0. The records' family test is included.
    • zig build test-metal-launch-map-host: 719 registered launches (700 before), 0 missing.
    • tf-h3-image-prompt selftest after the attention fix: every gate passes, with the same numbers as before.
    • tf-h3-image-decoder selftest after the four thread attributes: every gate passes.
    • zig fmt --check: clean.
  • CI: will run on this head.
  • Not run, and why:
    • tf-kernel-contract itself: this Mac has no offline Metal compiler. The suites import only metal, contract, rig.zig and the three kernel-source modules, which its build now provides.
    • The M1/M2 --offline compiles: every launch reserves its threads in its source instead.
    • An M5: these kernels use no tensor units.

Owed device cells

  • zig build kernel-contract -Dcpu=apple_m1 on a Mac with Xcode's Metal toolchain, to run the full runner with these suites. Any chip will do.

Receipt

  • Main against branch: n/a. These are kernel tests and one attention fix in a tool beside the engine. No token path changes.
  • Boxes it reaches: Metal, on any Apple GPU.
  • New switch? None. New build steps: tf-h3-image-contract and h3-image-contract.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: 8e31db2282, Zig 0.17.0, macOS on an M3 Ultra. No checkpoint: synthetic inputs.
  • Paths and platforms the change reaches, which I ran and which I could not: the source-only runner and the host tests ran; the full Metal runner did not.
  • Exactness, decode and prompt speed: n/a. The attention fix keeps every finite output's bytes.
  • Licence of any new weights or drafter: n/a, no weights.

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. Each kernel's planted control goes red at its gate. The padding control fails the old attention.
  • 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 for a denoiser beside the engine.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

/atc exchange 0331ecd2ba125a05807e7fe49d5e94936ceafe7013e5437501c00df501c42894

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Status on this head (8e31db2282): CI is green, and it merges cleanly with today's main.

…load's io, and H3's Metal tools in h3_metal.zig

Main moved H3's safetensors import into the core module (h3_core in metal_targets.zig, core in h3_host.zig). This
series came from before that move: tf-h3-image imported safetensors and checkpoint_fixture modules of their own. It
now imports core and reads both from it, since a file may sit in one module of a build only and core holds both.
Main's h3.Model.load also takes the process's io now, so tf-h3-image passes init.io as tf-h3-dit does.

Main's metal_targets.zig is at the 600-line cap, so tf-h3-image's target, and main's tf-h3-dit beside it, move to
h3_metal.zig with the H3 modules they share (and the kernel sources they take); metal_targets.zig calls it in one
line (589 lines). The steps and their modules are otherwise unchanged.
…trations and ten planted controls; four kernels reserve their group sizes
…istrations and fourteen planted controls; hp_attention's padded last key is a known finding
…infinite last value stays infinite; its contract entries lose their known finding and gain a control
Format only: combine the existing mixed-kernel predicates after main filled the runner. The short-circuit and append behavior are unchanged.
@ashhart
ashhart force-pushed the lead/h3-image-contract branch from 7c83c8b to d19fc5c Compare November 24, 2026 12:36
@ashhart
ashhart merged commit fa2358c into main Nov 24, 2026
1 check failed
@ashhart
ashhart deleted the lead/h3-image-contract branch November 24, 2026 12:36
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