[英]How can I run both TensorFlow and Torch on Mac M1 MacBook Pro?
I encounter some problems on my MacBook Pro M1.我在 MacBook Pro M1 上遇到了一些问题。 I thought it would be easier to start coding on it, apparently it's not a ML beast yet...我认为开始对其进行编码会更容易,显然它还不是 ML 野兽...
I need to use both PyTorch and TensorFlow on Python.我需要在 Python 上同时使用 PyTorch 和 TensorFlow。 I have installed TensorFlow 2.0 for Mac OS .我已经为 Mac OS 安装了 TensorFlow 2.0 。
The problem is: TensorFlow won't work when you use a x86_64 terminal.问题是:当您使用 x86_64 终端时,TensorFlow 将无法工作。 (So it doesn't work with PyCharm). (所以它不适用于 PyCharm)。 However, I can import TensorFlow 2.0 from an arm terminal.但是,我可以从 arm 终端导入 TensorFlow 2.0。 Paradoxically, PyTorch won't install on a arm terminal, only on a x86_64 terminal.矛盾的是,PyTorch 不会安装在 arm 终端上,只能安装在 x86_64 终端上。 So, on the same Python terminal, I'm not able to import both torch and TensorFlow 2.0.因此,在同一个 Python 终端上,我无法同时导入 Torch 和 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.由于HuggingFace 变压器对我来说至关重要,并且变压器需要 TensorFlow 2.0 和 PyTorch,我需要 go 回到我的旧计算机上进行编码。 I'm very disappointed!我非常失望!
Anyone successfully imported both PyTorch and TensorFlow on a Mac M1 device?有人在Mac M1设备上成功导入PyTorch 和 TensorFlow吗?
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? 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 .经过一番研究,我找到了这个答案: 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:因此,如果有人尝试使用 PyCharm Apple 硅版在 Mac M1 上同时运行 Tensorflow 和 Torch,请按照以下步骤操作:
Now you can open a PyCharm project with your freshly created virtual environment, and you'll be able to import both Tensorflow and Torch.现在,您可以使用新创建的虚拟环境打开 PyCharm 项目,并且可以导入 Tensorflow 和 Torch。 However, a lot of librairies will be tricky to install like PyTorch...但是,很多库安装起来会很棘手,比如 PyTorch...
Try building from the source code as I was able to install on my MacBook pro 13 M1.尝试从源代码构建,因为我能够安装在我的 MacBook pro 13 M1 上。 PyTorch installation from source PyTorch 从源码安装
Now you can pip install PyTorch for Macs with M1!现在您可以为带有 M1 的 Mac 安装 pip PyTorch!
https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/ 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并在您的代码中将“cuda”替换为“mps”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.