You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Metal backend: eliminate memory leak (pytorch#15343)
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.
0 commit comments