Skip to content

Studio MiniMax-H3 video: Auto INT8 attention with a 4-step exact start on every card (restores the Ada speedup, L4 denoise -19.4%) - #19344

Merged
danielhanchen merged 3 commits into
mainfrom
studio-h3-sm89-int8
Nov 24, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-h3-sm89-int8

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

MiniMax-H3 video under Auto now runs the first 4 denoise steps of every render on the 16-bit attention kernel and INT8 attention after, on every card where Auto engages the INT8 kernel. This replaces the sm89-only Auto off switch from #19098, so Ada cards (L4, RTX 4090, RTX 6000 Ada) get the INT8 speedup back. Explicit int8_attention="on" keeps INT8 on every step; Off is unchanged.

On L4 the denoise time goes from 315.5 s (off, what main runs on sm89 since #19098) to 254.3 s (-19.4%), 85% of the INT8-every-step speedup. On A100-40 it goes from 86.0 s to 75.0 s (-12.7%), 84% of it.

Root cause

sm89 does not drift more than other cards. #19098 flagged it only because its noise floor is tighter.

  • The INT8 kernel is bit-identical on L4 (sm89) and A100-40 (sm80) on the same inputs: a synthetic input at H3's production shape (19315 tokens, 8 heads) and one real captured H3 call (step 0, block 1, the worst head of 56, 4096 query rows against all 19315 keys) give the same output SHA-256 on both cards. INT8 error vs fp64 is 0.0234 / 0.0167 on both, against 0.0011 / 0.0018 for bf16 flash. The per-card kernel configs differ only in launch shape and instruction order, H3 takes the plain kernel path (no attention-sink race) on every card, and the long-call race picks the same 6144-token floor on L4 and A100.
  • INT8's distance from off is about the same on every card (audio log-mel L1 0.43-0.48 on L4, A100 and RTX PRO 6000 in Studio: keep MiniMax-H3 video Auto INT8 attention off on sm89 (audio drift past the L4 floor) #19098). What differs is the cuDNN kernel-swap floor it was compared with: 0.33 on L4, 0.40 on A100, 0.45 on RTX PRO 6000.
  • Against an fp32-attention reference, INT8 on every step fails on A100 as well (frames +0.039 [+0.004, +0.083], audio +0.081 [+0.005, +0.158]), so an arch-specific rule is not justified.
  • Teacher-forced on L4 (the Studio: keep MiniMax-H3 video Auto INT8 attention off on sm89 (audio drift past the L4 floor) #19098 diagnosis run), step 0 carries 4.2x the kernel-swap floor's audio velocity error; later steps are 0.8-1.6x. Keeping the first steps on 16-bit attention removes most of the drift.

Changes

  • video_minimax_h3_attn.py:
    • H3_INT8_EXACT_START_STEPS = 4, h3_int8_exact_steps() and H3Int8Gate.exact_steps. H3_INT8_AUTO_OFF_ARCHS is now empty.
    • install_int8_exact_start(transformer, pipe, steps): routes the strided processors' INT8 calls through unsloth_h3::int8_attention_exact_start, an opaque custom op that runs the processor's own 16-bit kernel (flash / cuDNN pinned as the processor runs it) or the INT8 kernel, chosen per call from the denoiser's own flag tensor. A forward pre-hook on the denoiser sets that flag through a second opaque op (unsloth_h3::int8_exact_start_tick) from the render's video scheduler step index, so no compiled block guards or recompiles on the step, a caller compiling a function around the whole denoiser (fullgraph included) traces it without a break, and two denoisers never read each other's route. Exact steps count from the first step the render runs, so a render that starts at a later grid point still gets 4. The op returns V's dtype on both branches (autocast off inside it), matching its fake.
    • The op refuses a CUDA graph capture on the operand's card, and the denoiser is marked so the block and whole-forward graph paths refuse it with the reason in the status (a replayed graph would freeze one route for every step). H3 video already declines graphs by default.
    • finish_h3_int8_auto, called by the load: if the exact start raises or installs on no processor, INT8 attention is removed for the load (never INT8 on every step under Auto) and the status says why.
  • video.py: after Auto engages INT8 on the H3 denoiser, calls finish_h3_int8_auto. The int8_attention status reason names the exact start, for example unsloth_int8 (cuda) on 52 attention modules, the first 4 denoise steps on 16-bit attention.
  • diffusion_cuda_graph.py: the graph eligibility checks refuse a denoiser that carries _unsloth_cuda_graph_unsafe.
  • UNSLOTH_H3_INT8_EXACT_STEPS=N overrides the step count under Auto (0 = INT8 on every step, as before Studio: keep MiniMax-H3 video Auto INT8 attention off on sm89 (audio drift past the L4 floor) #19098); a value that is not a count keeps the default with a warning.
  • diffusion_int8_attention_dispatch.py: an out-of-memory probe in the long / family race is retried once; a second one loses that call only and is no longer cached for the life of the process (one transient OOM used to decline INT8 for every later load).
  • ROCm: Auto never engages INT8 attention for H3 there (the H3 race is CUDA-kernel only), so nothing changes on ROCm.

Evidence

Colab, Studio at this branch, Studio defaults (960x544x124, 20 steps), the same 12 rows as #19098 (6 prompts x 2 seeds), fresh process per arm. Arms: REF (int8 off, fp32-math attention on every H3 attention call), OFF (int8 off), the cuDNN floor (off with the cuDNN kernel), INT8 every step, and exact start 2 / 4. Every candidate render engaged INT8 on 52 modules and took the exact path for 50 x K calls and INT8 for the rest; REF ran fp32 attention on every call; OFF, floor and REF never engaged INT8.

Rule fixed before running (fp32 reference)

d = metric(X vs REF) minus metric(OFF vs REF), paired bootstrap 95% CI; pass if the CI upper bound is at or below the floor |mean(cuDNN minus OFF)|.

card arm frames d [95% CI] floor audio d [95% CI] floor
L4 INT8 every step +0.057 [+0.024, +0.094] 0.004 +0.063 [-0.045, +0.175] 0.056
L4 exact start 2 +0.002 [-0.012, +0.014] 0.004 -0.000 [-0.047, +0.046] 0.056
L4 exact start 4 -0.001 [-0.014, +0.015] 0.004 +0.008 [-0.027, +0.043] 0.056
A100-40 INT8 every step +0.039 [+0.004, +0.083] 0.013 +0.081 [+0.005, +0.158] 0.003
A100-40 exact start 2 +0.008 [-0.017, +0.040] 0.013 +0.028 [-0.037, +0.102] 0.003
A100-40 exact start 4 +0.005 [-0.003, +0.015] 0.013 +0.047 [+0.002, +0.092] 0.003

No arm meets the rule on either card at 12 rows. Exact start 4 is indistinguishable from off against the fp32 reference on L4 (both CIs straddle 0) and misses only the frames floor bound (upper +0.015 vs 0.004). The A100 audio floor is degenerate: OFF and the cuDNN arm are on average equally far from the reference (0.003), while their paired difference spans [-0.056, +0.052], so the cuDNN kernel swap itself would fail this rule. The A100 A/A repeat of off is bit-identical, so an A/A floor is 0 there. On both cards exact start 4 is closer to the fp32 reference than INT8 on every step.

Paired against the cuDNN floor arm (scored against OFF)

metric(X vs OFF) minus metric(cuDNN vs OFF), paired 95% CI; negative = closer to off than a bf16 kernel swap.

card arm frames X / cuDNN frames diff [95% CI] audio X / cuDNN audio diff [95% CI]
L4 INT8 every step 0.215 / 0.169 +0.046 [-0.009, +0.089] 0.481 / 0.329 +0.152 [+0.050, +0.276]
L4 exact start 4 0.084 / 0.169 -0.085 [-0.136, -0.037] 0.310 / 0.329 -0.019 [-0.118, +0.092]
A100-40 INT8 every step 0.208 / 0.195 +0.013 [-0.029, +0.061] 0.426 / 0.404 +0.022 [-0.053, +0.102]
A100-40 exact start 4 0.085 / 0.195 -0.110 [-0.165, -0.062] 0.328 / 0.404 -0.077 [-0.121, -0.030]

Speed

Denoise seconds per clip, one row per arm, fresh process per arm, interleaved A B C D D C B A on one VM per card (repeats within 0.4 s):

card off INT8 every step exact start 2 exact start 4 share of INT8 speedup kept (4)
L4 315.5 243.0 (-23.0%) 246.7 (-21.8%) 254.3 (-19.4%) 85%
A100-40 86.0 72.9 (-15.2%) 73.6 (-14.4%) 75.0 (-12.7%) 84%

Tests

studio/backend/tests/test_h3_int8_exact_start.py (CPU, tiny real H3 transformer):

  • the gate sets the exact start on every card under Auto, ROCm / unknown included; explicit On keeps INT8 on every step; explicit Off wins over the env override; the Auto off reasons are unchanged
  • the env override and the bad-value fallback with a warning
  • exact steps match the off model bit for bit and later steps call the INT8 kernel, including a render that starts at a later grid point and the next render starting over
  • the op refuses a CUDA graph capture, judged on the operand's card, and both graph paths refuse an exact-start denoiser with the reason
  • the op adds no graph break over the 16-bit strided processor; a fullgraph compile of a function around the whole denoiser traces once and still switches route by step
  • two overlapping denoisers keep their own route
  • the op's fake dtype matches its real output under autocast
  • the load step takes INT8 off when the exact start raises or installs on no processor
  • a transient out-of-memory race probe is retried and never cached (test_diffusion_int8_attention_persisted.py)
  • on ROCm, Auto's H3 race installs nothing, so the exact start never installs
  • the H3 load calls the load step only under Auto

test_h3_int8_auto_arch.py is updated for the removed sm89 off switch. The new and the flipped tests fail on the merge base and pass here. The INT8 attention toggle, families and auto suites, the H3 attention suite, the CUDA graph suite and the video backend suite pass.

Not covered

  • RTX PRO 6000 / G4 (sm120), sm86 (RTX 3090 / A10 / A40), H100 and B200 were not re-gated with the exact start; they get it by the same rule.
  • The RTX 6000 Ada and the 12 / 16 GB tiers from the tester's round were not re-run on this branch.
  • i2v / reference workflows and the 10-step setting were not re-measured; a render with a begin index is covered by a CPU test only.
  • Explicit int8_attention="on" still runs INT8 on every step.
  • No listening test.

…ry card (re-enables sm89)

Under Auto, MiniMax-H3 video runs the first 4 denoise steps of each render on the
16-bit kernel and INT8 attention after, wherever Auto engages the kernel. This
replaces the sm89-only Auto off switch from #19098. Explicit On keeps INT8 on every
step; Off is unchanged. UNSLOTH_H3_INT8_EXACT_STEPS overrides the step count (0 =
INT8 on every step). Denoisers with the exact start refuse CUDA graphs.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 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-24T20:18:17.226208Z 4fe3d71 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. Already looking forward to the next diff.

Reviewed commit: d3a92c950f

ℹ️ 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".

…re check on the operand's card

- Each denoiser keeps its own route in a flag tensor that its forward pre-hook sets through an opaque tick op
  (unsloth_h3::int8_exact_start_tick); the attention op reads that flag. Overlapping denoisers no longer read a
  process-wide boolean, and a caller compiling a function around the whole denoiser (fullgraph included) traces the
  hook with no graph break and no recompile per step.
- The op returns V's dtype on both branches with autocast off inside it, matching its fake.
- The CUDA graph capture check runs under the operand's device.
- finish_h3_int8_auto (called by the H3 video load): an exact start that raises or installs on no processor takes
  INT8 attention off for the load, undoing any partial install.
…ver cache the loss

_race_wins kept an out-of-memory loss in _LONG_VERDICTS for the life of the process, so one transient OOM in the
H3 family race declined INT8 attention for every later load. The probe is now retried once after freeing the cache;
a second OOM loses that call only (not cached, not persisted).

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 24, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 4fe3d71e4f

ℹ️ 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 015c652 into main Nov 24, 2026
1 check passed
@danielhanchen
danielhanchen deleted the studio-h3-sm89-int8 branch November 24, 2026 22:10
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