-
Notifications
You must be signed in to change notification settings - Fork 713
Arm backend: Add support for single input matmul #10654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
AnnotateDecomposedMatmul makes sure that a decomposed matmul will two
dq-nodes before and a q-node after it's mm/bmm-node. Previously it
assumed that the partition always had two input nodes (two dq-nodes),
but this is not the case for a single input matmul, e.g.
torch.matmul(x, x). In such a case we must copy the dq-node and insert
it before the mm/bmm's two inputs.
Before pass:
-> expand -> view ->
/ \
x -> dq bmm -> view -> q
\ /
-> expand -> view ->
After pass:
-> expand -> view -> dq
/ \
x bmm -> q -> view
\ /
-> expand -> view -> dq
Signed-off-by: Oscar Andersson <[email protected]>
Change-Id: I5ac381ccd712a535736fa16d1ee864dc76ae2b30
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/10654
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 2 New FailuresAs of commit aedd502 with merge base e88aafc ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
MacOS fails is unrelated |
zingo
approved these changes
May 5, 2025
YufengShi-dudu
added a commit
to YufengShi-dudu/executorch
that referenced
this pull request
Sep 26, 2025
- ConvertMmToBmmPass converts an MM node to BMM nodes, turns input
and output tensors from rank-2 to rank-3 via unsqueeze/squeeze,
and inserts q-dq before and after BMM node when necessary.
- After ConvertMmToBmmPass:
x -> q -> dq -> unsqueeze -> q_2 -> dq_2 ->
\
bmm -> q_4 -> dq_4
/
y -> q_1 -> dq_1 -> unsqueeze -> q_3 -> dq_3 ->
- Therefore, if the original matmul was 2D, the bmm already has
DQ nodes on its inputs and Q node on its output.
If AnnotateDecomposedMatmulPass (pytorch#10654) is still applied in
this case, it produces illegal sequences such as:
x -> q -> unsqueeze -> q_2 (invalid)
- Fix by checking whether the BMM is already surrounded by DQ nodes
on its inputs and Q nodes on its output.
Change-Id: I9949d59b0b4a96fa34a88b0734014567ea6f24cc
Signed-off-by: Yufeng Shi <[email protected]>
Co-authored-by: Oscar Andersson <[email protected]>
zingo
pushed a commit
that referenced
this pull request
Oct 6, 2025
- ConvertMmToBmmPass converts an MM node to BMM nodes, turns input and
output tensors from rank-2 to rank-3 via unsqueeze/squeeze, and inserts
q-dq before and after BMM node when necessary.
- After ConvertMmToBmmPass:
```
x -> q -> dq -> unsqueeze -> q_2 -> dq_2 ->
\
bmm -> q_4 -> dq_4
/
y -> q_1 -> dq_1 -> unsqueeze -> q_3 -> dq_3 ->
```
- Therefore, if the original matmul was 2D, the bmm already has DQ nodes
on its inputs and Q node on its output. If AnnotateDecomposedMatmulPass
(#10654) is still applied in this case, it produces illegal sequences
such as: x -> q -> unsqueeze -> q_2 (invalid)
- Fix by checking whether the BMM is already surrounded by DQ nodes on
its inputs and Q nodes on its output.
Change-Id: I9949d59b0b4a96fa34a88b0734014567ea6f24cc
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218
Signed-off-by: Yufeng Shi <[email protected]>
Co-authored-by: Oscar Andersson <[email protected]>
pytorchbot
pushed a commit
that referenced
this pull request
Oct 7, 2025
- ConvertMmToBmmPass converts an MM node to BMM nodes, turns input and
output tensors from rank-2 to rank-3 via unsqueeze/squeeze, and inserts
q-dq before and after BMM node when necessary.
- After ConvertMmToBmmPass:
```
x -> q -> dq -> unsqueeze -> q_2 -> dq_2 ->
\
bmm -> q_4 -> dq_4
/
y -> q_1 -> dq_1 -> unsqueeze -> q_3 -> dq_3 ->
```
- Therefore, if the original matmul was 2D, the bmm already has DQ nodes
on its inputs and Q node on its output. If AnnotateDecomposedMatmulPass
(#10654) is still applied in this case, it produces illegal sequences
such as: x -> q -> unsqueeze -> q_2 (invalid)
- Fix by checking whether the BMM is already surrounded by DQ nodes on
its inputs and Q nodes on its output.
Change-Id: I9949d59b0b4a96fa34a88b0734014567ea6f24cc
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218
Signed-off-by: Yufeng Shi <[email protected]>
Co-authored-by: Oscar Andersson <[email protected]>
(cherry picked from commit 9a7fb42)
GregoryComer
pushed a commit
that referenced
this pull request
Oct 7, 2025
- ConvertMmToBmmPass converts an MM node to BMM nodes, turns input and
output tensors from rank-2 to rank-3 via unsqueeze/squeeze, and inserts
q-dq before and after BMM node when necessary.
- After ConvertMmToBmmPass:
```
x -> q -> dq -> unsqueeze -> q_2 -> dq_2 ->
\
bmm -> q_4 -> dq_4
/
y -> q_1 -> dq_1 -> unsqueeze -> q_3 -> dq_3 ->
```
- Therefore, if the original matmul was 2D, the bmm already has DQ nodes
on its inputs and Q node on its output. If AnnotateDecomposedMatmulPass
(#10654) is still applied in this case, it produces illegal sequences
such as: x -> q -> unsqueeze -> q_2 (invalid)
- Fix by checking whether the BMM is already surrounded by DQ nodes on
its inputs and Q nodes on its output.
Change-Id: I9949d59b0b4a96fa34a88b0734014567ea6f24cc
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218
Signed-off-by: Yufeng Shi <[email protected]>
Co-authored-by: Yufeng Shi <[email protected]>
Co-authored-by: Oscar Andersson <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ciflow/trunk
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
partner: arm
For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm
topic: not user facing
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
AnnotateDecomposedMatmul makes sure that a decomposed matmul will two dq-nodes before and a q-node after it's mm/bmm-node. Previously it assumed that the partition always had two input nodes (two dq-nodes), but this is not the case for a single input matmul, e.g. torch.matmul(x, x). In such a case we must copy the dq-node and insert it before the mm/bmm's two inputs.
cc @digantdesai @freddan80 @per @zingo