Repository navigation
Studio INT8 attention: skip the Triton path on NVIDIA Triton 3.3 (torch 2.7) - #17957
Merged
Merged
Conversation
…ch cannot compile its quantiser
Member
Author
|
@codex review |
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: Didn't find any major issues. Hooray! 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". |
danielhanchen
added a commit
that referenced
this pull request
Nov 16, 2026
…(rest red on main) (#17963) ## Summary `(Python 3.13, rest)` is red on main (seen on the staging runs of #17953 and #17957, base `bf7f6e050d`): ``` studio/backend/tests/test_video_ltx25_te_hosted.py::test_a_rejected_hosted_file_refuses_the_dense_fallback_without_room E Expected regex: 'needs about 24 GB' E Actual message: '... quantizing the dense encoder at load needs about 23.9 GB of free memory (8.0 GB free).' studio/backend/tests/test_video_ltx25_te_hosted.py::test_the_dense_fallback_room_check_prices_the_load_dtype[float32-30-True] E Expected regex: 'needs about 48 GB' E Actual message: '... needs about 47.8 GB of free memory (30.0 GB free).' ``` #17948 changed the LTX-2.5 dense text encoder refusal to print the need to one decimal, so it can no longer read "needs about 24 GB ... (24 GB free)" for a 24.3 GB need with 23.8 GB free. That is intended. It updated the same assertion in `test_video_hub_unreachable_cached_load.py` but not these two in `test_video_ltx25_te_hosted.py`, which still pin the old whole-GB text. ## Change Test only, `studio/backend/tests/test_video_ltx25_te_hosted.py`: - The hosted-file refusal pins the full one-decimal text: `needs about 23.9 GB of free memory (8.0 GB free)`. - The dtype pricing case derives the need from `LTX25_TE_BF16_GB` (a float32 load needs twice the bf16 encoder) and pins both figures to one decimal, so a change to the encoder size constant does not break it again while a return to whole-GB rounding still does. No product code changes; when a load is refused is unchanged. ## Testing - `test_video_ltx25_te_hosted.py`: 18 passed. On main the two tests above fail. - Sabotage: printing the need with `:.0f` again (the pre-#17948 rounding) fails both tests.
[skip ci]
danielhanchen
added a commit
that referenced
this pull request
Nov 16, 2026
…he gloo shard (2100 s cap) (#17969) ## Summary `Repo tests (CPU, gloo)` is timing out again: the shard's pytest runs under `timeout --signal=INT 2100` and recent runs were cut off there with nothing failing: | run | result | |---|---| | #17934 (upstream) | 257 passed, 3 skipped in 2089.55 s, exit 124 | | staging run of #17904 | 258 passed, 3 skipped in 2095.11 s, exit 124 | | staging run of #17957 | 251 passed, 1 failed in 2096.44 s, exit 124 | For comparison the same shard ran 241 tests in 1292 s when #17892 merged this morning. Since then #17886 (`test_tp_dpo_peft_ref_adapter_gloo.py`), #17930 (`test_cp_ulysses_media_towers_gloo.py`), `test_cp_ulysses_dynamic_len_gloo.py` and the DeepSeek-V4.1 additions to `test_parallel_deepseek_v41_gloo.py` landed in it, and a slower runner now goes over the cap. Every one of those tests passes; the shard just no longer fits. ## Change - `.github/workflows/studio-backend-ci.yml`: `tests/test_tp_[!n]*gloo*.py` (the non-native tensor parallel files: `tp_env`, `tp_eval`, `tp_full_finetune`, `tp_replica`, `tp_kv_replicated`, `tp_moe_dropout`, `tp_dpo_peft_ref_adapter`, ...; 12 files) moves out of `gloo` into a new `gloo-tp-env` shard. `gloo` keeps its other three globs (19 files). Comment added with the numbers above. - `tests/studio/test_backend_ci_parallel_isolation.py`: the command scan's expected counts go from 15 parallel runs / 10 repo-root shards to 16 / 11, as its message asks when a shard is added. ## Why that split Measured locally on main with the shard's exact command (`-n 4 --dist loadgroup`): 275 passed in 1302.83 s. Of the 40 slowest tests (2815 worker-seconds), 2716 s are in `tests/test_tp_[!n]*gloo*.py`; out of about 5200 worker-seconds in total, so these 12 files are well over half of the shard. Each half now has room under the cap on a slower runner. ## Testing - `tests/test_ci_repo_cpu_shards.py` (every repo test file collected by exactly one shard, every glob matches a file): 15 passed. - All 15 test files that read `studio-backend-ci.yml`: 341 passed, 3 skipped. - The new shard's first run on this PR is the timing check.
danielhanchen
added a commit
that referenced
this pull request
Nov 16, 2026
…ameter name (#17972) ## Summary `tests/test_cp_ulysses_media_towers_gloo.py::test_gemma4_with_towers_matches_one_process` (from #17930) has failed in four of the last gloo shard runs on unrelated PRs (staging runs of #17957, #17960, #17831 and #17966), always as: ``` E AssertionError: model.language_model.layers.0.self_attn.q_proj.weight ``` and it passes locally every time (5 of 5 standalone, and 53 of 53 with all five `test_cp_*gloo*.py` files in one process, so it is not state left by an earlier test in the worker). The assertion passes `msg = name`, which replaces torch's whole mismatch report with the parameter name, so the CI logs do not say how many elements are off or by how much. Without that there is no way to tell a float32 reduction-order difference on the CI runners' CPUs (a tolerance question) from a real context parallel gradient bug. ## Change Test only. The gradient `assert_close` calls in `test_cp_ulysses_media_towers_gloo.py` and `test_cp_ulysses_generic_gloo.py` pass `msg` as a callable that prefixes the parameter name to torch's report instead of replacing it: ``` model.language_model.layers.0.self_attn.q_proj.weight: Tensor-likes are not close! Mismatched elements: ... Greatest absolute difference: ... (up to ... allowed) Greatest relative difference: ... (up to ... allowed) ``` Tolerances are unchanged. The next CI failure will carry the numbers needed to decide whether the tolerance or the code is wrong. ## Testing - Both files (2-rank gloo, CPU): 24 passed. - The message form checked directly against `torch.testing.assert_close` (output above).
danielhanchen
added a commit
that referenced
this pull request
Nov 24, 2026
… (torch 2.7) (#19319) ## 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. - **The failure:** the Q / K rotation joins `(a + b, a - b)` with `tl.join`. On Triton 3.3, the `TritonGPURemoveLayoutConversions` pass 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 breaks `prep`, `kv` and `quant_rows` on every NVIDIA arch: sm80, sm86, sm89, sm100 and sm120. `attn` compiles. Triton 3.2 and 3.4+ compile the join. - **The fix:** on NVIDIA Triton 3.3 only, the rotation builds the same interleave with `tl.where` on a size-2 axis instead of `tl.join`. Every other Triton, ROCm included, keeps the existing source, so its compiled kernels and output bits do not change. - **Why two definitions instead of one with a `constexpr` switch:** the two `_rotate` bodies are separate definitions, picked in Python at import. Triton 3.2 and 3.3 leave a `constexpr` global's value out of `JITFunction.cache_key`. I checked this directly: the same source with `G = tl.constexpr(True)` and with `False` gives identical keys on 3.2.0 and 3.3.1, and different keys on 3.7.1. With one body behind a `constexpr` `if`, both variants would share one compiled kernel. - **Clearer fallback log:** when the kernel falls back to native attention, the log now gives the reason (`UNSLOTH_DIFFUSION_INT8_ATTENTION_IMPL=cuda`, Triton not installed, or no Triton config for `sm_XY head_dim=N`). It used to say only "no kernel for this card". The install log line also includes the verdict's error. - **Persisted probe key:** the key now reads the Triton version from `triton-windows`, `triton-rocm`, `triton-xpu`, `pytorch-triton-rocm`, `pytorch-triton` and `pytorch-triton-xpu` as well as `triton`. Before, it was `None` on Windows and ROCm wheels, so verdicts from different Triton versions shared one key there. NVIDIA Linux keys do not change (the `triton` distribution comes first). - **One re-race on Windows and ROCm:** saved INT8 attention verdicts there are invalidated once after upgrading, because the key now carries the Triton distribution version (`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 - **Old torch is a real install path:** `install.sh` installs 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.py` sets up the diffusion stack (torchao, diffusers) for torch 2.6 to 2.9. - **NVIDIA tries the CUDA kernel first:** on NVIDIA, Studio runs the CUDA (NVRTC) INT8 kernel and uses Triton only when that kernel cannot be built or loaded, or when `IMPL=triton` is 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. - **So this PR covers the fallback:** it restores the Triton stand-in on torch 2.7 for cards where the CUDA kernel fails at runtime, or where it is turned off. Studio still races the Triton path against native attention, so it only engages where it is faster. ## Evidence **CPU compile:** fresh `TRITON_CACHE_DIR` per run, all prep / kv / quant_rows / attn variants for head dims 64 and 128. | Triton | origin/main | this branch | |---|---|---| | 3.2.0 (torch 2.6) | 0 failures (sm80, sm89) | 0 failures (sm80, sm86, sm89) | | 3.3.1 (torch 2.7) | 120 failures of 200 (prep, kv, quant_rows on sm80 / 86 / 89 / 100 / 120) | 0 failures (sm80 / 86 / 89 / 90 / 100 / 120) | | 3.7.1 | 0 | 0 | **Studio's own `verdict()` (untimed accuracy check):** B200, torch 2.7.1+cu128, Triton 3.3.1, `IMPL=triton`, the sm89 Triton config. | arm | triton_available | implementation | verdict | |---|---|---|---| | origin/main | False | None | ok=False, "no kernel for this card" | | this branch | True | triton | ok=True, cos 0.999943, rel L1 0.00934 | | this branch, Triton 3.7.1 (control) | True | triton | ok=True, cos 0.999943, rel L1 0.00934 | **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. | shape (B, Sq, Sk, H, D) | arm | max abs vs fp32 | max abs / max ref | rel L1 vs fp32 | min row cos | rel L1 vs bf16 SDPA | |---|---|---|---|---|---|---| | Qwen-Image-2.1 1024 px (1, 4096, 4127, 32, 128) | 3.3.1 branch | 1.193e-2 | 1.644e-2 | 1.099e-2 | 0.999891 | 1.097e-2 | | | 3.7.1 current kernel | 1.193e-2 | 1.644e-2 | 1.099e-2 | 0.999891 | 1.099e-2 | | Wan2.2 5B 480p (1, 12090, 12090, 24, 128) | 3.3.1 branch | 4.246e-3 | 1.344e-2 | 1.111e-2 | 0.999910 | 1.110e-2 | | | 3.7.1 current kernel | 4.246e-3 | 1.344e-2 | 1.111e-2 | 0.999910 | 1.111e-2 | | Wan2.2 A14B 480p (1, 32760, 32760, 40, 128) | 3.3.1 branch | 2.323e-3 | 1.257e-2 | 1.109e-2 | 0.999924 | 1.109e-2 | | | 3.7.1 current kernel | 2.323e-3 | 1.257e-2 | 1.109e-2 | 0.999924 | 1.110e-2 | | LTX-2.5 audio (1, 126, 126, 32, 64) | 3.3.1 branch | 3.633e-2 | 9.655e-3 | 9.977e-3 | 0.999923 | 9.935e-3 | | | 3.7.1 current kernel | 3.633e-2 | 9.655e-3 | 9.977e-3 | 0.999923 | 9.928e-3 | For scale, bf16 SDPA vs fp32 on the same inputs has a rel L1 of 2.1e-3 to 2.3e-3. **Bits:** - The rotation alone (64x128, 64x64, 32x128, 128x64) is bit-identical to a torch reference on both Triton versions. - On 3.3.1 the join-free kernel's operands and outputs are bit-identical to the same join-free source on 3.7.1, on every shape. - Against the current join kernel on 3.7.1, K codes and both scale tensors are bit-identical. A few Q int8 codes differ by one at rounding ties: 21 of 16.8M for Qwen and 42 of 37.2M for Wan 5B. Against a float64 single-rounding reference, the join-free codes miss 40 and the join codes miss 59. The outputs differ by at most 9.8e-4, with the same error against fp32 to four digits. - Repeated calls are bit-identical on every arm. **Colab A100-40 (sm80) with the wheels `install.sh` picks 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. | shape | Triton 3.3.1 (join-free) vs Triton 3.2.0 (join) | max abs vs fp32 | rel L1 vs fp32 | min row cos | rel L1 vs bf16 SDPA | |---|---|---|---|---|---| | Qwen-Image-2.1 1024 px | outputs and int8 operands bit-identical | 7.256e-3 | 1.109e-2 | 0.999923 | 1.107e-2 | | Wan2.2 5B 480p | bit-identical | 4.568e-3 | 1.114e-2 | 0.999918 | 1.113e-2 | | Wan2.2 A14B 480p | bit-identical | 3.655e-3 | 1.112e-2 | 0.999919 | 1.111e-2 | | LTX-2.5 audio (head dim 64) | bit-identical | 4.401e-2 | 1.002e-2 | 0.999926 | 9.987e-3 | | 1039 tokens, head dim 64 | bit-identical | 1.848e-2 | 1.037e-2 | 0.999921 | 1.034e-2 | 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:** | torch / Triton | arm | IMPL | serves | verdict | |---|---|---|---|---| | 2.7.1 / 3.3.1 | origin/main | triton | None | ok=False, "no kernel for this card" | | 2.7.1 / 3.3.1 | this branch | triton | triton | ok=True, cos 0.999945, rel L1 0.00914 | | 2.7.1 / 3.3.1 | both | auto | cuda | ok=True, cos 0.999925 | | 2.6.0 / 3.2.0 | both | triton | triton | ok=True, cos 0.999945 (same as 3.3.1 branch) | | 2.6.0 / 3.2.0 | both | auto | cuda | ok=True, cos 0.999925 | 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: - version gate (NVIDIA 3.3 only; not ROCm 3.3, 3.2, 3.4, 3.7, 3.10 or unparsable versions) - both `_rotate` bodies present, with `tl.join` only in the default one - the reloaded module picks the right body for its Triton - probe-key Triton version for each distribution name - keys differ across Triton versions - decline reasons and the no-kernel verdict message - Related CPU suites: 539 passed. 5 tests fail the same way on origin/main (diffusers / dynamo device import on a CPU host). ## Not covered - No render timing. The Triton path's speed on Triton 3.3 against native attention is not measured here. The existing per-card race decides whether it engages, and a slower stand-in keeps native attention. - No sm89 (L4) or sm120 (G4) run on a real card; those archs only have the CPU compile. Windows `triton-windows` 3.3 and ROCm 3.3 were not run. ROCm keeps the unchanged join source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On NVIDIA with torch 2.7 (Triton 3.3), the Triton INT8 attention kernel cannot compile: Triton 3.3 rejects the Q / K rotation's
tl.joinonce the quantiser's int8 stores are vectorised ("'tt.join' op failed to infer returned types"). Triton 3.2 and 3.4+ compile the same code, and ROCm's Triton 3.3 backend lowers it. Today Studio attempts the compile, it fails, and the call falls back to native attention after the failed compile.triton_available()now reports the Triton path unavailable on NVIDIA Triton 3.3.x, so Studio goes straight to the CUDA INT8 kernel (where it serves) or native attention. Every other Triton version, ROCm builds, and an unparsable version string are unchanged.Why not make it compile
A column-wise rewrite of the quantiser that avoids the join does compile on 3.3 and gives the same bits (checked on L4, A100 and G4, quantised operands bit-identical, fp64 oracle exact), but on Triton 3.3 the whole call is still 1.3 to 2.9x slower than native SDPA because of the attention kernel's 3.3 codegen. Studio's per-card speed race would keep native there anyway, so it was not worth about 200 lines of kernel code.
Tests
tests/test_diffusion_int8_attention_triton33.py: Triton 3.3.0 / 3.3.1 on NVIDIA report unavailable; 3.3.1 on ROCm, 3.2, 3.4, 3.7 and an unparsable version stay available; no Triton stays unavailable. The two Triton 3.3 NVIDIA cases fail on main.tests/test_diffusion_int8_attention.pypasses unchanged.GPU evidence (Colab L4 / A100 / G4, torch 2.7.1 + Triton 3.3.1, main)