Skip to content

Conversation

@shewu-quic
Copy link
Collaborator

@shewu-quic shewu-quic commented Jul 23, 2025

Summary:

  • Add a unit test for masked softmax
  • Add amin op support
  • Add a flag --enable_masked_softmax to enable masked softmax feature.
    It is designed to optimize the LLMs accuracy and performance executed on HTP backend. MaskedSoftmax is used to replace the Softmax(Add(In, Mask)) structure in attention block in LLMs during backend optimization. For more details, please refer to QNN documents.
    Note that it is only supported starting from QNN 2.35.

cc: @haowhsu-quic , @winskuo-quic

@shewu-quic shewu-quic requested a review from cccclai as a code owner July 23, 2025 06:25
@pytorch-bot
Copy link

pytorch-bot bot commented Jul 23, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit cf02afa with merge base 45846c8 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@facebook-github-bot facebook-github-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 Jul 23, 2025
@shewu-quic
Copy link
Collaborator Author

@pytorchbot label "release notes: qualcomm"

@pytorch-bot pytorch-bot bot added the release notes: qualcomm Changes to the Qualcomm backend delegate label Jul 23, 2025
@shewu-quic
Copy link
Collaborator Author

shewu-quic commented Jul 23, 2025

Hi @cccclai,

This PR enables the new "MaskedSoftmax" feature for LLM on the HTP backend. MaskedSoftmax is used to replace specific patterns, such as the Softmax(Add(In, Mask)) structure. It is supported staring from QNN 2.35. Since this is a backend optimization, we need to check optrace to confirm if it is successfully enabled. I have evaluated its performance on story llama and llama 3.2 1/3B, and it shows a slight improvement in TTFT and token generation rate.

image

raise RuntimeError(f"Using an unknown kv update {args.kv_updater}")

if args.enable_masked_softmax and is_qnn_sdk_version_less_than("2.35"):
logging.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

Great! Is there a way to query the qnn sdk version? Just in case weird behavior if users didn't notice the warnning

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we can use QnnBackend_getBuildid to query the sdk version from QNN SDK.
Let me think how to integrate this API in pybind.
image

Summary:
- Add a unit test for masked softmax
- Add amin op support
- Add a flag `--enable_masked_softmax` to enable masked softmax feature.
  It is designed to optimize the LLMs accuracy and performance executed on HTP backend. MaskedSoftmax is used to replace the Softmax(Add(In, Mask)) structure in attention block in LLMs during backend optimization.
For more details, please refer to QNN documents.
Note that it is only supported starting from QNN 2.35.
@shewu-quic shewu-quic force-pushed the dev1/hutton/enable_masked_softmax branch from 2c88338 to cf02afa Compare July 28, 2025 04:57
@shewu-quic
Copy link
Collaborator Author

Hi @cccclai, I have updated the API to get sdk version. Does it look good now?

Copy link
Contributor

@cccclai cccclai left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you

@facebook-github-bot
Copy link
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this in D79106663.

@cccclai cccclai merged commit 8b2ddb2 into pytorch:main Jul 29, 2025
100 of 101 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. release notes: qualcomm Changes to the Qualcomm backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants