module 'torch' has no attribute 'has_mps'
I just followed a youtube video that teaches how to install PyTorch nightly for MacBook to accelerate by m1 chip. However, I came across a  problem really wierd. I can see in the jupyter notebook that torch.has_mps = True. But in jupyter notebook in vscode, it shows that module 'torch' has no attribute 'has_mps'.
Can anyone kindly tell me why? really confusing.

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 &quot;mps&quot; instead of &quot;cuda&quot; (what you see in tutorials):
device = &quot;mps&quot; if torch.has_mps else &quot;cpu&quot;
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
