Repository navigation
Studio Triton kernels: resolve factory closure names on Triton 3.2 / 3.3 - #18591
Conversation
…s for Triton 3.2 / 3.3
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. Bravo. 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". |
0xalkinun
left a comment
There was a problem hiding this comment.
I recommend merging this change. I reproduced the closure lookup failures on an RTX 3090 with the official PyTorch CUDA 11.8 wheels and verified the fix at 2390dfd854.
- PyTorch 2.7.1 / Triton 3.3.1. All 13 GPU probes failed to launch or fell back on the merge base. All 13 ran on the PR and matched their PyTorch references bit for bit, including FLUX rotary embeddings, grouped INT8 GEMV and the FP8 weight transpose. A reduced-channel Diffusers FLUX.2 VAE also went from disabling the strip path on its first decode to completing both 136 × 200 strip decodes. The largest absolute difference from stock decode was 1.05e-6.
- PyTorch 2.6.0 / Triton 3.2.0. Twelve direct probes matched bit for bit. Forcing the private H3 fused RMSNorm + RoPE kernel differed from eager PyTorch on this build. I checked the runtime dispatch separately on both 2.6.0 and 2.7.1. It kept PyTorch RMSNorm, used the restored Triton rotary kernel, and matched eager bit for bit on all 32 FP16/BF16 inputs per release. The merge base used the stock path on every input.
- Compiler boundary. For the VAE strip and H3 row-modulation kernels, the merge base failed to compile on 3.2.0 and 3.3.1 and compiled on 3.4.0 and 3.5.1. The PR compiled both kernels on all four versions for sm75, sm80, and sm86. T4 and A100 coverage was compile-only.
I found no merge-blocking regression in the reviewed change.
Triton 3.2 and 3.3 (the Triton of torch 2.6 and 2.7, and the newest torch on CUDA 11.8 wheels, all inside Studio's
torch>=2.4,<2.12install range) resolve the names a@triton.jitkernel reads in the kernel's module globals only. Newer Triton also reads the function's closure. Most Studio kernels are built inside a lazy factory (_kernels(),_kernel(), ...) that importstriton.language as tllocally and often defines JIT helpers and constants next to the kernel, so on Triton 3.2 / 3.3 they fail to lower withNameError('tl is not defined')(or the same for a helper). Three factories (diffusion_vae_fused,diffusion_int8_fused,video_minimax_h3_vae) already worked around this withglobals().update(triton = triton, tl = tl); the other fourteen did not. Depending on the call site the result is a crash at the first launch, a silent fallback to a slower path (the frozen FP8 transpose), or a kernel probe that fails and keeps the stock path.Found in a recheck of #17966 (
_rows_residualin the VAE strip decode, confirmed with an offline Triton 3.3.0 compile for sm75 and sm80: fails on main, compiles with the name in module globals, still compiles on 3.8.0).Change
core/inference/triton_closure_globals.py:publish(result)finds every JIT kernel reachable from a factory's result (namespaces, containers, plain launcher closures, and the JIT helpers a kernel calls) and copies each kernel's closure names into its module globals withsetdefault, so an existing module global is never overwritten.publishes_closure_globalsis the decorator form.lru_cacheon the factories indiffusion_convrot_quant,diffusion_flux2_rope,diffusion_flux3_qk_rope,diffusion_int8_fused,diffusion_int8_gemm,diffusion_int8_gemv,diffusion_moss_fused,diffusion_native_w8a8_rdna,diffusion_qwenimage21_eager,diffusion_rocm_fused,video_minimax_h3_qknorm,video_minimax_h3_rowmodandvideo_wan_fused;diffusion_frozen_fp8publishes its transpose kernel when it builds it.diffusion_vae_stripsbindstllike the fused VAE module (first commit).Tests
tests/test_triton_closure_globals.py(CPU, nothing compiles): for each of the 17 factories, every reachable JIT kernel must find every closure name in its module globals. 16 fail on main (for example_f3_qk_norm_rope:tl,_qk_norm_rope_kernel:_rsqrt,i8mm_dq:_rbf16,transpose:tl);diffusion_vae_fusedpasses on both. A second test checks that a kernel reached only through a plain launcher, and the JIT helper it calls, are published, and that an existing module global is left alone.tests/test_diffusion_vae_strips.py::test_kernel_names_resolve_from_module_globals: fails on main, passes here.Base vs head over the changed test files: 16 fixed, 56 unchanged, 0 failing on this branch.
Not proven here