mps device.
Native macOS or Docker?
Both options work, but each has a tradeoff. A native installation uses your Mac’s GPU, so training and other compute-heavy tasks are usually much faster. The downside is that you manage the dependencies yourself, and your installed versions may gradually differ from the course environment. The Docker container gives you the same pinned environment used to run the notebooks on this site. This makes it easier to reproduce the published results, but the container can only use your Mac’s CPU. A practical approach is to work natively most of the time, then use the container or Colab if a result looks suspicious and you want to rule out your local setup. Every assignment includes a Colab badge for this reason.Setup
You will need Python anduv. If you do not have them yet, follow the Python and uv guide first. The commands below assume that uv is available in your terminal.
Selecting the device
Let PyTorch choose from the devices that are actually available instead of hard-coding one. With the following check, the same code can run on your Mac, a CUDA machine, or Colab:mps. If the output says cpu, you are probably running inside a container or using a PyTorch build without Metal support.
When an operation is not supported
PyTorch’s Metal backend does not support every operation yet. If your model reaches an unsupported one, PyTorch stops with a runtime error that names the operator. You can tell it to run unsupported operations on the CPU instead:A note about course notebooks
Some course notebooks only check forcuda and otherwise default to cpu. Those notebooks will still use the CPU on a Mac, even after you complete this setup. If you come across one, replace its device-selection code with the example above; that is usually the only change required.

