Skip to content

Studio ROCm: tell self from cross attention without guarding the query length on the key length - #15458

Merged
danielhanchen merged 2 commits into
mainfrom
fix/diffusion-attn-joint-guard
Oct 27, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/diffusion-attn-joint-guard

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

#14869 added joint = kv == seq to _rocm_flash_length_reason in studio/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 example L['q'].size()[1] != 6000. Two things follow:

  • Cross attention whose query length crosses the key length recompiles even though the routing bucket is unchanged.
  • A query length marked dynamic over a range that spans the key length fails with 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_true is 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:

torch check before #14869 main this PR
2.13 cumulative graphs 1, 1, 1, 1 1, 2, 2, 2 1, 1, 1, 1
2.13 query marked dynamic [4500, 7500], key static compiles ConstraintViolationError compiles
2.14 cumulative graphs 1, 1, 1, 1 1, 2, 2, 2 1, 1, 1, 1
2.14 marked dynamic compiles ConstraintViolationError compiles

Two tests in test_diffusion_attention_rocm_flash.py cover both checks. They are skipped on a torch whose Dynamo cannot trace statically_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.

…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T00:19:47.664033Z 47d240e Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T00:18:36.526069Z 47d240e PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 47d240e284

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 88ff2b0 into main Oct 27, 2026
37 of 43 checks passed
@danielhanchen
danielhanchen deleted the fix/diffusion-attn-joint-guard branch October 27, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant