Repository navigation
Studio INT8 attention: verify the long-sequence kernel at install, fall back to the short one - #17796
Conversation
…ll back to the short one
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. What shall we delve into next? 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". |
…-long-config-probe # Conflicts: # studio/backend/core/inference/diffusion_int8_attention.py
…-long-config-probe # Conflicts: # studio/backend/core/inference/diffusion_int8_attention.py
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
[skip ci]
…on mode (diffusion red since #18004) (#18035) ## Summary #18004 (INT8 attention on by default) gave `quantise` and `_cuda_attention` in `core/inference/diffusion_int8_attention.py` a new `mode` argument. `studio/backend/tests/test_diffusion_int8_attention_long_probe.py` (from #17796) replaces both with CPU stand-ins that still take the old arguments. All 7 tests in the file fail on main, which makes `(Python 3.13, diffusion)` red for every PR based on `b2ad0b4493` or later: ``` TypeError: _fake_card.<locals>.quantise() takes from 4 to 5 positional arguments but 6 were given KeyError: 'long' assert (False) ``` The `KeyError` and the failed asserts follow from the same `TypeError`: the card check catches the error from the stand-in and reports a failed check, so the assertions about what it verified fail. With only the stand-ins updated, all 7 pass. The change in #18004 is fine. The test's fakes did not follow it. ## Change - The fake `quantise` takes `mode` (default `MODE_MAIN`), and the `_cuda_attention` stand-in becomes a function with the same parameters as the real one and passes `mode` through. - `_fake_card` now checks that each stand-in takes exactly the real function's parameters, by name. The next signature change then fails every test with `update the fake quantise: it takes [...]`, instead of a `TypeError` that the card check swallows and turns into confusing assertion failures. No production code changes. ## Verification - `tests/test_diffusion_int8_attention_long_probe.py`: 7 failed on main, 7 passed with this change. - Adding a parameter to the real `quantise` makes all 7 fail with the `update the fake quantise` message. - `tests/test_diffusion_int8*.py` and `tests/test_diffusion_attention*.py`: 1044 passed, 307 skipped.
Summary
Follow-up to #17769. Some INT8 attention kernel configs carry a
long_keys/longoverride (sm80 hd128 and sm89 hd64 switch towpc=8from 4608 keys; ROCm gfx1151 hd128 from 8000).select_configturns that into a second compiled kernel, but the install-time check never reached it: the accuracy probe uses about 1000 tokens and the race usesRACE_TOKENS = (4096, 1024). Two problems followed:_VERIFIED.exceptinint8_attention_impladded(index, head_dim)to_BROKEN. That also turned off the verified short kernel for the rest of the process.Changes
studio/backend/core/inference/diffusion_int8_attention.py:_long_check: when the card's config haslong_keys, the install check (_check, so alsoverdict) compiles and checks the long variant once per (card, head dim, dtype, impl). It runs eagerly, outside any capture, on the cheapest probe that selects it: batch 1, 2 heads, 1000 queries againstlong_keys + 100keys (the last key tile is ragged). The probe uses the same plain and sharp accuracy bars as the short check. A pass goes into_LONG_VERIFIED. The result shows up aslongin the verdict and instatus()["verdicts"], and the install log line getslong_ok=...._run: when no explicit config is passed, a call long enough for the long variant runs it only if that variant was verified (and has not failed since). Otherwise the call runs the short config. The short config is a valid kernel at any length, just slower on long calls, and the output is the same either way: the block shape does not change any output bit (test_long_overrides_do_not_change_the_output). An explicitconfig=is still run exactly as given.int8_attention_impl: a runtime failure in a call that ran the long variant now adds(index, head_dim, impl)to_LONG_BROKEN. That call runs native attention, and later long calls go back to the short kernel. A failure in a short-kernel call still marks(index, head_dim)broken, as before.okis unchanged.long_keysbehave exactly as before: no extra probe, no extra compile, same call path.Tests
New
studio/backend/tests/test_diffusion_int8_attention_long_probe.py(CPU, a faked sm89 card with the compile / launch mocked):kernel failed, native attention from here on)The existing INT8 suites (
test_diffusion_int8_attention.py,_dispatch,_triton_fallback,_rocm) pass on CPU on both trees: 126 passed, 93 skipped on this branch; main fails only the 4 new tests.GPU evidence (Colab L4 sm89 and A100 sm80, torch 2.14.1+cu130, main at f490069 vs this branch)
INT8 GPU suites (
test_diffusion_int8_attention.py,_dispatch,_triton_fallback, and the new file) on each card: 197 passed, 6 skipped on this branch. Main fails only the 4 new tests (193 passed). The 6 skips need two CUDA cards.The long variant is verified at install, as recorded in the verdict:
{'ok': True, 'keys': 4708, 'cos': 0.99996, 'rel_l1': 0.0077, 'sharp_cos': 0.9971},_LONG_VERIFIED = [(0, 64, bf16, cuda)]{'ok': True, 'keys': 4708, 'cos': 0.99996, 'rel_l1': 0.0081, 'sharp_cos': 0.9970},_LONG_VERIFIED = [(0, 128, bf16, cuda)]long_keys: no long verdict, no extra kernel.Output and per-call time through the registered op, bf16, 24 heads, 8 fresh processes in ABBA order (main head head main head main main head). The A/A noise is the spread across the 4 main runs:
Both trees run the same kernel (same
wpc) at every shape, the outputs are bit-identical, and every call engaged INT8. One row is above its A/A spread: A100 4608 / hd64, about 1 us per call. That config has nolong_keys, so the GPU work is the same kernel. On the host the only addition there is one dict lookup in_run.Install-time cost
Median of 3 fresh processes per arm. "Fresh driver cache" is a new
CUDA_CACHE_PATH; "warm driver cache" is a second process on the same path. "In-process" means the verdict caches were dropped but the compiled kernels kept, so it measures the probes only.This is a cost moved, not added, wherever a long call follows. On main, the first 4608-key call pays the long compile. For L4 hd64 that first call is 1258 to 1276 ms on main vs 1.7 ms on head with a fresh driver cache, and 30.8 ms vs 1.7 ms with a warm one. On A100 hd128 the first 4608-key call is 2112 to 6942 ms on main vs 1075 to 1100 ms on head. Both arms include about 1 s of first-op-call setup there, which also appears on cards without
long_keys. Cards and head dims withoutlong_keysdo not change (L4 hd128: 2162 vs 2159 ms; A100 hd64: 2225 vs 2239 ms). Only a process that never makes a call at or abovelong_keyspays the extra compile and gets nothing for it.With #17791's disk compile cache (now on main), measured on this head with a fresh driver cache and a fresh kernel cache per arm: the long compile moves from the first long call to install (L4 hd64: about 2330 ms vs 2360 ms total, first long call 840-853 ms down to 1.7 ms; A100 hd128: about 3325 ms vs 3375 ms, first long call 1785 ms down to about 1080 ms). What is added is the long accuracy probe itself, about 18 ms on L4 and 33 ms on A100, once per card, head dim and dtype per process.
Not covered
long_keyson the CUDA path).long_keys = 8000entry goes through the same_long_check/_runcode, but it was not run on AMD hardware here.