[NPU] Add NPU support for multi_token_attention#1122
Open
lowdy1 wants to merge 5 commits intolinkedin:mainfrom
Open
[NPU] Add NPU support for multi_token_attention#1122lowdy1 wants to merge 5 commits intolinkedin:mainfrom
lowdy1 wants to merge 5 commits intolinkedin:mainfrom
Conversation
Contributor
Author
Contributor
Author
|
softmax multi token attention |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
The current MTA kernel suffers from UB overflow issues and suboptimal benchmark performance. This PR introduces an NPU-optimized implementation of MTA to address these limitations.
The new implementation:
Fuses causal masking with Softmax and Sparsemax (both forward and backward)
Uses row-wise 1D processing to improve memory efficiency
Introduces a 3-axis masking kernel with UB-aware BLOCK_SIZE estimation for matrix masking
In terms of performance:
The fused softmax kernel shows lower performance than the benchmark mainly because of softmax kernel.
The sparsemax variant demonstrates better performance than the benchmark.
Testing Done
Tested passed with
python benchmark/scripts/benchmark_multi_token_attention.pypython benchmark/scripts/benchmark_sparse_multi_token_attention.pypytest -v test/transformers/test_multi_token_attention.pyHardware Type: Atlas 800I A2
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence