Skip to content

MiniMax H3 on Metal: Ref2VA, video and audio from reference pictures, videos and sound - #961

Closed
drowzeys wants to merge 6 commits into
ashhart:mainfrom
drowzeys:upstream/h3-ref2va
Closed

drowzeys wants to merge 6 commits into
ashhart:mainfrom
drowzeys:upstream/h3-ref2va

Conversation

@drowzeys

Copy link
Copy Markdown
Contributor

Stacked on upstream/h3-revoice (#960), then upstream/h3-steps (#959), upstream/h3-firstframe (#950) and upstream/h3-metal (#949). Review those first.

Reference-driven video and audio generation (Ref2VA) now runs on TensorFold's Metal runtime. MiniMax-H3's Ref2VA model makes a clip from a prompt plus reference pictures, videos and audio clips. Here, a picture of a fox and a soundtrack: "the fox from <Picture 1> trots through deep snow…, the soundtrack follows <Audio 1>".

  • The references are packed ahead of the clip and attended by every row.
  • Reference pictures and videos are held at the keyframe level.
  • Reference audio is clean and pinned at timestep 1.
  • None of them is ever stepped.

This is the model behind the Studio's Ref2VA shots. It needs the pieces of the stack below it: keyframe rows (#950), the native schedule and the released weights' layout. It adds one count to the case and one rule to the sampler step.

On the Mac Studio (M5 Ultra), 864x480 with 124 frames, the case has 16,673 rows: 455 text (the prompt and the references' vision tokens), 405 reference-picture rows, 828 audio (414 of them reference audio), 14,985 video, in 308 tiles. Results:

  • Parity on real steps against the MLX reference.
    • Step 16 of 30: video velocity cosine 0.99977 (relative error 0.022); the clip's audio cosine 0.99995 (relative error 0.010).
    • Step 1: video 0.99964, the clip's audio 0.99992.
  • A full 30-step run renders the reference's fox in the snow, consistent across the clip, with sound (decoded RMS 0.018), judged by eye.
  • Speed: 16.9 s a step (median of 30) against 14.8 s for MLX's bf16 forward with fused dense attention on the same Mac. The dense-attention kernel is the gap, as in upstream/h3-revoice (MiniMax H3 on Metal: the released MiniMax-H3 weights, and re-voicing a finished clip #960).
  • Memory: 4.8 GB peak process footprint, plus the 42 GB checkpoint mapped read-only in place.
  • Kernel contract on this tree (the whole stack): SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 2 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems, and PASS limits: 93 registered Metal launches against M1-M5, 0 problems. The 2 known findings are main's affine_mm.
  • Host suite: 206/206 steps, 2994 of 3004 tests passed, 10 skipped. main gives 204/204 and 2989 of 2999 with the same 10 skips; the 5 new tests are the schedule's. Lean check: 517, with 0 added.

What it adds

  • h3.zig: the case geometry's eighth count, the reference audio rows at the front of the audio. modulation.zig: passes that count to the plan, which pins those rows at timestep 1.
  • The tool:
    • Its Euler step moves only the generated audio rows.
    • steps=N on the released weights makes their own grid of N + 1 points (video shift 12, audio shift 3).
  • The released Ref2VA transformer loads with upstream/h3-revoice (MiniMax H3 on Metal: the released MiniMax-H3 weights, and re-voicing a finished clip #960)'s loader, unchanged.
  • The case exporter, h3_ref2va_case.py on the fork's exporter branch (h3-case-tools):
    • It reads and encodes the references the way the Studio does.
    • It packs them with the Python family's packing.reference_layout.
    • It reorders every per-row table into the engine's order: [text | reference video | audio, reference audio first | video].
    • Attention does not depend on row order once each row keeps its position, modality and tile.
    • It is not part of this change.

Receipts

Released checkpoint MiniMaxAI/MiniMax-H3, Ref2VA transformer, 13 shards.

Check Video velocity The clip's audio velocity
Step 1, the case's tables cosine 0.99964, rel. error 0.027 cosine 0.99992, rel. error 0.013
Step 1, tables made here (steps=30) cosine 0.99952, rel. error 0.032 cosine 0.99961, rel. error 0.030
Step 16, the case's tables cosine 0.99977, rel. error 0.022 cosine 0.99995, rel. error 0.010
Step 16, tables made here cosine 0.99971, rel. error 0.024 cosine 0.99995, rel. error 0.011
Step 16, the two native runs against each other cosine 0.99976, rel. error 0.022

The reference audio rows' own velocities match less well. Those rows alone are at cosine 0.976 at step 1. All audio rows together are at 0.996 at step 1 and 0.993 at step 16. These velocities are discarded, because those rows are never stepped. Their part in every other row's attention is what the clip's rows above measure.

zig-out/bin/tf-h3-dit <MiniMax-H3>/Ref2VA/transformer 13 ref-at0/case.safetensors out
zig-out/bin/tf-h3-dit <MiniMax-H3>/Ref2VA/transformer 13 ref-at15/case.safetensors out steps=30,from=15,once
zig build tf-kernel-contract -Dcpu=apple_m1 -Doptimize=ReleaseFast && zig-out/bin/tf-kernel-contract --offline DIR
zig build test -Dcpu=apple_m1

Next steps

  • Reference videos with their own soundtrack, and several references at once. The exporter and engine handle them, since the row counts are general, but this receipt has one picture and one audio clip.
  • A dense-attention kernel, to close the 2 s a step against MLX.
  • The reference encoders (video VAE encoder, audio VAE encoder, vision tower) in Zig. Today the exporter runs them in Python.

Licenses

The code is Apache-2.0. MiniMax H3 weights are under the MiniMax H3 Community License. No weights are included.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PfjmufXm4L7qsVNFyRw9ZK

@ashhart

ashhart commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Thank you, @drowzeys, the held-reference audio and schedule rules give the Metal H3 stack a useful shared-family endpoint.

We checked 25599e2. h3.zig:158-171 reads six geometry counts without first requiring six, and held_audio can exceed audio before h3_dit.zig slices it. We can add count/range/product checks and negative fixtures at landing.

We will carry the Metal stages with the bf16 CUDA component into one H3 family, preserving M5-only qualification until other hardware runs. Native conditioning/reference encoders, latent decoders and synchronized media output follow the denoiser/schedule pieces. Please retain identical-step and held-audio/reference fixtures for the combined pipeline; raw latent rows and external exporter results remain distinct from a complete native clip.

Posted by Ash's AI Assistant Synthena

@ashhart ashhart mentioned this pull request Oct 17, 2026
…de the engine

A video and audio model's denoising transformer on the M5 tensor units, in the checkpoint's precision: bf16
weights read in place, products on the prefill kernels' tfp::gemm_nax (MLX's GEMM, fp32 sums), FastH3's
tile-routed attention in bf16 with fp32 scores and an online softmax. zig build tf-h3-dit runs every denoising
forward for a case file. The lane core, the server and the other families are untouched.

Thirteen kernels are registered with the kernel contract and pass gates 1-4; their launches and the two GEMM
entry points are in registry.zig. The recipe holds the receipt.
A case exported with a first frame holds the keyframe's rows between the text and the audio. They enter like video
rows on every pass at the keyframe noise level and are never stepped. Text to video is bit-identical to before.
…aLN tables made here

The rungs, shifts and per-row timestep plan come from the checkpoint's contract (or N rungs spread from its first);
the timestep embedder runs on the host and each block's AdaLN projection on the GPU (h3_modulation, registered with
the kernel contract), so a case no longer fixes the step count.
…a finished picture

Loads the released checkpoint's layout (model-* shards, each head's fused [q, k, v] rows, [gate; value] SwiGLU rows,
dense attention without routing gates, its embedder and AdaLN names). revoice=N holds every row but the generated
audio at the keyframe level and takes the audio down the released model's grid, as the Python sampler's revoice does.
h3_heads takes a row-head stride and h3_swiglu a gate-first flag; both are covered by the kernel contract.
A Ref2VA case holds the references' video rows as keyframe rows and their clean audio ahead of the clip's audio; the
geometry's eighth count marks those reference audio rows, which are pinned at timestep 1 and never stepped. steps=N
on the released weights makes their own grid.
@drowzeys

Copy link
Copy Markdown
Contributor Author

Rebased on main 6ee828c2 with the rest of the H3 Metal stack; head 25599e2f is now 50cb1341. The pull request's diff against main is patch-identical to before (main's new commits only touch docs); zig fmt --check clean on the changed Zig files; python3 tools/zig/lean_check.py reports no new findings against main.

…g them

Model.load read geometry[0..5] whatever the tensor's length and cast each i32
count to usize, and a Ref2VA case's held_audio could exceed its audio rows
before h3_dit.zig sliced audio[held..]. schedule.geometry() now takes the
counts first: fewer than six is error.ShortGeometry, more than eight or a
negative count error.BadGeometry, and more held audio rows than audio rows
error.HeldAudioTooLong. h3_dit.zig also refuses a held span past its audio
before slicing. Host test in schedule.zig (zig build test).
@drowzeys

Copy link
Copy Markdown
Contributor Author

Thank you. Both points are fixed in 2116a88a, on top of the stack's head; nothing below it changes.

  • Six geometry counts (h3.zig:158-171): Model.load now passes the case's counts to a new schedule.geometry() before using any of them:
    • fewer than six counts is error.ShortGeometry;
    • more than eight, or a negative count, is error.BadGeometry;
    • nothing is cast from i32 until every count has been checked.
  • held_audio > audio: schedule.geometry() refuses more held reference audio rows than audio rows with error.HeldAudioTooLong. h3_dit.zig also checks the held span against its audio buffer, with the same error, before slicing audio[held..].

Test: the case's geometry: six to eight counts, none negative, held audio within the audio in schedule.zig, a host test that runs in zig build test. It covers an empty geometry, five counts, nine counts, negative counts, held audio one row past the audio, held audio with no audio, and the equal-length edge case, which is allowed.

Checks on the M5 Ultra:

Check Result
zig fmt --check build.zig zig clean
lean_check 517, the same as main
zig build test -Dcpu=apple_m1 206/206 steps
tf-h3-dit builds

These are build and host tests only; I didn't do a device run. The identical-step fixtures and the held-audio and reference fixtures are all kept.

@ashhart

ashhart commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Thanks @drowzeys for checking all six-to-eight counts before casting and refusing held audio beyond the audio span. The equal-length case and malformed geometry controls are the right boundaries.

Our Metal component integration retains those checks and the held-reference schedule, with the later geometry review repairs. The reported host steps and harness build are not a device rerun. Identical-step, held-audio and reference fixtures still need to pass on the final integrated source, alongside numerical/resource checks. The native block and schedule work remains distinct from the encoders, tower and decoders needed for complete native media serving.

Posted by Ash's AI Assistant Synthena

ashhart added a commit that referenced this pull request Oct 18, 2026
… beneath it

The H3 and FastH3 transformer on Metal as a test tool beside the release's, clips that start from an image, any step
count with its schedule and AdaLN tables, the released MiniMax-H3 weights with re-voicing of a finished clip, and
Ref2VA's reference pictures, videos and audio. Against this branch: build.zig runs the H3 schedule's host tests
beside the XPU admission tests.
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thank you, @drowzeys, for H3/FastH3 on Metal. 1.1.0 consolidates #949, #950, #959 and #960 through #961 (013b75368) in one family. The bf16 tf-h3-dit test tool handles text/image-conditioned clips, schedules, re-voicing and Ref2VA reference media with family-owned kernels. Geometry, media ranges, checkpoint shapes and scratch sizes are checked before launch. Schedule tables are replaced together only after successful completion. Numerical/resource, media fidelity and schedule results: Apple M5 Ultra H3 kernels passed 15/15 with controls; full FastH3/H3 checkpoint/media-tool cells remain unrun.

Posted by Ash's AI Assistant Synthena

@ashhart

ashhart commented Oct 19, 2026

Copy link
Copy Markdown
Owner

The bf16 H3 Metal component shipped in 1.1.0 as 013b75368; thanks @drowzeys. We're closing it as landed.

Posted by Ash's AI Assistant Synthena

@ashhart ashhart closed this Oct 19, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…hart#950, ashhart#959 and ashhart#960 beneath it

The H3 and FastH3 transformer on Metal as a test tool beside the release's, clips that start from an image, any step
count with its schedule and AdaLN tables, the released MiniMax-H3 weights with re-voicing of a finished clip, and
Ref2VA's reference pictures, videos and audio. Against this branch: build.zig runs the H3 schedule's host tests
beside the XPU admission tests.
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