添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
健壮的眼镜  ·  JAVA ...·  1 年前    · 
酷酷的生姜  ·  tick.json 简介 | ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Why does loading tensorflow on Mac lead to "Process finished with exit code 132 (interrupted by signal 4: SIGILL)"?

Ask Question

I am using a MacBook Pro with M1 processor, macOS version 11.0.1, Python 3.8 in PyCharm, Tensorflow version 2.4.0rc4 (also tried 2.3.0, 2.3.1, 2.4.0rc0). I am trying to run the following code:

import tensorflow

This causes the error message:

Process finished with exit code 132 (interrupted by signal 4: SIGILL)

The code runs fine on my Windows and Linux machines. What does the error message mean and how can I fix it?

SIGILL means Illegal Instruction, at the assembly level, so I don't think this is something we can fix, you should file a bug with the provider of your TensorFlow version (is it Apple's or the official TF wheels?) – Dr. Snoopy Dec 11, 2020 at 0:14 @Dr.Snoopy I download Tensorflow using pip from pypi.python.org. I don't know if that means I'm using Apple's or the official TF wheels. – user505117 Dec 11, 2020 at 10:07 I also tried the TF version that I get from following the instructions in the "tensorflow_macos" repository on github: github.com/apple/tensorflow_macos . Maybe that is what you mean by Apple's version. The installation was fine, but the error remains the same. – user505117 Dec 11, 2020 at 10:20

Seems that this problem happens when you have multiple python interpreters installed, and some of them are for differente architectuers (x86_64 vs arm64). You need to make sure that the correct python interpreter is being used, if you installed Apple's version of tensorflow, then that probably requires an arm64 interpreter.

If you use rosetta (Apple's x86_64 emulator) then you need to use a x86_64 python interpreter, if you somehow load the arm64 python interpreter, you will get the illegal instruction error (which totally makes sense).

If you use any script that installs new python interpreters, then you need to make sure the correct interpreter for the architecture is installed (most likely arm64).

Overalll I think this problem happens because the python environment setup is not made for systems that can run multiple instruction sets/architectures, pip does check the architecture of packages and the host system but seems you can run a x86_64 interpreter to load a package meant for arm64 and this produces the problem.

For reference there is an issue in tensorflow_macos that people can check.

Thank you. The problem was that I used a Rosetta terminal to try to run my arm64 tensorflow code. How do I check whether my Python interpreter is x86_64 or arm64? And how can I tell pip to download x86_64 packages? I would like to go all x86_64, but I don't know how. Should I create this as a new question? – user505117 Dec 25, 2020 at 16:51 @user505117 That is complicated because as my answer says, the python interpreter is not aware of both architectures, only one. So be very careful about using rosetta and native python interpreters. – Dr. Snoopy Jan 22, 2021 at 0:03 @user505117 you can check the architecture through this code. >> import platform >> platform.platform() 'macOS-10.16-x86_64-i386-64bit' – Qazi Ammar Jul 13, 2021 at 12:24

For M1 Macs, From Apple developer page the following worked:

First, download Conda Env from here and then follow these instructions (assuming the script is downloaded to ~/Downloads folder)

chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate

reload the shell and do

python -m pip uninstall tensorflow-macos
python -m pip uninstall tensorflow-metal
conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal

If the above doesn't work for some reason, there are some edge cases and additional information provided at the Apple developer page

I had the same issue

This is because of M1 chip. Now there is a pre-release that delivers hardware-accelerated TensorFlow and TensorFlow Addons for macOS 11.0+. Native hardware acceleration is supported on M1 Macs and Intel-based Macs through Apple’s ML Compute framework.

You need to install the TensorFlow that supports M1 chip Simply pull this tensorflow macos repository and run the ./scripts/download_and_install.sh