Just make sure you installed the nightly build of PyTorch.
Apple Silicon support in PyTorch is currently available only in nightly builds.
e.g., if you're using conda, try this:
conda install pytorch torchvision -c pytorch-nightly
or with pip
pip3 install --pre torch torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cpu
See more here:
https://pytorch.org/get-started/locally/
The script to verify that you're using the correct version is like you write, you can simply open python REPL in your env where you installed the above:
import torch
torch.has_mps
And you should get
True
To select the device, use "mps" instead of "cuda" (what you see in tutorials):
device = "mps" if torch.has_mps else "cpu"
print(f'Using device: {device}')
P.S. Although the guide suggest to install torchaudio, it will not work, at least with conda environments.
P.P.S. Also, try with the environment in this github repo:
https://github.com/causevic/mlboxm1/blob/main/pytorch_mac_m1.yml