Skip to content

Studio video: bit-identical int8 GEMM routes on streamed int8 denoisers - #17658

Merged
danielhanchen merged 10 commits into
mainfrom
studio-h3v-stream-int8
Nov 13, 2026
Merged

danielhanchen merged 10 commits into
mainfrom
studio-h3v-stream-int8

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Stacked on #17617 (base branch h3-int8-sm120). Retarget to main once that merges.

Summary

#17617 moved uncompiled, resident int8 denoisers onto Studio's bit-identical int8 GEMM routes. A denoiser that streams block by block still ran torchao's eager int8 Linear. That covers MiniMax-H3 INT8 at speed off on L4, A100-40 and any card where the other components need the room. This PR gives those streamed denoisers the same routes in call-time mode.

MiniMax-H3 INT8-ConvRot, speed off, streamed, 640x384, 124 frames, 20 steps:

  • G4: 2.06 -> 1.14 s/step, the same speed as the resident tier (1.13).
  • L4: 12.26 -> 9.16 s/step (-25%).
  • Frames are byte-identical to the base on both cards (sha256).

Root cause

apply_speed_optims runs _install_eager_int8_gemm (#17617) before placement, and that function skips any denoiser that will move (moved = offload_active if denoiser_offloaded is None else denoiser_offloaded). The compiled streamed install (video.py, if denoiser_streamed and "compiled" in speed_optims) covers only the compiled tier. So a streamed H3 denoiser on speed off / eager, or after a declined compile, kept torchao's Linear for all 300 int8 calls per step: a float32 epilogue, an eager rotation and an eager act quant. The generic video placement (apply_memory_plan, with the event-fenced prefetch from diffusion_memory) has the same gap for any other family that streams int8 Linears.

Change

  • diffusion_int8_gemm.install_streamed_eager(transformer, device) is install(..., device=device, exact=True). These are install_eager's routes: the fused-dequant GEMM, the dense rotq_i8 rotation + act quant (never rotq_h16), and no SwiGLU fusion. They run in the existing call-time mode: each call checks that the Linear's own weight is still the installed Parameter and sits on the activation's card. Otherwise the call takes torchao's path.

  • diffusion_speed.install_streamed_eager_int8_gemm(pipe, device) runs after placement. It engages only on a denoiser that:

    • is driven by the event-fenced prefetcher (module_prefetcher). That prefetcher copies into the same Parameters (swap_tensors / inner-tensor re-pointing), so the identity check sees every onload;
    • is not compiled (compiled_denoiser), not already swapped, and has int8 candidates.
  • video.py calls it in two places:

    • in the MiniMax-H3 branch, for a streamed denoiser the compile did not take;
    • in the generic video placement, right after compile_pipe_below_offload_hooks, for every denoiser view.

    Status reports int8_gemm_streamed, and int8_gemm_live drops it when nothing swapped.

  • shared_rotq_linears (shared Q/K/V act quant) now passes exact when every Linear in the group is on the eager routes. The shared quant is then the same dense kernel each Linear runs on its own. Compiled installs never set the mark, so they are unchanged.

Switches:

  • UNSLOTH_DIFFUSION_INT8_GEMM_STREAMED_EAGER=0 keeps torchao's path on streamed denoisers.
  • UNSLOTH_DIFFUSION_INT8_GEMM_EAGER=0, UNSLOTH_DIFFUSION_INT8_GEMM_STREAMED=0 and UNSLOTH_DIFFUSION_INT8_GEMM=0 also turn it off.

Results

MiniMax-H3 fl2va, hosted INT8-ConvRot (text encoder int8), 640x384, 124 frames, 20 steps, guidance 1.0, torch 2.14.1+cu130, torchao 0.18.0, Triton 3.8.0. Setup:

G4 (RTX PRO 6000 Blackwell), streaming forced with the VRAM budget, 2 clips:

placement arm s/step s/clip (clip 1, clip 2) peak VRAM alloc GiB frames vs base
fully streamed (budget 30%, UNSLOTH_H3_DIT_RESIDENT=0) base 2.056 45.9, 43.9 6.37 -
base repeat 2.057 45.7, 43.9 6.37 identical
this PR 1.140 28.6, 25.6 6.38 identical
this PR, switch off 2.057 45.2, 43.9 6.37 identical
part resident (budget 20%, 27 of 50 blocks resident) base 2.049 45.7, 43.7 16.95 -
base repeat 2.050 45.7, 43.7 16.95 identical
this PR 1.137 26.7, 25.5 16.95 identical
budget 30% (per-request refit holds all 50 blocks) base 2.037 45.9, 43.5 26.60 -
base repeat 2.039 45.2, 43.5 26.60 identical
this PR 1.126 27.3, 25.3 26.60 identical
this PR, switch off 2.039 45.2, 43.5 26.60 identical
resident (no budget, #17617's eager install) this PR 1.128 25.4, 25.3 25.32 identical
speed default (compiled), budget 30% base / this PR 0.891 / 0.891 28.9, 19.8 / 22.9, 19.8 25.13 / 25.13 identical
speed default (compiled), fully streamed this PR 0.895 28.6, 20.0 4.91 -

L4, 1 clip (it streams on its own: 9 blocks resident at load, 37 of 50 after the per-request refit):

arm s/step s/clip peak VRAM alloc GiB frames vs base
base, speed off 12.261 298.7 20.31 -
base repeat 12.264 288.0 20.31 identical
this PR, speed off 9.156 225.7 20.31 identical
base, speed default (compiled) 6.345 189.2 19.30 -
this PR, speed default (compiled) 6.359 176.3 19.30 identical

Host RSS peaks were 96-105 GiB on G4 and 46.4-46.7 GiB on L4. The spread was the same between the base and its repeat, with no shift this PR adds.

What runs per denoiser forward (torch.profiler, two steady forwards, per forward):

card, placement arm int8 Linear calls route int8 GEMM kernel H2D copy (overlapped)
G4, fully streamed base 300 torchao: eager rotation + quant, cuBLAS i16832gemm_s8 tn, float32 epilogue 451 ms 344 ms (330 ms)
G4, fully streamed this PR 300, 0 fallbacks rotq_i8 + i8mm_dq_tma 431 ms 344 ms (333 ms)
L4, streamed base 300 torchao 2555 ms 414 ms (394 ms)
L4, streamed this PR 300, 0 fallbacks rotq_i8 + cuBLAS TN + torchao's epilogue op for op (the Triton GEMM stays off on sm_89) 2699 ms 412 ms (392 ms)

The prefetcher already hides the copies (14 ms exposed per forward on G4, 20 ms on L4), so the streamed tier was compute-bound on torchao's eager Linear. On G4 the base's three largest elementwise kernels (the float32 / bf16 epilogue passes and the bf16 copy, about 490 ms per forward) are gone, and the eager rotation + quant becomes one rotq_i8 launch per Linear. With them gone, the streamed tier runs at the resident tier's speed.

Tests

  • New CPU tests:
    • both kill switches, and install_streamed_eager threading device + exact through install; the streamed and global switches also stop it;
    • install_streamed_eager_int8_gemm engages behind the prefetcher and skips:
      • a denoiser with no prefetcher;
      • a compiled denoiser;
      • a dense denoiser;
      • an already swapped denoiser;
      • a call with no device;
    • it swallows an install failure;
    • int8_gemm_live drops the new key;
    • the shared Q/K/V quant is exact only when every Linear is;
    • an AST check that video.py calls it in the H3 streamed-uncompiled branch and after the generic offload hooks.
  • New GPU test: a ConvRot int8 Linear (torchao v1 and v2 configs) is installed while its weight is on the host. After a swap_tensors onload (what the prefetcher does) it takes the eager routes, bit-identical to torchao's Linear, with no rotq_h16.
  • test_diffusion_int8_gemm.py + test_diffusion_stream_int8_gemm.py with CUDA tests on (-o addopts=):
    • G4: 188 passed (base 181).
    • L4: 187 passed, 1 failed (base 180 passed, 1 failed). The L4 failure, test_no_compiled_variant_spills_to_local_memory, fails the same way on the base (Triton 3.8 spills on sm_89).
  • The commit applies cleanly on Studio: run the bit-identical int8 GEMM routes on uncompiled int8 denoisers #17617 alone, and test_diffusion_int8_gemm.py + test_diffusion_speed.py pass there (308 passed).

Not covered

  • Other video families that stream int8 Linears through the generic placement (Wan, LTX, HunyuanVideo-1.5) are covered by the CPU wiring tests only. No GPU render was run for them.
  • A100-40 was not run. On sm_80 the route is the same as on L4: the dense rotation kernel plus cuBLAS TN, because the Triton GEMM stays off on sm_8x with Triton 3.8.
  • Streamers that swap in new Parameters per call (H3-Image's pageable ModuleListStreamer) are excluded by the prefetcher gate. Diffusers' own onload without the prefetcher is excluded too.
  • The shared Q/K/V quant change affects the resident eager speed tier with strided attention, which now takes the dense kernel instead of rotq_h16. That tier was not timed here.
  • ROCm, MPS and Windows were not run. The install refuses ROCm and non-CUDA devices.

…oisers

torchao's eager int8 Linear is cuBLAS _int_mm plus four float32 passes over
the [rows, N] output. On sm_120 cuBLASLt picks a forward-compat sm_80 WMMA
int8 kernel, so an eager int8 ConvRot Linear costs about 3x the bf16 one
(MiniMax-H3 at 640x384x124: 3.3 vs 1.56 s/step). Compiled loads already swap
in Studio's fused-dequant GEMM; speed off / eager loads never did.

install_eager swaps the same GEMM onto an uncompiled resident denoiser,
limited to the routes that are bit-identical to torchao's eager Linear: the
fused-dequant GEMM and the dense rotq_i8 rotation + act quant (never rotq_h16),
no SwiGLU fusion. apply_speed_optims runs it on speed off and whenever the
denoiser stays uncompiled. UNSLOTH_DIFFUSION_INT8_GEMM_EAGER=0 keeps torchao.
…rs behind the pinned prefetcher

An uncompiled int8 denoiser that streams block by block (MiniMax-H3 on L4 / A100-40,
or any card where other components need the room) kept torchao's eager int8 Linear:
a per-call transposed weight copy, a slow NN-layout int8 GEMM and a float32 epilogue.

After placement, install_streamed_eager runs install_eager's routes (fused-dequant
GEMM + dense rotq_i8, never rotq_h16, no SwiGLU fusion) in call-time mode: each call
checks that the Linear's own weight sits on the activation's card, else torchao's
path. Only behind the event-fenced prefetcher, which copies into the same
parameters; a compiled denoiser keeps its own install. The shared Q/K/V quant takes
the dense kernel when every Linear is on the eager routes.

UNSLOTH_DIFFUSION_INT8_GEMM_STREAMED_EAGER=0 keeps torchao's path on streamed
denoisers.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-13T12:41:35.702140Z 4fabe11 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. Can't wait for the next one!

Reviewed commit: 6688d85e0f

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

…alone

The streamed eager install runs after placement, so a Linear that diffusers hooked directly (a Linear inside a top-level Sequential or ModuleList) would have its hooked forward replaced, skipping its onload. Skip such Linears on the streamed installs.

[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. Keep them coming!

Reviewed commit: 4fabe1128f

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

Base automatically changed from h3-int8-sm120 to main November 13, 2026 13:12
@danielhanchen
danielhanchen merged commit d90c243 into main Nov 13, 2026
@danielhanchen
danielhanchen deleted the studio-h3v-stream-int8 branch November 13, 2026 13:18
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