tensorflow: tensorflow 2.15 "Illegal instruction: 4" Mac M1 processor

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

2.15.0

Custom code

No

OS platform and distribution

Darwin MacBook-Pro-2.localdomain 23.3.0 Darwin Kernel Version 23.3.0; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64 (Sonoma 14.3 Apple M1 Max)

Mobile device

No response

Python version

3.11.7

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

$ python3 Python 3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.

import tensorflow Illegal instruction: 4 $

I expected to be able to import the module after it is installed. I suspect the newer processor is an issue.

Standalone code to reproduce the issue

$ python3
Python 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Illegal instruction: 4
$

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 15 (2 by maintainers)

Most upvoted comments

This issue should be reopened, I am still facing the same issue, even with 2.16

@thesofakillers Thanks, it worked. The trick is to use correct architecture:

CONDA_SUBDIR=osx-arm64 conda create -n tf -c conda-forge python=3.11

CONDA_SUBDIR=osx-arm64 is important for arm Mac

the issue i mention above is not conda exclusive fwiw.

Try running

python -c "import platform; print(platform.machine())"

This should print

arm64

If you’re on apple silicon. If it isn’t (e.g. its printing x86_64) and you are on apple silicon, something about your python installation is wrong, and tensorflow won’t work.

fyi, check whether your python was installed via conda, and whether the conda installed is actually the ARM version of conda and not the x86 version of conda. I was mistakingly using x86 conda after transferring over from an old intel-based mac. Changing conda to the correct architecture fixed this issue for me.

Same problem happens with TensorFlow 2.10.0-rc0 and 2.9.1 on Mac M1 Pro