Skip to content

Use symmetric per-query windows for CUDA DFlash attention (#25644) - #25644

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
psiddh:export-D133915608
Nov 24, 2026
Merged

meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
psiddh:export-D133915608

Conversation

@psiddh

@psiddh psiddh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

DFlash's sliding attention mask now uses strict per-query distance, abs(query_position - key_position) < window. The CUDA sequence export still selected the older shared-context/whole-block mode, and cell-cache draft masks used the same old assumption. This produced numerically different attention from the model.

Add an explicit trailing symmetric_window option to the CUDA kernel and thread it through sequence manifests and lowering. CUDA DFlash export selects it, while ordinary one-sided windows and the documented legacy context_window mode retain their defaults and behavior. Apply the same strict per-query mask to cell-cache draft rows, preserving causal, warmup, ownership, placement and rewind behavior.

Keep the production model mask unchanged. Original comparisons retain their tolerances and use the mode selected by production export; extend coverage for exact boundaries, block sizes at least the window, ring wraps, graph replay, dynamic lengths and lowered KV execution. Existing compiled CUDA sequence artifacts must be re-exported to select the new mode; cell-layout consumers need the updated native runtime.

Reviewed By: Gasoonjia

Differential Revision: D133915608

Copilot AI balanced review requested due to automatic review settings November 24, 2026 01:02
@pytorch-bot

pytorch-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25644

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⏳ No Failures, 11 Pending

As of commit 5b7ea76 with merge base d0a9d13 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 24, 2026
@meta-codesync

meta-codesync Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@psiddh has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133915608.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Gasoonjia Gasoonjia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-codesync meta-codesync Bot changed the title Use symmetric per-query windows for CUDA DFlash attention Use symmetric per-query windows for CUDA DFlash attention (#25644) Nov 24, 2026
psiddh added a commit to psiddh/executorch that referenced this pull request Nov 24, 2026
)

Summary:

DFlash's sliding attention mask now uses strict per-query distance, `abs(query_position - key_position) < window`. The CUDA sequence export still selected the older shared-context/whole-block mode, and cell-cache draft masks used the same old assumption. This produced numerically different attention from the model.

Add an explicit trailing `symmetric_window` option to the CUDA kernel and thread it through sequence manifests and lowering. CUDA DFlash export selects it, while ordinary one-sided windows and the documented legacy `context_window` mode retain their defaults and behavior. Apply the same strict per-query mask to cell-cache draft rows, preserving causal, warmup, ownership, placement and rewind behavior.

Keep the production model mask unchanged. Original comparisons retain their tolerances and use the mode selected by production export; extend coverage for exact boundaries, block sizes at least the window, ring wraps, graph replay, dynamic lengths and lowered KV execution. Existing compiled CUDA sequence artifacts must be re-exported to select the new mode; cell-layout consumers need the updated native runtime.

Reviewed By: Gasoonjia

Differential Revision: D133915608
Copilot AI balanced review requested due to automatic review settings November 24, 2026 01:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

)

Summary:

DFlash's sliding attention mask now uses strict per-query distance, `abs(query_position - key_position) < window`. The CUDA sequence export still selected the older shared-context/whole-block mode, and cell-cache draft masks used the same old assumption. This produced numerically different attention from the model.

Add an explicit trailing `symmetric_window` option to the CUDA kernel and thread it through sequence manifests and lowering. CUDA DFlash export selects it, while ordinary one-sided windows and the documented legacy `context_window` mode retain their defaults and behavior. Apply the same strict per-query mask to cell-cache draft rows, preserving causal, warmup, ownership, placement and rewind behavior.

Keep the production model mask unchanged. Original comparisons retain their tolerances and use the mode selected by production export; extend coverage for exact boundaries, block sizes at least the window, ring wraps, graph replay, dynamic lengths and lowered KV execution. Existing compiled CUDA sequence artifacts must be re-exported to select the new mode; cell-layout consumers need the updated native runtime.

Reviewed By: Gasoonjia

Differential Revision: D133915608
Copilot AI balanced review requested due to automatic review settings November 24, 2026 07:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@meta-codesync
meta-codesync Bot merged commit 5f6a523 into pytorch:main Nov 24, 2026
306 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants