简体   繁体   中英

How can I run both TensorFlow and Torch on Mac M1 MacBook Pro?

I encounter some problems on my MacBook Pro M1. I thought it would be easier to start coding on it, apparently it's not a ML beast yet...

I need to use both PyTorch and TensorFlow on Python. I have installed TensorFlow 2.0 for Mac OS .

The problem is: TensorFlow won't work when you use a x86_64 terminal. (So it doesn't work with PyCharm). However, I can import TensorFlow 2.0 from an arm terminal. Paradoxically, PyTorch won't install on a arm terminal, only on a x86_64 terminal. So, on the same Python terminal, I'm not able to import both torch and TensorFlow 2.0.

Since HuggingFace transformers is crucial for me, and transformers needs both TensorFlow 2.0 and PyTorch, I need to go back on my old computer to code. I'm very disappointed!

Anyone successfully imported both PyTorch and TensorFlow on a Mac M1 device?

And does anyone know if there is a way to force PyCharm to use an arm terminal, so I can use TensorFlow 2.0 on PyCharm on my M1 MPB?

Thank you!

After some research, I found this answer: https://github.com/pytorch/pytorch/issues/48145 .

So if someone tries to run both Tensorflow and Torch on Mac M1 with PyCharm Apple Silicon Version, here's how to proceed:

Now you can open a PyCharm project with your freshly created virtual environment, and you'll be able to import both Tensorflow and Torch. However, a lot of librairies will be tricky to install like PyTorch...

Try building from the source code as I was able to install on my MacBook pro 13 M1. PyTorch installation from source

Now you can pip install PyTorch for Macs with M1!

https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/

You basically need to use this

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

and replace "cuda" with "mps" in your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM