Skip to content

Studio Triton kernels: resolve factory closure names on Triton 3.2 / 3.3 - #18591

Merged
danielhanchen merged 2 commits into
mainfrom
fix-recheck-vae-tl
Nov 20, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix-recheck-vae-tl

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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.12 install range) resolve the names a @triton.jit kernel 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 imports triton.language as tl locally and often defines JIT helpers and constants next to the kernel, so on Triton 3.2 / 3.3 they fail to lower with NameError('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 with globals().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_residual in 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

  • New 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 with setdefault, so an existing module global is never overwritten. publishes_closure_globals is the decorator form.
  • The decorator sits under the existing lru_cache on the factories in diffusion_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_rowmod and video_wan_fused; diffusion_frozen_fp8 publishes its transpose kernel when it builds it. diffusion_vae_strips binds tl like the fused VAE module (first commit).
  • No kernel source changes. On current Triton the published names are the same objects the closure already holds.

Tests

  • New 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_fused passes 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

  • No real launch on torch 2.6 / 2.7: only the offline Triton 3.3 compile of the VAE strip kernel and the module-globals check above. A T4 run on torch 2.7.1 is the follow-up.
  • Triton 3.4 to 3.6 were not checked for which release started reading closures.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-20T07:35:01.783717Z 2390dfd 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. Bravo.

Reviewed commit: 2390dfd854

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

@0xalkinun 0xalkinun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants