Skip to content

h3: MiniMax-H3-Image's prompt path on Metal: Qwen3-VL to layer 50 and the token refiner (tf-h3-image-prompt) - #2779

Closed
ashhart wants to merge 4 commits into
mainfrom
lead/h3-image-prompt
Closed

ashhart wants to merge 4 commits into
mainfrom
lead/h3-image-prompt

Conversation

@ashhart

@ashhart ashhart commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

What this changes

MiniMax-H3-Image's prompt path runs on Metal. Before, tf-h3-image could take its prompt rows only from a reference pipeline's case. After, tf-h3-image-prompt makes them from the prompt itself:

  1. The prompt is tokenised verbatim.
  2. Qwen3-VL's text model runs 50 of its 64 layers, and the unnormalised rows leaving layer index 49 are kept.
  3. The transformer's condition_proj, its two token-refiner blocks and final_norm follow.

The tool writes text and text_tags in the picture case's format. Everything runs on any Apple GPU, with no tensor units needed.

Checks on this head

  • Head commit: 0fa460a1c6. The checks below were rerun after the rebase onto h3: MiniMax-H3-Image's edit encoder on Metal in fp32 (tf-h3-image-encoder) #2778: 13 of 13 steps and 70 tests.

  • Lean checker: 386 on the base and 386 on this head, 0 new. tools/pr_check.py: 0 errors (the one advisory warning is the Unreleased line, which the lead adds).

  • Tests run, with the command and pass, fail and skip counts:

    • zig build test-h3-geometry test-h3-image-prompt compile-h3-host compile-h3-image-prompt test-picture-host --summary all: 14 of 14 steps. test-h3-image-prompt has 13 tests, and is part of zig build test.
    • Each rule was broken in turn, and each failed its test.
    • zig fmt --check and git diff --check: clean.
  • tf-h3-image-prompt selftest on an M3 Ultra: a synthetic checkpoint loaded as a real run loads one, checked against a float64 host reference.

    Check Gate Measured
    Each kernel alone (11) ≥ 99.9% bit-equal 99.97-100%
    Text encoder rows, text cosine ≥ 0.999 and within 2x the fp32-sum host run's distance cosine 0.9999984, rel 1.82e-3 (host run 2.50e-3)
    Encoder with vision and DeepStack rows at M-RoPE positions as above cosine 0.9999941, rel 3.44e-3 (host run 3.42e-3)
    condition_proj, refiner, final norm as above cosine 0.9999884, rel 4.81e-3 (host run 4.66e-3)
    Second run byte-identical byte-identical

    The whole-run gate changed after a run. It was first cosine ≥ 0.99999 and relative error ≤ 0.005, and the refiner missed it on a second seed while every kernel alone was bit-exact. It is now "no further from float64 than twice a float32-sum host run", the form MOSS-Image's gates use. Please review that change.

  • CI: will run on this head.

  • Not run, and why: real weights. Their download is on hold.

Receipt

  • Main against branch: n/a. This is a tool beside the engine; no token path changes.
  • Boxes it reaches: Metal on any Apple GPU, through tf-h3-image-prompt.
  • New switch? None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: a87931041b, Zig 0.17.0, an M3 Ultra under macOS. Configs from MiniMaxAI/MiniMax-H3-Image at 492fd8c4ec and MiniMax-H3's text_encoder/config.json.
  • Paths and platforms the change reaches, which I ran and which I could not: Metal (ran on an M3 Ultra). No CUDA.
  • Exactness, decode and prompt speed: n/a.
  • Licence of any new weights or drafter: n/a, no weights.
Kernel contract
  • The kernels are new and runtime-compiled for this tool; none replaces an engine kernel. They are gated by tf-h3-image-prompt selftest against a float64 reference, not yet registered with tf-kernel-contract.

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: this makes a denoiser's prompt rows, beside the engine.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto today's main, on #2778's new head, so the stack's CI runs on one base (head 28067fa169). CI on the old head 0fa460a1c6 was green.

On the new head these pass: test-h3-geometry, test-h3-image-prompt (13 passed), test-picture-host (26 passed, 6 skipped: main's two new JPEG tests and the usual four), compile-h3-host, compile-h3-image-encoder and compile-h3-image-prompt.

On the whole-run gate that changed after a run: the new form is sound. The selftest keeps a floor of cosine 0.999, and a run must sit no further from float64 than twice a float32-sum host run. That bound follows the reduction order's own noise, which a fixed 0.99999 did not. MOSS-Image's gates use the same form.

One fix for this PR's kernel sits higher in the stack. In zig/kernels/metal/h3/h3_prompt.metal:177, a padded slot gets weight zero but still reads the last real key's value row. If that value is infinite, 0 times infinity turns the output into NaN where it should stay infinite. #2808 (f910fef300) skips padded slots there, so the stack should land through #2808 for that.

What's left:

  1. h3: MiniMax-H3-Image's transformer on Metal from a picture case (tf-h3-image) #2766, h3: MiniMax-H3-Image's VAE rules on the host, and Pillow's Lanczos-3 in core/picture #2775 and h3: MiniMax-H3-Image's edit encoder on Metal in fp32 (tf-h3-image-encoder) #2778 land first, in that order.
  2. With the weights: the prompt rows on a real prompt against the reference pipeline's. Their download is still on hold.
  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/h3-image-prompt branch from 0fa460a to 28067fa Compare November 12, 2026 14:29
@ashhart
ashhart force-pushed the lead/h3-image-prompt branch from 28067fa to b538cc1 Compare November 18, 2026 15:17
ashhart added a commit to plotarmordev/TensorFold that referenced this pull request Nov 20, 2026
 does

The macOS dev-tools job failed to compile tf-h3-image-encoder: "file exists in modules 'picture_codec' and 'core'".
The tool's encoder imports core, whose root has imported picture/picture.zig since eb43e2b, and the tool also
built a picture_codec module rooted at that file. The tool now imports that same core and reads core.picture: the
picture half of ashhart#2779's "the edit encoder, its reference rules and its tool read safetensors and pictures through
core", which this stack's older copy of the encoder commit lacks.
ashhart added a commit to plotarmordev/TensorFold that referenced this pull request Nov 21, 2026
 does

The macOS dev-tools job failed to compile tf-h3-image-encoder: "file exists in modules 'picture_codec' and 'core'".
The tool's encoder imports core, whose root has imported picture/picture.zig since eb43e2b, and the tool also
built a picture_codec module rooted at that file. The tool now imports that same core and reads core.picture: the
picture half of ashhart#2779's "the edit encoder, its reference rules and its tool read safetensors and pictures through
core", which this stack's older copy of the encoder commit lacks.
@ashhart
ashhart force-pushed the lead/h3-image-prompt branch from b538cc1 to a105e8f Compare November 21, 2026 11:11
Each text segment is tokenised on its own and cut to 4,096 tokens; references enter as a label and a vision
block whose rows are tagged 0. Positions follow Qwen-VL's M-RoPE, and the rotary table rounds to bf16. The Qwen
copy of a reference keeps or scales its short edge to 1,024 with Pillow's LANCZOS. The text encoder's and the
refiner's configs are checked at the released geometry.
tf-h3-image-prompt turns a prompt into the text rows tf-h3-image reads: Qwen3-VL's text model to the hidden
state leaving layer index 49, then condition_proj, the two token-refiner blocks over every row and the final
norm. Weights are bf16 read in place; products run in simdgroup matrices with fp32 sums, so chips without
tensor units run it too. The encoder also takes a reference's vision rows and DeepStack features at their image
pads, ready for the edit's tower.

Its selftest writes a tiny synthetic checkpoint, loads it as a real run does, and gates each kernel alone and
each whole run against a float64 host reference with the same bf16 rounding points.
… its fixture through core, as main does

prompt.zig pulls in tensors.zig, which on main reads core.safetensors, so the tool's prompt module imports core. A file
may sit in one module of a build only, and core already holds picture.zig, qwen_vl/rope.zig and checkpoint_fixture.zig,
so picture_prompt.zig, its test and the tool read them through core, and the build's own picture, rope and fixture
modules go. test-h3-image-prompt's root imports core in their place.
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Closing this one: all of its work is on main, some of it moved or renamed since this branch was cut, so nothing is left to merge.

  • Synthena

@ashhart ashhart closed this Nov 23, 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.

1 participant