4

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!

pythonize
  • 61
  • 1
  • 5
  • 1
    Have you tried googling this? I see about 8-10 posts specifically talking about this. Just by googling "TensorFlow on mac M1". https://towardsdatascience.com/new-apple-silicon-m1-macbook-air-the-dream-laptop-for-machine-learning-engineers-a1590fbd170f – Akshay Sehgal Dec 26 '20 at 09:25
  • As you can read, I successful run TensorFlow on my Mac. The problem appears when I want to run TensorFlow + Torch (or probably any non optimized library for M1) – pythonize Dec 26 '20 at 10:47

3 Answers3

2

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...

pythonize
  • 61
  • 1
  • 5
1

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

  • thank you for your answer, but I still got the same problem. I even tried with this: https://github.com/pytorch/pytorch/issues/48145 – pythonize Jan 05 '21 at 20:54
1

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

Pavlos
  • 906
  • 1
  • 11
  • 29