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
{{ message }}
Repository navigation
Pytorch video_inference_superanimal runs slow and then hangs, despite torch detecting GPU, GPU not used. #3155
thanks Juan,
I went through utils.py and commented out all instances of converting device to cpu if specified as mps. The code above now engages the GPU, but unfortunately still hangs after several multiples of the the detector batch size.
Hi @drhochbaum, unfortunately MPS support in PyTorch is still evolving and not yet on par with CUDA. This holds especially for detectors like Faster R-CNN which rely on complex ops. This is probably the reason why you experience your inference hanging / slow, when you enable device = 'mps'. The inelegant device assignment in our code mentioned by @juan-cobos was introduced to avoid the case where tensors are continuously copied back to CPU as fallback, making the detection slower or even fail with MPS enabled. We are currently not testing on MPS, so always happy to get feedback.
Have you tried using the newer versions of PyTorch? I suspect that your issues still remain, but happy to hear otherwise. In case your analysis still hangs on MPS or remains slow, we advice to run your analysis on CPU instead, or try to get access to CUDA-enabled machine (or use a cloud service, like Google Colab).
Activity
juan-cobos commentedon Dec 5, 2025
Hi, I was debugging some things yesterday and I found cpu is assigned when using mps.
/deeplabcut/pose_estimation_pytorch/apis/utils.py
I don't know why it shouldn't work since after it's using torch device, so try to remove those lines. I cannot test mps from my side.
Hope that helps
Juan
drhochbaum commentedon Dec 5, 2025
thanks Juan,
I went through utils.py and commented out all instances of converting device to cpu if specified as mps. The code above now engages the GPU, but unfortunately still hangs after several multiples of the the detector batch size.
deruyter92 commentedon Dec 18, 2025
Hi @drhochbaum, unfortunately MPS support in PyTorch is still evolving and not yet on par with CUDA. This holds especially for detectors like Faster R-CNN which rely on complex ops. This is probably the reason why you experience your inference hanging / slow, when you enable
device = 'mps'. The inelegant device assignment in our code mentioned by @juan-cobos was introduced to avoid the case where tensors are continuously copied back to CPU as fallback, making the detection slower or even fail with MPS enabled. We are currently not testing on MPS, so always happy to get feedback.Have you tried using the newer versions of PyTorch? I suspect that your issues still remain, but happy to hear otherwise. In case your analysis still hangs on MPS or remains slow, we advice to run your analysis on CPU instead, or try to get access to CUDA-enabled machine (or use a cloud service, like Google Colab).
Here are some useful links for reference:
pytorch/pytorch#141287
https://discuss.pytorch.org/t/current-state-of-mps/172212/2
https://pytorch-lightning.readthedocs.io/en/2.4.0/pytorch/accelerators/mps_basic.html
Add a hardware gate for running object detectors on Apple MPS
Add a hardware gate for running object detectors on Apple MPS
Add a hardware gate for training object detectors on Apple MPS
Add a hardware gate for training object detectors on Apple MPS
Add a hardware gate for training object detectors on Apple MPS