Repository navigation
Studio ROCm: tell self from cross attention without guarding the query length on the key length - #15458
Conversation
…y length on the key length Under torch.compile(dynamic=True), comparing the key and query lengths to detect self / joint attention added a q.size(1) != kv guard for cross attention: an extra graph when the query length hits the key length, and a marked dynamic query range spanning it raised ConstraintViolationError. Use statically_known_true where Dynamo traces it in graph (no guard); torch 2.6 keeps the direct comparison.
|
@codex review |
Codex Review SummaryThis 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 SummaryThis 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. Bravo. 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". |
#14869 added
joint = kv == seqto_rocm_flash_length_reasoninstudio/backend/core/inference/diffusion_attention.py, to tell self / joint attention (one length symbol) from cross attention. In a traced graph, cross attention has independent query and key length symbols, and evaluating that comparison makes Dynamo install a guard on it, for exampleL['q'].size()[1] != 6000. Two things follow:ConstraintViolationError.The traced path now asks
statically_known_true(kv == seq). Self / joint attention shares one symbol, so it is still treated as joint, and cross attention no longer gets a guard.statically_known_trueis resolved outside tracing when the dispatch guard installs, and is used only when this torch's Dynamo traces it in graph (torch 2.10, 2.13, 2.14). On torch 2.6, Dynamo cannot trace it, so the direct comparison stays there, guard included. The stored-bucket reuse for self attention from #14869 depends on that comparison.Cross attention, key length 6000, query lengths 5000 / 6000 / 7000 / 5500 (same admitted bucket),
torch.compile(dynamic=True, fullgraph=True), kernels stubbed, CPU:ConstraintViolationErrorConstraintViolationErrorTwo tests in
test_diffusion_attention_rocm_flash.pycover both checks. They are skipped on a torch whose Dynamo cannot tracestatically_known_true. The file gives 2 failed, 191 passed on main and 193 passed with this PR (torch 2.13). Nothing here ran on ROCm hardware.