Repository navigation
Studio INT8 attention and GEMM: CFG replicas keep the sink mode, strided cuDNN admits only the probed dtype, fused int8 takes plain SYMMETRIC only, _int_mm fallback stays on the operand's card - #18140
Merged
Conversation
…e under its own name The StridedCudnn marker kept only the probed card ids, so a bf16 probe also sent fp16 calls (an autocast or a later cast of the pipe) down the strided path. The marker now carries the probed dtype, plain_qkv declines other dtypes, and a re-install at a new dtype probes that dtype instead of keeping the old marker. The INT8 dispatch race named the strided incumbent dispatch:_native_cudnn, the same key as the contiguous cuDNN call, so verdicts cached for one were reused for the other. It now races as dispatch:_native_cudnn:strided. The GPU no-copy check asserted flatten(2, 3).is_contiguous(), which also holds when flatten copies; it now checks the output is contiguous and the flatten shares its storage.
…ETRIC weights only _plain_int8_weight accepted any mapping containing SYMMETRIC, so a torchao weight with SYMMETRIC_NO_CLIPPING_ERR activation quant reached kernels that always divide amax by 127.5 (torchao 0.17 codes and scales differ for that mode). Studio's own loaders only build SYMMETRIC weights, so this only narrows a path no Studio load takes. The new test fails on main.
…iews, not copies No test checked the no-copy claim of #17180: putting diffusers' .contiguous() copies back into the strided call passed every test. The new test spies on scaled_dot_product_attention and asserts Q / K / V arrive as the permuted (non-contiguous) views; it fails with the copies restored and passes on main.
… replicas) Int8Route.__reduce__ rebuilt the route from its constructor arguments only, so copy.deepcopy (Studio's CFG replica builder), copy.copy and pickle reset the sink kernel mode chosen by _install to 0. The replica's attention then ran the plain INT8 path while the source ran the sink path. The reduce tuple now carries the mode as state; the new test fails on main for modes 1 and 2.
… card For K or N not a multiple of 8 the safe _int_mm wrapper (Studio and core copies, inherited from torchao) ran the matmul on the CPU and moved the result with .to(input.device.type), which is the current card. With the operands on cuda:1 and cuda:0 current the int32 result landed on cuda:0. It now moves back to input.device. The new test fails on main.
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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
This was referenced Nov 17, 2026
danielhanchen
added a commit
that referenced
this pull request
Nov 20, 2026
…rd times (#18584) #18140 gave a strided cuDNN incumbent its own INT8 race verdict name, `dispatch:_native_cudnn:strided`, because the strided call differs from diffusers' contiguous `_native_cudnn` call. But the name was taken from the marker's class alone. The marker only takes the strided call on the cards it probed and at the dtype it probed; on any other card or dtype `plain_qkv` declines and the race times diffusers' call. The dispatch install races each module on the load card and on every secondary card (layer split, CFG replica), so a marker for `{0}` raced on `cuda:1` timed the contiguous call and cached that verdict as `cuda:1 ... :strided`. A marker for `{0, 1}` then read that verdict on `cuda:1`, although its real call there is the strided one, and the reverse order had the same mix-up. The INT8 token floor on that card could then come from a different incumbent call than the one the route replaces. ## Change `_race_name` in `diffusion_int8_attention_dispatch.py` takes optional `card` and `dtype` and keeps the `:strided` suffix only when the marker's `cards` contains the card and its probed dtype matches (or is unset). Elsewhere it returns the plain `dispatch:_native_cudnn` name, so those races share the verdict of the call they actually time. The dispatch install computes the name per raced card with the race dtype. Called without the new arguments, `_race_name` returns what it did before, and the persisted verdict names are unchanged. ## Tests New `tests/test_diffusion_int8_attention_strided_race_key.py`, CPU only: - `test_strided_race_name_follows_the_call_the_card_times`: a `{0}` bf16 marker is `:strided` on card 0 at bf16, plain on card 1 and plain at fp16; a `{0, 1}` marker is `:strided` on card 1. Fails on main, passes here. - `test_dispatch_race_keys_each_card_by_its_timed_call` (3 cases): runs the real dispatch install with a load card and a secondary card, records the verdict name each card races under. `{0}` bf16 gives strided on 0 and plain on 1; `{0, 1}` fp16 under a bf16 load gives plain on both. Both fail on main (every card raced as `:strided`) and pass here. `{0, 1}` bf16 gives strided on both and passes on main and here. Differential (`test_differential.py`, the new file plus `test_diffusion_int8_attention_persisted.py` and `test_diffusion_int8_attention_dispatch.py`): DISCRIMINATING, fixed=3, unchanged=68, head_fail=0. Suite (`test_diffusion_qwenimage21_strided_attn.py`, `test_diffusion_flux3_strided_attn.py`, `test_diffusion_int8_attention_auto.py`, `test_diffusion_int8_attention_dispatch.py`, `test_diffusion_int8_attention_persisted.py`, `test_diffusion_attention.py`, `test_diffusion_attention_honest_status.py`, `test_diffusion_attention_cudnn_head_dim.py`): main 272 passed, 1 skipped, 1 failed; this branch 276 passed (the 4 new), 1 skipped, 1 failed. The failing ID is the same on both, `test_diffusion_qwenimage21_strided_attn.py::test_attention_hook_installs_on_cudnn_pins`, which greps moved source and is fixed separately. ## Not proven here No GPU run. The tests stub the race, so they show which name each card is raced under, not a changed token floor on real hardware. That would take Qwen-Image-2.1 with a cuDNN pin split across two NVIDIA cards, with the strided probe passing on only one of them, comparing the per-card `diffusion.int8_attention` race log lines on main and here.
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.
Fixes from a re-check of recent Studio INT8 kernel PRs.
Int8Route.__reduce__(studio/backend/core/inference/diffusion_int8_attention_dispatch.py) rebuilt the route from its constructor arguments only, socopy.deepcopy(Studio's CFG-parallel replica builder),copy.copyand pickle reset the sink kernel mode chosen at install to 0. With CFG split across two cards, the replica ran the plain INT8 path while the primary ran the sink path, so the guided output depended on the card count. The reduce tuple now carries the mode as state.StridedCudnnmarker kept only the probed card ids, so a bf16 probe also sent fp16 calls (an autocast, or a later cast of the pipe) down the strided path. The marker now carries the probed dtype,plain_qkvdeclines other dtypes, and a re-install at a new dtype probes that dtype. The INT8 dispatch race named the strided incumbentdispatch:_native_cudnn, the same key as the contiguous cuDNN call, so cached verdicts crossed over; it now races asdispatch:_native_cudnn:strided. The GPU no-copy check assertedflatten(2, 3).is_contiguous(), which also holds when flatten copies; it now checks the flatten shares storage._plain_int8_weightaccepted any mapping containing SYMMETRIC, so a torchao weight withSYMMETRIC_NO_CLIPPING_ERRactivation quant reached kernels that always divide amax by 127.5. Studio's own loaders build plain SYMMETRIC only, so this narrows a path no Studio load takes._int_mmoff-grid fallback returns on the operand's card (Studio int8: keep torchao's transposed weight in the TN layout for _int_mm (fixes an illegal memory access on L4) #17613, inherited from torchao). For K or N not a multiple of 8 the safe_int_mmwrapper (Studiodiffusion_torchao_patches.pyand the copy inunsloth/import_fixes.py) ran the matmul on the CPU and moved the result with.to(input.device.type), which is the current card. With the operands on cuda:1 and cuda:0 current, the int32 result landed on cuda:0. It now moves back toinput.device..contiguous()copies passed every test. The new test spies onscaled_dot_product_attentionand asserts Q / K / V arrive as the permuted views. Test only.GPU results, base (main 62d66cb) vs this branch
CFG sink mode, Kaggle 2x T4 (sm75), torch 2.11.0+cu130, diffusers 0.42.1. Tiny FLUX.1 transformer with random weights at the real head dim (128), fp16, one attention-sink key; Studio's
CfgParallelRouterwith the replica built bybuild_replicaon cuda:1; INT8 attention installed with the sink kernels (mode 2, NVRTC CUDA kernel) on both cards; guided 3-step render, cond on cuda:0 and uncond on the replica._int_mmfallback, same Kaggle 2x T4: int8 operands on cuda:1, cuda:0 current, both copies of_make_safe_int_mmwith the realout_dtype.L4 (sm89), Colab, torch 2.12.1+cu130, cuDNN 9.20.0, torchao 0.17.0:
SYMMETRIC_NO_CLIPPING_ERRweightsTests
studio/backend/tests/test_diffusion_int8_attention_dispatch.py::test_route_copies_keep_the_sink_mode[1|2]: fails on main.test_diffusion_int8_attention_dispatch.pybase 2 failed (test_route_copies_keep_the_sink_mode[1|2]) / 46 passed, this branch 48 passed with the two-card tests included.studio/backend/tests/test_torchao_int_mm_transposed.py::test_off_grid_fallback_returns_on_the_operand_card: fails on main; on the T4 pair base 1 failed / 9 passed, this branch 10 passed (including the CUDA transposed_int_mmexactness cases).studio/backend/tests/test_diffusion_qwenimage21_strided_attn.py:test_marker_admits_only_its_probed_dtype,test_reinstall_at_a_new_dtype_probes_it,test_strided_incumbent_races_under_its_own_namefail on main; on the L4 base 3 failed / 14 passed, this branch 17 passed, and the GPU bitwise test ran in both arms.studio/backend/tests/test_diffusion_int8_fused.py::test_only_plain_symmetric_activation_quant_is_eligible[SYMMETRIC_NO_CLIPPING_ERR-False]: fails on main; on the L4 this branch 101 passed / 1 skipped (a torchao >= 0.18 case).studio/backend/tests/test_diffusion_flux3_strided_attn.py::test_strided_processor_hands_sdpa_the_projection_views: passes on main, fails with the copies restored.test_real_processor_decode_call_takes_the_strided_pathhits a RecursionError on main and on this branch alike (test-order interaction, not touched here).Not covered
_int_mmchecks on T4 only.