feat: Add Metal Performance Shaders (MPS) backend support for Apple Silicon acceleration#86
Conversation
… Shaders backend (torch.backends.mps)
|
Hi @evaezekwem! Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention. You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
mmuckley
left a comment
There was a problem hiding this comment.
Hello @evaezekwem, it looks like this changes the default behavior of several functions. Could you update the code so the default behavior is not altered?
As a simple example, run_sample_inference should be like:
def run_sample_inference(device="cuda:0")
rather than
def run_sample_inference(device)
Overview
This PR adds support for Apple Silicon (M1/M2/M3) chips through PyTorch's Metal Performance Shaders (MPS) backend, enabling GPU acceleration for V-JEPA2 inference on macOS devices.
Motivation
Changes Made
Core Implementation
torch.backends.mps).to(device)Specific Files Modified
notebooks/vjepa2_demo.py: Added MPS device detection and initializationnotebooks/vjepa2_demo.py: Added MPS device detection and initializationKey Code Changes
Also modified instances where tensor were moved explicitly to cuda e.g.
model_hf.cuda().eval()tomodel_hf.to(device).eval()Testing
Tested Configurations
✅ Apple M3 Max (40 GPU cores) - macOS Sequoia 15.6.1
✅ Memory - 128 GB
✅ Backward compatibility verified with CUDA devices
✅ CPU fallback functionality maintained
Validation
Known Limitations
vjepa2_vit_giant_384(1B) due to memory limitations.Future Improvements
Breaking Changes
None - all changes are backward compatible.