M2 installation

I am using OSX 13.2 on M2 chip, Python 3.11.0.
I have followed the rosetta.

In the official website it says I can use pip install torch torchvision torchaudio
But it does not work. It return error as follow.

ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
ERROR: No matching distribution found for torch

When I try nightly

❯ pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/nightly/cpu
Collecting torch
  Using cached https://download.pytorch.org/whl/nightly/cpu/torch-2.0.0.dev20230205-cp311-none-macosx_10_9_x86_64.whl (139.0 MB)
ERROR: Could not find a version that satisfies the requirement torchvision (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3)
ERROR: No matching distribution found for torchvision

Branch: nigthly
cmd: python setup.py develop

/Users/sarit/packages/pytorch/aten/src/ATen/native/metal/MetalDevice.h:40:2: error: "Metal is not available on the current platform."
#error "Metal is not available on the current platform."
 ^
1 error generated.
[14/876] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/autograd/engine.cpp.o
ninja: build stopped: subcommand failed.

How to install PyTorch with MPS enable?

I must configure the arch when install the Python. In this case I am using pyenv.

  1. arch -arm64 pyenv install 3.11.1
  2. pyenv virtualenv 3.11.1 artifact
  3. pyenv local artifact
  4. pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu
  5. Check in the shell
❯ python

Python 3.11.1 (main, Feb 6 2023, 14:02:26) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import torch

>>> torch.backends.mps.is_available()

True