Repository navigation
Studio video: bit-identical int8 GEMM routes on streamed int8 denoisers - #17658
Conversation
…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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Stacked on #17617 (base branch
h3-int8-sm120). Retarget tomainonce 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
offon 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:Root cause
apply_speed_optimsruns_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 speedoff/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 fromdiffusion_memory) has the same gap for any other family that streams int8 Linears.Change
diffusion_int8_gemm.install_streamed_eager(transformer, device)isinstall(..., device=device, exact=True). These areinstall_eager's routes: the fused-dequant GEMM, the denserotq_i8rotation + act quant (neverrotq_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:module_prefetcher). That prefetcher copies into the same Parameters (swap_tensors/ inner-tensor re-pointing), so the identity check sees every onload;compiled_denoiser), not already swapped, and has int8 candidates.video.pycalls it in two places:compile_pipe_below_offload_hooks, for every denoiser view.Status reports
int8_gemm_streamed, andint8_gemm_livedrops it when nothing swapped.shared_rotq_linears(shared Q/K/V act quant) now passesexactwhen 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=0keeps torchao's path on streamed denoisers.UNSLOTH_DIFFUSION_INT8_GEMM_EAGER=0,UNSLOTH_DIFFUSION_INT8_GEMM_STREAMED=0andUNSLOTH_DIFFUSION_INT8_GEMM=0also 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:
_int_mm, so it is faster than the 3.31 s/step Studio: run the bit-identical int8 GEMM routes on uncompiled int8 denoisers #17617 started from.cuda.synchronizeat each forward boundary applies to every arm alike.generatewall time, which includes the encode and the decode.G4 (RTX PRO 6000 Blackwell), streaming forced with the VRAM budget, 2 clips:
UNSLOTH_H3_DIT_RESIDENT=0)L4, 1 clip (it streams on its own: 9 blocks resident at load, 37 of 50 after the per-request refit):
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):
i16832gemm_s8 tn, float32 epiloguerotq_i8+i8mm_dq_tmarotq_i8+ cuBLAS TN + torchao's epilogue op for op (the Triton GEMM stays off on sm_89)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_i8launch per Linear. With them gone, the streamed tier runs at the resident tier's speed.Tests
install_streamed_eagerthreadingdevice+exactthroughinstall; the streamed and global switches also stop it;install_streamed_eager_int8_gemmengages behind the prefetcher and skips:int8_gemm_livedrops the new key;video.pycalls it in the H3 streamed-uncompiled branch and after the generic offload hooks.swap_tensorsonload (what the prefetcher does) it takes the eager routes, bit-identical to torchao's Linear, with norotq_h16.test_diffusion_int8_gemm.py+test_diffusion_stream_int8_gemm.pywith CUDA tests on (-o addopts=):test_no_compiled_variant_spills_to_local_memory, fails the same way on the base (Triton 3.8 spills on sm_89).test_diffusion_int8_gemm.py+test_diffusion_speed.pypass there (308 passed).Not covered
ModuleListStreamer) are excluded by the prefetcher gate. Diffusers' own onload without the prefetcher is excluded too.eagerspeed tier with strided attention, which now takes the dense kernel instead ofrotq_h16. That tier was not timed here.