Skip to content

Conversation

manuelcandales
Copy link
Contributor

Adds bfloat16/float32 working implementations of the following AOTI shim ops:

  • aoti_torch_mps_mm_out
  • aoti_torch_mps_convolution
  • aoti_torch_mps__scaled_dot_product_attention_math_for_mps

Adds a stub implementation of aoti_torch_mps_addmm_out

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Oct 10, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit 4367977 with merge base 6e0c9f6 (image):

NEW FAILURE - The following job has failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

[ghstack-poisoned]
* ExecutorTorch implementation of aoti_torch_mps_mm_out.
* Performs simple matrix multiplication: out = self @ mat2
*/
AOTITorchError aoti_torch_mps_mm_out(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does custom ops use caching mechanism like the ETMetalShaderLibrary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, not yet. These fallback ops are implemented using MPSGraph, so, here we would be caching the graph. This is something I want to look into later when optimizing performance. But this deserves time. In particular, since I never understood why MPSGraph operations have a non-trivial CPU overhead in PyTorch, in spite of PyTorch having a caching mechanism for MPSGraphs.

Comment on lines +1182 to +1183
// For attention weights, zero-fill the GPU buffer (shared memory allows CPU memset)
std::memset(attn_contents_ptr, 0, attn_size_bytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need zero filling here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I though it was nicer to return 0, rather than some random stuff.


// Set output tensor handles
*ret0 = out_tensor_handle;
*ret1 = attn_tensor_handle;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is ret1 actually populated or just zerod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just zeroed.
We are using MPSGraph's scaledDotProductAttention which only returns the output tensor.
We need to return an attention tensor because we need to match _scaled_dot_product_attention_math_for_mps signature. But we don't really need it, it gets thrown away here

[ghstack-poisoned]
[ghstack-poisoned]
@manuelcandales manuelcandales added the release notes: none Do not include this in the release notes label Oct 13, 2025
[ghstack-poisoned]
[ghstack-poisoned]
manuelcandales added a commit to manuelcandales/executorch-1 that referenced this pull request Oct 14, 2025
Adds bfloat16/float32 working implementations of the following AOTI shim ops:
 - aoti_torch_mps_mm_out
 - aoti_torch_mps_convolution
 - aoti_torch_mps__scaled_dot_product_attention_math_for_mps

 Adds a stub implementation of aoti_torch_mps_addmm_out


ghstack-source-id: 61b8cc4
ghstack-comment-id: 3392300522
Pull-Request: pytorch#15023
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
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: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants