Skip to content

Conversation

manuelcandales
Copy link
Contributor

@manuelcandales manuelcandales commented Oct 22, 2025

This pull request refactors the Metal backend's stream commit logic and improves memory management for MPSGraph operations. The most significant changes are the rewrite of the "commit" SyncType to always release the command buffer after commit, and the addition of explicit resource releases to prevent memory leaks after MPSGraph execution.

Stream commit logic changes:

  • The ETMetalStream::commit method now always commits and releases the command buffer directly, removing support for the "commit and continue" optimization and adding error logging if no command buffer is present.
  • All MPSGraph execution calls in the ops shim now use SyncType::COMMIT instead of SyncType::COMMIT_AND_CONTINUE.

Memory management improvements:

  • After MPSGraph execution in all ops (mm_out, convolution, and scaled_dot_product_attention_math_for_mps), the code now explicitly releases the MPSGraph and all associated MPSGraphTensorData objects to prevent memory leaks.

Code simplification and clarity:

  • Unused API availability check for scaledDotProductAttentionWithQueryTensor was removed, streamlining the attention math implementation.
  • Tensor data variables (biasData, maskData) are now declared outside conditional blocks for proper release and scope management.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@manuelcandales
Copy link
Contributor Author

manuelcandales commented Oct 22, 2025

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 22, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Cancelled Job, 2 Pending, 2 Unrelated Failures

As of commit ee043e3 with merge base 5d71c9b (image):

NEW FAILURE - The following job has failed:

CANCELLED JOB - The following job was cancelled. Please retry:

BROKEN TRUNK - The following jobs 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.

manuelcandales added a commit that referenced this pull request Oct 22, 2025
ghstack-source-id: f9bebec
ghstack-comment-id: 3430431335
Pull-Request: #15343
@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 Oct 22, 2025
[ghstack-poisoned]
[ghstack-poisoned]
manuelcandales added a commit that referenced this pull request Oct 22, 2025
ghstack-source-id: 394199f
ghstack-comment-id: 3430431335
Pull-Request: #15343
@manuelcandales manuelcandales added the release notes: none Do not include this in the release notes label Oct 22, 2025
Base automatically changed from gh/manuelcandales/146/head to main October 22, 2025 07:35
[ghstack-poisoned]
@manuelcandales manuelcandales merged commit 526eb18 into main Oct 22, 2025
133 of 140 checks passed
@manuelcandales manuelcandales deleted the gh/manuelcandales/147/head branch October 22, 2025 07:51
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