Issue:
I am trying to train a Faster R-CNN model using Detectron2 on my MacBook Pro (M3, macOS Sonoma) with MPS (Metal Performance Shaders).
However, I keep running into missing operator issues during training:
from detectron2.engine import DefaultTrainer
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False) # Start from scratch
trainer.train()
Error message:
device_grads = torch._foreach_add(device_grads, device_params, alpha=weight_decay)
295 if momentum != 0:
296 bufs = []
NotImplementedError: The operator 'aten::_foreach_add.List' is not currently implemented for the MPS device. If you want this op to be added in priority during the prototype phase of this feature, please comment on . As a temporary fix, you can set the environment variable `PYTORCH_ENABLE_MPS_FALLBACK=1` to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.
import os
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
import torch
print(f"Using MPS: {torch.backends.mps.is_available()} (Fallback Enabled: {os.environ['PYTORCH_ENABLE_MPS_FALLBACK']})")
Has anyone successfully trained Faster R-CNN or Mask R-CNN on Mac M3 with MPS without running into missing operator issues? Is there a better workaround to enable missing ops without fully relying on CPU fallback?