Repository navigation
Studio INT8 attention: compile the Triton kernel on NVIDIA Triton 3.3 (torch 2.7) - #19319
Conversation
….3 (torch 2.7)
Triton 3.3's TritonGPURemoveLayoutConversions pass hands the rotation's tl.join a
result layout that JoinOp's own type inference rejects ("'tt.join' op failed to
infer returned types"), so prep / kv / quant_rows failed to compile on every NVIDIA
arch and #17957 turned the Triton path off on 3.3. On NVIDIA Triton 3.3 the
rotation now interleaves (a + b, a - b) with tl.where on a size-2 axis instead;
every other Triton (and ROCm 3.3) keeps the tl.join source unchanged. The two
bodies are separate definitions picked in Python: Triton 3.2 / 3.3 leave a
constexpr global's value out of the JIT cache key, so one body behind a constexpr
if would share compiled kernels.
Also: a fallback to native attention now says why Triton could not stand in
(IMPL=cuda, no Triton, no config for the card), the install log line carries the
verdict's error, and the persisted probe key reads the Triton version from
triton-windows / pytorch-triton-rocm / pytorch-triton too (it was None there).
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59546d9888
ℹ️ 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".
| monkeypatch.setattr(triton, "__version__", version) | ||
| name = "core.inference.diffusion_int8_attention_triton" | ||
| fresh = importlib.reload(sys.modules[name]) | ||
| try: | ||
| assert ("tl.join" in inspect.getsource(fresh._rotate.fn)) is join_in_rotate |
There was a problem hiding this comment.
Control the build type in the rotation reload test
On a ROCm PyTorch installation with Triton available, the 3.3.1 case fails even though the implementation behaves correctly: reloading the module calls join_free_rotation(), which detects the real ROCm build and deliberately selects the tl.join variant, while this test unconditionally expects the join-free variant. Mock the build detection dependency across the reload or parameterize the expected result by build type so the test also passes on the supported ROCm environment.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4d5e01cc73: the reload test now pins the build identity (torch.version.hip and torch.__version__) and runs four cases, 3.3.1 and 3.7.1 on NVIDIA and on ROCm, with both ROCm cases expecting the tl.join variant. Run as a ROCm build, the old version fails [3.3.1-False] and the new one passes all four.
…el; triton-rocm / triton-xpu keys A split load raced and filtered only the primary card, then ran an untimed verdict() on each secondary. With the Triton path now compiling on Triton 3.3, a secondary whose CUDA module failed fell through to an unraced Triton check and served Triton, even for a CUDA-only Auto family (FLUX.3). verdict() takes impl_only: a secondary is checked only on the implementation the primary's floor raced and accepted, anything else is declined unchecked, so that card keeps native attention as before. The probe-cache Triton version also reads the current triton-rocm and triton-xpu distribution names (it read None there). The rotation reload test pins the torch build identity and covers ROCm 3.3 keeping tl.join. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
…imary's raced kernel The generic Auto path (no family floor) still ran an untimed verdict() on each split / CFG-replica secondary without impl_only, so a secondary whose CUDA module failed could adopt the unraced Triton stand-in. Pass the primary's implementation there too, and keep the family-race floor's untimed check on the CUDA kernel only. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
…rsion Same _TRITON_DISTS + _triton_version() helper as #19319 (triton, triton-windows, the ROCm and XPU distributions), replacing the triton-windows-only fallback, so the fingerprint key changes once. [skip ci]
Summary
Studio's Triton INT8 attention kernel did not compile on NVIDIA Triton 3.3 (torch 2.7.x). #17957 dealt with this by switching the Triton path off on that version. This PR makes the kernel compile there, so the Triton path can stand in on 3.3 like it does on every other version.
(a + b, a - b)withtl.join. On Triton 3.3, theTritonGPURemoveLayoutConversionspass assigns the join a result layout with the new axis as the last register bit.JoinOp's own type inference expects that axis as the first register bit, so verification fails with'tt.join' op failed to infer returned types/PassManager::run failed. This breaksprep,kvandquant_rowson every NVIDIA arch: sm80, sm86, sm89, sm100 and sm120.attncompiles. Triton 3.2 and 3.4+ compile the join.tl.whereon a size-2 axis instead oftl.join. Every other Triton, ROCm included, keeps the existing source, so its compiled kernels and output bits do not change.constexprswitch: the two_rotatebodies are separate definitions, picked in Python at import. Triton 3.2 and 3.3 leave aconstexprglobal's value out ofJITFunction.cache_key. I checked this directly: the same source withG = tl.constexpr(True)and withFalsegives identical keys on 3.2.0 and 3.3.1, and different keys on 3.7.1. With one body behind aconstexprif, both variants would share one compiled kernel.UNSLOTH_DIFFUSION_INT8_ATTENTION_IMPL=cuda, Triton not installed, or no Triton config forsm_XY head_dim=N). It used to say only "no kernel for this card". The install log line also includes the verdict's error.triton-windows,triton-rocm,triton-xpu,pytorch-triton-rocm,pytorch-tritonandpytorch-triton-xpuas well astriton. Before, it wasNoneon Windows and ROCm wheels, so verdicts from different Triton versions shared one key there. NVIDIA Linux keys do not change (thetritondistribution comes first).triton-windows,triton-rocm,pytorch-triton-rocm, and so on). The first load re-runs the check and race; later loads reuse the new verdict.Who this reaches
install.shinstalls torch 2.6.0 for drivers reporting CUDA 12.0 to 12.5 (cu124 index, newest is 2.6.0) and torch 2.7.1 for CUDA 11.x drivers (cu118 index, newest is 2.7.1). It also keeps an existing 2.4+ torch on update.install_python_stack.pysets up the diffusion stack (torchao, diffusers) for torch 2.6 to 2.9.IMPL=tritonis set. I compiled the CUDA kernel's attention and quantiser sources with NVRTC 11.8, 12.4 and 12.8 for every configured card and head dim. All of them compile, except sm120 on 11.8 and 12.4, which those wheels cannot run anyway.Evidence
CPU compile: fresh
TRITON_CACHE_DIRper run, all prep / kv / quant_rows / attn variants for head dims 64 and 128.Studio's own
verdict()(untimed accuracy check): B200, torch 2.7.1+cu128, Triton 3.3.1,IMPL=triton, the sm89 Triton config.Numerics on B200: Studio's Triton path vs fp32 attention and vs bf16 SDPA, at real attention shapes. bf16 inputs; keys with a per-channel offset; values with a spread of channel ranges.
For scale, bf16 SDPA vs fp32 on the same inputs has a rel L1 of 2.1e-3 to 2.3e-3.
Bits:
Colab A100-40 (sm80) with the wheels
install.shpicks for older drivers: torch 2.7.1+cu126 (Triton 3.3.1) and torch 2.6.0+cu124 (Triton 3.2.0). Both versions run the same inputs and the same branch.On sm80, the join-free kernel on Triton 3.3.1 matches the current join kernel on Triton 3.2.0 bit for bit.
Studio
verdict()on the same A100:With the default
IMPL=auto, the CUDA (NVRTC) kernel serves on both old-torch installs, so default users were already getting INT8 attention there. This PR fixes the Triton stand-in, which is used when that CUDA kernel cannot be used.Tests
tests/test_diffusion_int8_attention_triton33.py, rewritten:_rotatebodies present, withtl.joinonly in the default oneNot covered
triton-windows3.3 and ROCm 3.3 were not run. ROCm keeps the unchanged join source.