Skip to content

Studio MiniMax-H3 video: ship the reference implementation's defaults - #17802

Merged
danielhanchen merged 19 commits into
mainfrom
studio-h3-video-reference-defaults
Nov 15, 2026
Merged

danielhanchen merged 19 commits into
mainfrom
studio-h3-video-reference-defaults

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Summary

MiniMax-H3 video on the Diffusers engine now ships the reference implementation's defaults. #17764 matched the recipe (sampler, sigma grid, noise, media handling); this PR flips the divergences it kept on purpose, plus the ones found while checking the reference's pinned workflow templates and the kernels it runs on GPU.

default before after switch to the old behaviour
q/k RMSNorm + RoPE rotation diffusers chain: each product and the sum rounded to bf16 the reference kernel's float32 fma, rounded once UNSLOTH_H3_QK_ROPE_ROUNDING=eager
8-bit quantisation of decoded reference frames rounded truncated, as the reference LANCZOS helper (astype(uint8)) none
output frames round(x * 255) (x * 255).clamp(0, 255).byte() truncation, as the reference save none
dense time embedding float32 up to the AdaLN SiLU rounded to the compute dtype before the SiLU, as the reference none
condition latents (keyframes, reference images and videos) posterior sampled under seed 42, rounded to float16 posterior mean in float32, as the reference encode UNSLOTH_H3_REFERENCE_LATENT=sample
keyframe canvas without a size matched to the keyframe's aspect the reference node's 1344x768 (first frame stretched, last centre-cropped) send width / height, or pick "Match source"
page: keyframe upload switched the size to "Match source" keeps the chosen size; "Match source" is explicit and sends the matched size pick "Match source"
page size 1344x768 preset; a fresh page rendered 800x544 864x480 (the t2v and r2v templates' 0.4 MP 16:9) from the first render pick a preset
MP4 export libx264 CRF 23, BT.601 matrix, untagged, int16 AAC CRF 18, BT.709 matrix, tagged BT.709 / sRGB / limited, float AAC none

Unchanged because they already equal the reference: 20 steps, CFG 1, 124 frames, 24 fps, shifts 12 / 3, res_multistep + simple, the AdaLN curve, and the int8 ConvRot video decoder (the templates load an int8_convrot VAE; Studio's int8 and float16 decoders are equally close to it, 0.00087 vs 0.00086 LPIPS on the reference's own latent, so int8 stays and UNSLOTH_H3_VAE_INT8=0 gives float16). The denoiser file stays Studio's hosted INT8 ConvRot build: the templates' pruned int8_convrot file is no faster, needs 0.74 GiB more VRAM and 16.6 GiB more host RAM at load, and is not consistently closer to the reference render (closer on one t2va case, further on fl2va and on t2va with the reference's conditioning).

Speed levers that do not change what the reference computes stay on: compile, INT8 attention routing, the fused VAE kernels, the int8 decoder, tile batching, frame-threaded x264.

The request API keeps 1344x768 for a request without a size (the reference node's default). The page takes the templates' 864x480 for its first render; a size the user picked, or a stored recipe, is kept.

The text encoder default does not change: a request without text_encoder_quant still loads the hosted int8 ConvRot conditioner, exactly as on main. The reference templates' nvfp4_awq conditioner is not adopted: against the bf16 conditioner it is less accurate than the int8 one (per-token cosine 0.99744 vs 0.99990; video LPIPS vs a bf16-conditioner render 0.0876 vs 0.0325).

q/k-norm + RoPE

The reference CUDA kernel normalises, rounds the normed value to bf16, then rotates with fma(x1, f01, x0 * f00) in float32 and rounds once. Diffusers rounds each product and the sum. The video denoiser now uses the reference's rotation in the same Triton kernel (the device check compares it bit for bit against an exact emulation before engaging). On H3's shape (41,811 tokens x 24 heads x 128, rotary 96) against the reference kernel on a G4:

elements that differ max abs kernel
before 23.0% 0.0625 0.390 ms
after 0.0013% 0.0156 0.388 ms

The rest comes from the RMS sum order. The image pipeline keeps the eager rounding.

Measurements

Colab G4 (RTX PRO 6000 Blackwell) unless noted, Studio defaults otherwise (hosted INT8 denoiser, compiled), 1344x768x124, 20 steps. Every arm ran in a fresh process. The reference renders come from the reference implementation at eee5918 with exactly the files its templates load; they are bit-identical across two VMs, as are Studio's. LPIPS is AlexNet on every 4th frame.

LPIPS to the reference render of the same seed, main against this PR (the int8 conditioner on both sides). Two G4 VMs ran both sides in fresh processes, and every main/main and PR/PR pair across them is bit-identical, so the differences below are the change, not noise.

job seed 4242 seed 11 seed 777 mean
t2va 0.119 -> 0.214 0.207 -> 0.229 0.253 -> 0.224 0.193 -> 0.222
fl2va 0.054 -> 0.028 0.086 -> 0.144 0.120 -> 0.115 0.087 -> 0.095
ref2va_long 0.361 -> 0.323 0.347 -> 0.299 0.483 -> 0.431 0.397 -> 0.351

ref2va_long, the job the condition-latent change targets, is closer on all 3 seeds, which is why the posterior mean stays. t2va has no condition latents: only the RoPE rounding and the output truncation touch it, and its trajectories are chaotic, so a kernel-level change that brings the RoPE within 0.0013% of the reference still moves a single render as much as any perturbation.

Speed and memory against main, same VM, fresh processes (VM a / VM b):

job wall s, main wall s, this PR peak GPU memory GiB, main / this PR
t2va 4242 / 11 / 777 161.73, 161.80, 161.73 / 160.88, 161.24, 161.18 161.54, 161.96, 161.88 / 161.32, 161.37, 161.29 60.06 / 60.06
fl2va 4242 / 11 / 777 194.63, 191.03, 191.03 / 194.87, 190.38, 190.42 195.69, 191.14, 191.13 / 194.08, 190.53, 190.52 60.06, 58.64 / same
ref2va_long 4242 / 11 / 777 309.41, 309.51, 309.48 / 308.20, 308.79, 308.36 309.63, 309.69, 309.73 / 308.61, 308.93, 308.74 62.83 / 62.84

The flips add +0.1 to +0.4 s per clip (at most 0.1%, on the edge of the 0.4 s same-arm spread on one VM; fl2va 4242 is the first fl2va of each VM, cold cuDNN autotune) and leave peak VRAM and the decode peaks unchanged.

Costs beyond noise:

  • CRF 18 export: +0.21 s per 124-frame clip (0.89 -> 1.10 s, CPU), and the file is twice the size. The reference's quality setting.
  • Non-16:9 keyframe without a size: renders the full 1344x768 canvas, as the reference node does.
  • RoPE where the Triton kernel does not run (ROCm, CPU, MPS): the single-rounding fallback is 13% slower than the eager chain for that op on CPU.

Evidence

  • CPU bit-parity against the reference's own code (scripts/h3_parity/ref_parity.py, default mode): 97/97 after (the original 59/59), 72/97 before. The 38 new checks cover the dense time embedding, the AdaLN curve, the condition posterior, output quantisation, the keyframe canvas, the template defaults and the MP4 export against the reference's own save (pictures 29.4 -> 51.8 dB PSNR, soundtrack bit-identical).
  • GPU probes: the RoPE table above; the exported MP4 carries tags (1, 13, 1, 1) on the GPU renders.
  • Unit tests: new tests/test_h3_reference_defaults.py, new cases in test_h3_ref_encode.py, test_video_encode.py, test_h3_qk_rope_exact.py and test_video_minimax_h3_attn.py (CUDA cases ran on G4 and A100). Tests that pinned the old behaviour were updated:
    • test_h3_reference_recipe.py: the 8-bit conversion expects truncation ([0, 1, 254], was [0, 2, 255]).
    • test_h3_ref_encode.py: the chunked-vs-stock tests run the explicit sample switch, because they compare against Diffusers' sampled encode.
    • test_video_backend.py: a portrait last frame without a size renders 1344x768.
    • test_video_stream_encode.py: the H3 stream is compared with the reference-profile export (CRF 18).
    • test_h3_qk_rope_exact.py: monkeypatched helpers take the new rounding argument.
    • Frontend video-start-frame-upload.test.ts: the 1:4 to 4:1 warning shows only where a keyframe would pick the canvas.
  • Neighbouring suites (every test_video_*, test_h3_* and test_openai_videos* file, CPU): the head failures are a subset of base's and all pre-existing in the CPU venv (the chunked-encode contiguity assertion on torch 2.14 and three ffmpeg-missing cases). Head merged with current main: 4864 passed, 7 failed; base: 4769 passed, 8 failed (its extra one is a timing flake that passes alone). Frontend: the touched node --test files pass, tsc and the Vite build pass.

Not covered

  • Vision tower precision: the reference runs the Qwen3-VL vision tower in float32 (bf16 weights cast up per op). Moving Studio's whole tower to float32 brought fl2va from 0.029 to 0.017 LPIPS and ref2va_long from 0.351 to 0.295 (seed 4242), but cost 1.2 to 1.7 GiB of peak VRAM and also widened the language model on vision prompts, so it is not in this PR. A vision-only per-op cast is the follow-up.
  • sd.cpp engine: unchanged, except that it shares the keyframe resolver, so a keyframe without a size renders 1344x768 there too.
  • Not proven:
    • the RMS sum order of the reference RoPE kernel (the remaining 0.0013%);
    • fl2va seed 11 was not bisected to a single change;
    • G4 and A100 only (no L4); the page change has helper and source tests, tsc, a build, and the browser screenshots below.

Screenshots

MiniMax-H3 on the Video page, using the status a loaded MiniMax-H3 pipeline reports (no weights are loaded for the screenshot). A fresh render now opens at 864 x 480, the reference workflow's default (800 x 544 before):

MiniMax-H3 default size, before and after

Uploading a start frame no longer switches the size to Match source; the chosen 864 x 480 is kept:

MiniMax-H3 size after a start frame upload, before and after

Flip the defaults the reference-recipe work kept on the Diffusers engine, so a
default render matches what the reference workflow produces:

- Decoded reference frames are quantised to 8 bits by truncation, as the
  reference LANCZOS helper does (astype(uint8)), not rounded.
- Output frames leave the decoder on the truncated 8-bit grid, the reference
  save's (x * 255).clamp(0, 255).byte(); every export path (np, PIL, the
  on-device uint8 path, the stream encoder) then writes those values.
- Dense checkpoints round the time embedding to the compute dtype before the
  AdaLN SiLU, as the reference does. Curve-form checkpoints are unchanged (they
  already interpolate the table the reference way).
- Keyframe and reference conditions use the VAE posterior mean in float32, as
  the reference encode returns. UNSLOTH_H3_REFERENCE_LATENT=sample restores
  the seeded draw rounded to float16.
- Keyframes without a size render at the reference node's 1344x768 (first
  frame stretched, last centre-cropped) instead of an aspect-matched canvas.
  The page no longer switches to "Match source" on its own; picking it sends
  the matched size. The page starts at the reference templates' 864x480.
- The video decoder stays float16 by default; the int8 ConvRot decoder is
  opt-in with UNSLOTH_H3_VAE_INT8=1.
The reference workflow saves H.264 at CRF 18, converts RGB with the BT.709
matrix and tags the stream BT.709 / sRGB transfer / limited range, and writes
the soundtrack as float AAC. Studio wrote libx264's default CRF 23, let
swscale convert with its BT.601 default untagged, and quantised the
soundtrack to int16 first.

MiniMax-H3 renders now write that file on both the stream encoder and the
post-decode encode (encode_x264 reference=True). Other families are
unchanged. Frame threading stays: it is a speed lever whose pictures agree
with the reference's slice-threaded encode to about 52 dB PSNR.
The page keeps a size the user already picked; 864x480 is what the Default
preset applies. Comments and the status field description only.
… path and pinned tests

Other families open the x264 stream with the stock call again (the reference
flag is passed only for MiniMax-H3), and the tests that pinned the old H3
behaviour expect the reference defaults: the streamed MP4 matches the
reference export, a portrait last frame without a size keeps 1344x768, the
page builds the request size with requestCanvas, and the recipe report lists
the new entries.
…iles

The recipe install shims Diffusers' module-level condition encode, as the
load does. The recipe tests now restore it after each test, and the
condition-encode tests unwrap to Diffusers' own function, so the files pass
in any order and worker.
…a work

The BT.709 conversion now reuses one swscale reformatter per encode: a
per-frame reformat with a colorspace rebuilt the context every frame and
cost 2.2x the encoder's own conversion. With it, the reference export costs
the same as main except for CRF 18 itself (more bits to entropy-code).

The output truncation runs in place on the decode's own float32 frames, so
it adds no copy of the clip; it is idempotent on the 8-bit grid, so a
fallback that postprocesses the same tensor again still gets the same frames.
The reference templates decode with an int8 ConvRot VAE, not a float one.
Decoding the reference's own final latent on one G4, Studio's int8 decoder
lands LPIPS 0.00087 from the reference's int8 decode and its float16
decoder 0.00086, while float16 costs 0.84 s more per 124-frame clip and
1.12 GiB more resident VRAM. So the int8 decoder stays the default, as on
main; UNSLOTH_H3_VAE_INT8=0 keeps the decoder float16.
The fused q/k RMSNorm + RoPE op gains a second rounding mode. The video denoiser now rotates the bf16 normed values
with the bf16 table in float32 (fma(x1, f01, x0 * f00), the reference CUDA kernel's order) and rounds once, instead
of diffusers' chain that rounds each product and the sum. Same Triton kernel and device check (bit-exact against the
unfused math of the chosen rounding), so speed is unchanged. UNSLOTH_H3_QK_ROPE_ROUNDING=eager restores the old
chain; the image pipeline keeps it.
The page only applied the Default preset's size when the preset was picked, so a fresh page rendered at a fit of
the generic 768x512 fallback. When a family that declares a first-render size loads, the page now takes it, behind
the same gate as the family's default clip length (a stored recipe or the user's own pick still wins).
Where the Triton kernel does not run, the once rotation is an addcmul in float32 (within one float32 bit of the
reference kernel's fma) instead of a float64 emulation, which was about 3x slower than the eager chain on a G4. The
device check still compares the kernel against the exact float64 emulation.
…ence numerics

The conditioner loader recognises the reference workflow's nvfp4_awq file: NVFP4 projections stay packed (15.7 GB
resident for the 50 layers, against 27.2 GB for int8) and each call dequantizes the weight in the reference CUDA
kernel's order (code * (block scale * global scale) in float32, one rounding; one fused Triton pass on NVIDIA),
after the AWQ input scale, then a dense matmul, as the file's full_precision_matrix_mult asks. The int8 embedding is
dequantized once at load. No scheme points at the file yet: hosting it is a separate decision.
…wq conditioner

An unset text_encoder_quant now takes nvfp4_awq, the conditioner every reference video template loads, read with the
reference's numerics. On a G4 its conditioning is within 0.9% of the reference's (int8: 2.2%), the t2va render's
LPIPS to the reference render falls from 0.214 to 0.075, peak VRAM drops from 60.1 to 50.4 GiB, host RAM at load
from 39.5 to 30.1 GiB, and the encode is no slower. int8 stays an explicit request; nvfp4_awq is auto-only.

Merge prerequisite: host the reference templates' qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors unchanged
(sha256 35a88d51044231fe332301d7a62aa81e3f2cba62febeb446e2c1e3e0ef76f2c6) in unsloth/MiniMax-H3-FP8 as
text_encoders/official/qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors. Without it an unset load keeps the dense
encoder.
… file is unhosted

An unset text_encoder_quant keeps the hosted int8 conditioner, no scheme names an nvfp4_awq file, and a request
naming nvfp4_awq is refused at validation with the supported list. The nvfp4_awq loader only engages on a file in
that layout.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T12:36:48.484594Z 4fa8f10 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 33d5569e77

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 4e3b1e965b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 15, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 15, 2026
…le is hosted (no request reaches it)

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbe94376f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1843 to +1847
if (familyChanged && loadedFamily && applyFamilyDefault) {
// The family's first-render size (MiniMax-H3: the templates' 864x480), so a fresh page renders it.
const firstSize = familyFirstRenderResolution(status?.defaults, resolutionPresets);
if (firstSize) {
setResolutionIntent(firstSize);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve an explicitly chosen resolution when loading H3

If a user chooses a resolution and then unloads/reloads MiniMax-H3 or switches to it from another family, this effect replaces their selection with 864×480. shouldApplyModelDefaults returns true for an already-seeded form unless the current model pick was superseded, so applyFamilyDefault does not establish that the resolution is untouched. Previously, resolutionIntent survived these family transitions and was fitted to the newly loaded family's limits. Gate this first-render initialization on whether the resolution has actually been initialized or explicitly chosen, rather than reusing the clip-length defaults gate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4fa8f10: the first-render size now applies only while the form's size is untouched. Picking a size or restoring a clip's recipe marks it chosen, so a reload or a switch to MiniMax-H3 keeps it (fitted to the family's limits as before).

…-render size only on an untouched form)

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 4fa8f1022e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 0f23f06 into main Nov 15, 2026
@danielhanchen
danielhanchen deleted the studio-h3-video-reference-defaults branch November 15, 2026 14:08
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