Repository navigation
Studio diffusion kernels: keep per-resolution sizes out of the Triton compile key - #16582
Conversation
… compile key Token counts (int8 GEMM / ConvRot M, RoPE / AdaLN / MOSS S, Qwen-Image rows) and VAE / H3 spatial sizes (HW, W, n_chunks, frames) were plain ints, so their % 16 specialisation recompiled every kernel the first time a resolution whose sizes are not multiples of 16 ran (1328x1328 after 1024x1024: about 6 s of cold compiles on A100). They are now in do_not_specialize (the VAE kernels through the existing _SHAPE_ARGS table); strides and channel counts stay specialised. Steady-state time unchanged or faster (int8 GEMM -7% at 1328x1328), GroupNorm error vs fp64 unchanged. Wan's L is left specialised: dns L cost 1.4-1.9% at 720p.
|
@codex review |
Codex Review SummaryThis 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. Swish! 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". |
…on-resolution-args # Conflicts: # studio/backend/core/inference/diffusion_vae_fused.py [skip ci]
…nslothai#16585) ## Summary Comment-only. Every `tl.constexpr` parameter line in the Unsloth Triton kernels and the Studio diffusion / video kernels now carries a short trailing comment naming what it is (`# hd`, `# block size along K`, `# int8 clamp max`, `# fuse swiglu before rotation`), so a reviewer can tell at a glance whether a constexpr is a true constant or a per-call size that would recompile. - 482 lines across 29 files (`unsloth/kernels/**`, `unsloth/optimizers/flash_adamw.py`, `studio/backend/core/inference/**` kernels). - Not touched: `unsloth/kernels/nf4*.py`, the fast LoRA kernels and the fast-inference decode path, which are being reworked separately. - No code changes: `comment_tools.py check --changed --allow-docstring-edits --strict-ext` passes 29 / 29 files (AST-compared, comments and whitespace only). The functional recompile fixes found by the same audit are separate PRs: unslothai#16582 (Studio diffusion kernels, per-resolution sizes) and unslothai#16584 (layernorm dW, fp8 block matmul, nvfp4 split sum).
Runtime n_rows was 2.5% slower at even token counts on A100; n_seq stays runtime, so the first odd-token resolution still skips most recompiles.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 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". |
Summary
The first render at a resolution whose token count or VAE width is not a multiple of 16 recompiled almost every Studio diffusion Triton kernel once (1328x1328 after 1024x1024: 7401 tokens, 166-wide VAE maps). That is about 6 s of cold compiles per process on an A100 before the image starts. Triton specialises plain integer arguments on
% 16and== 1, so those per-resolution sizes were part of the compile key.This moves only the per-resolution sizes into
do_not_specialize. Strides and channel counts stay specialised.Change
diffusion_int8_gemm.py(i8mm_dq,i8mm_dq_tma):M.diffusion_convrot_quant.py(rotq_i8,rotq_h16):M.diffusion_flux2_rope.py,diffusion_moss_fused.py,diffusion_rocm_fused.py(AdaLN):S.diffusion_qwenimage21_eager.py:n_seq.n_rowskeeps its hint: as a runtime argument it was 2.5% slower at even token counts on A100. With onlyn_seqruntime the kernel compiles to the same binary as main at 1024x1024 and 1024x768 (sm75 to sm120), and it keeps one compile (about 0.3 s) at the first odd-token resolution.diffusion_vae_fused.py: GroupNorm partials / combine / apply, row softmax and the DC-AE upsample add join the existing_SHAPE_ARGStable that four of its kernels already used.video_minimax_h3_qknorm.py,video_minimax_h3_vae.py: row counts and spatial sizes.Evidence
Kernels driven at the shapes the pipelines run, base vs head, Colab A100 and G4 (RTX PRO 6000), 3 fresh processes per arm, interleaved,
do_benchmedian, A/A spread first. A 48 GiB allocator segment is reserved before any compile: without it the base arm, which compiles more variants, gets a different memory layout and byte-identical binaries read up to 6% apart._qk_norm_rope_kernel_norm_rope_kernel_add_residual, VAE_dcae_up_addtorch.group_norm.Tests
studio/backend/tests/test_diffusion_triton_resolution_args.py(static, CPU): every per-resolution size of these kernels is listed indo_not_specialize. 9 fail on main, 9 pass here.Not covered