Pytorch

Pytorch for M series mac (Metal accelerated)

Using bare pip

From Apple documentation, using simple pip:

pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

For a uv project

For a Python project using uv as a project and package manager do the following:

Add to the uv pyproject.toml file:

[tool.uv.sources]
torch = { index = "pytorch" }
torchvision = { index = "pytorch" }
torchaudio = { index = "pytorch" }

[[tool.uv.index]]
name = "pytorch"
url = "https://download.pytorch.org/whl/nightly/cpu"
explicit = true

Then run:

uv add --prerelease allow torch torchvision torchaudio

There is an open issue on uv github to improve a bit the CLI to automatically add explicit indexes to the pyproject.toml file.

For a simple script/one time projec using uv

Run the command:

uv add --prerelease allow torch torchvision torchaudio --index pytorch=https://download.pytorch.org/whl/nightly/cpu