viable/strict/1772965588
A persistent bug causing memory exhaustion on Macs with M1/M2/M3 chips has finally been resolved.
The PyTorch open-source team has addressed a significant stability issue affecting users on Apple Silicon Macs. The bug, identified by the internal tag 'viable/strict/1772965588', was a memory leak within the Metal Performance Shaders (MPS) backend—PyTorch's framework for leveraging Apple's custom GPU architecture. Specifically, the issue was located in the `getStridedMPSNDArray` function, where `NSArray` copies were not being managed correctly by the autorelease pool, causing system memory to be consumed and never freed during tensor operations.
This fix, committed under hash `2b8b4ff`, resolves a problem that could cause Macs with M1, M2, or M3 chips to gradually run out of memory during extended machine learning tasks, leading to application crashes or system slowdowns. For developers and researchers, this patch is a vital update that enhances the reliability of local AI model development and experimentation on Apple hardware. The MPS backend is a key component for achieving performant, GPU-accelerated PyTorch operations without relying on external NVIDIA hardware, making this stability fix essential for the growing ecosystem of on-device AI development.
- Fixes a memory leak in PyTorch's MPS backend for Apple Silicon (tag: viable/strict/1772965588).
- The bug was in `getStridedMPSNDArray` causing incorrect autorelease of NSArray copies.
- Prevents system memory exhaustion and crashes during ML workloads on M1/M2/M3 Macs.
Why It Matters
Enables stable, long-running AI training and inference on Apple Silicon Macs, a crucial platform for on-device development.