I'm trying to set up Docker for a Python project on my Mac and want to use MPS (Metal Performance Shaders) for GPU acceleration with PyTorch inside the container.
What I have tried so far:
import torch
print(torch.backends.mps.is_available())
This returns False
, meaning MPS is not detected inside the container.
My questions:
Does Docker on macOS support GPU passthrough for MPS acceleration?
Are there any specific Docker settings or configurations to enable GPU access inside the container?
If GPU passthrough is not supported, are there any workarounds to use MPS with PyTorch inside Docker?
Any guidance or workarounds would be greatly appreciated. Thanks!
No. Docker on macOS does not support GPU passthrough, including access to Apple's Metal API or MPS backend inside containers.
This is because Docker runs inside a lightweight Linux virtual machine (via HyperKit or Apple Virtualization Framework), and GPU access is not exposed to that VM.
No. There are currently no supported Docker settings, flags, or experimental features that allow a container to access the host's Metal/MPS capabilities.
Even with all dependencies and PyTorch correctly installed inside the container, torch.backends.mps.is_available()
will return False
.