Skip to content

Conversation

@SS-JIA
Copy link
Contributor

@SS-JIA SS-JIA commented Sep 9, 2025

Stack from ghstack (oldest at bottom):

Context

As title; optimize the SDPA operator by introducing shaders to perform the operation in 3 steps:

  1. Compute attention weights, multiplying QT x K_cache, and applying scale and mask
  2. Compute softmax normalization of computed attention weights
  3. Compute final output by multiplying attention weights with V cache

This new implementation is much more efficient than the existing one, which performed slicing, repeat_interleave, and transposition of projected and cache tensors as separate steps. The fusion of scale and mask with the computation of attention weights also allows for the computation of elements within the mask region to be skipped.

Impact

Decode latency for LLMs is much improved. For llama 3.2 3B generating ~250 tokens, decode latency increases from ~15 tok/s to ~21.5 tok/s

Differential Revision: D82053493

## Context

As title; optimize the SDPA operator by introducing shaders to perform the operation in 3 steps:

1. Compute attention weights, multiplying QT x K_cache, and applying scale and mask
2. Compute softmax normalization of computed attention weights
3. Compute final output by multiplying attention weights with V cache

This new implementation is much more efficient than the existing one, which performed slicing, repeat_interleave, and transposition of projected and cache tensors as separate steps. The fusion of scale and mask with the computation of attention weights also allows for the computation of elements within the mask region to be skipped.

## Impact

Decode latency for LLMs is much improved. For llama 3.2 3B generating ~250 tokens, decode latency increases from ~15 tok/s to ~21.5 tok/s

Differential Revision: [D82053493](https://our.internmc.facebook.com/intern/diff/D82053493/)

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Sep 9, 2025

🔗 Helpful Links

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

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

❌ 2 New Failures, 37 Cancelled Jobs

As of commit 12b0f12 with merge base 245630a (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

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

SS-JIA pushed a commit that referenced this pull request Sep 9, 2025
## Context

As title; optimize the SDPA operator by introducing shaders to perform the operation in 3 steps:

1. Compute attention weights, multiplying QT x K_cache, and applying scale and mask
2. Compute softmax normalization of computed attention weights
3. Compute final output by multiplying attention weights with V cache

This new implementation is much more efficient than the existing one, which performed slicing, repeat_interleave, and transposition of projected and cache tensors as separate steps. The fusion of scale and mask with the computation of attention weights also allows for the computation of elements within the mask region to be skipped.

## Impact

Decode latency for LLMs is much improved. For llama 3.2 3B generating ~250 tokens, decode latency increases from ~15 tok/s to ~21.5 tok/s

Differential Revision: [D82053493](https://our.internmc.facebook.com/intern/diff/D82053493/)

ghstack-source-id: 308592117
Pull Request resolved: #14130
@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 Sep 9, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D82053493

@github-actions
Copy link

github-actions bot commented Sep 9, 2025

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.

## Context

As title; optimize the SDPA operator by introducing shaders to perform the operation in 3 steps:

1. Compute attention weights, multiplying QT x K_cache, and applying scale and mask
2. Compute softmax normalization of computed attention weights
3. Compute final output by multiplying attention weights with V cache

This new implementation is much more efficient than the existing one, which performed slicing, repeat_interleave, and transposition of projected and cache tensors as separate steps. The fusion of scale and mask with the computation of attention weights also allows for the computation of elements within the mask region to be skipped.

## Impact

Decode latency for LLMs is much improved. For llama 3.2 3B generating ~250 tokens, decode latency increases from ~15 tok/s to ~21.5 tok/s

Differential Revision: [D82053493](https://our.internmc.facebook.com/intern/diff/D82053493/)

[ghstack-poisoned]
SS-JIA pushed a commit that referenced this pull request Sep 9, 2025
Pull Request resolved: #14130

## Context

As title; optimize the SDPA operator by introducing shaders to perform the operation in 3 steps:

1. Compute attention weights, multiplying QT x K_cache, and applying scale and mask
2. Compute softmax normalization of computed attention weights
3. Compute final output by multiplying attention weights with V cache

This new implementation is much more efficient than the existing one, which performed slicing, repeat_interleave, and transposition of projected and cache tensors as separate steps. The fusion of scale and mask with the computation of attention weights also allows for the computation of elements within the mask region to be skipped.

## Impact

Decode latency for LLMs is much improved. For llama 3.2 3B generating ~250 tokens, decode latency increases from ~15 tok/s to ~21.5 tok/s
ghstack-source-id: 308621243
@exported-using-ghexport

Differential Revision: [D82053493](https://our.internmc.facebook.com/intern/diff/D82053493/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D82053493

## Context

As title; optimize the SDPA operator by introducing shaders to perform the operation in 3 steps:

1. Compute attention weights, multiplying QT x K_cache, and applying scale and mask
2. Compute softmax normalization of computed attention weights
3. Compute final output by multiplying attention weights with V cache

This new implementation is much more efficient than the existing one, which performed slicing, repeat_interleave, and transposition of projected and cache tensors as separate steps. The fusion of scale and mask with the computation of attention weights also allows for the computation of elements within the mask region to be skipped.

## Impact

Decode latency for LLMs is much improved. For llama 3.2 3B generating ~250 tokens, decode latency increases from ~15 tok/s to ~21.5 tok/s

Differential Revision: [D82053493](https://our.internmc.facebook.com/intern/diff/D82053493/)

[ghstack-poisoned]
SS-JIA pushed a commit that referenced this pull request Sep 10, 2025
Pull Request resolved: #14130

## Context

As title; optimize the SDPA operator by introducing shaders to perform the operation in 3 steps:

1. Compute attention weights, multiplying QT x K_cache, and applying scale and mask
2. Compute softmax normalization of computed attention weights
3. Compute final output by multiplying attention weights with V cache

This new implementation is much more efficient than the existing one, which performed slicing, repeat_interleave, and transposition of projected and cache tensors as separate steps. The fusion of scale and mask with the computation of attention weights also allows for the computation of elements within the mask region to be skipped.

## Impact

Decode latency for LLMs is much improved. For llama 3.2 3B generating ~250 tokens, decode latency increases from ~15 tok/s to ~21.5 tok/s
ghstack-source-id: 308660072
@exported-using-ghexport

Differential Revision: [D82053493](https://our.internmc.facebook.com/intern/diff/D82053493/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D82053493

@facebook-github-bot facebook-github-bot merged commit 711ccd8 into gh/SS-JIA/324/base Sep 10, 2025
246 of 288 checks passed
@facebook-github-bot facebook-github-bot deleted the gh/SS-JIA/324/head branch September 10, 2025 05:16
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. fb-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants