Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple M1 - How to build 2.6 or Master (Fixed) #51506

Closed
0xA1B2 opened this issue Aug 15, 2021 · 15 comments
Closed

Apple M1 - How to build 2.6 or Master (Fixed) #51506

0xA1B2 opened this issue Aug 15, 2021 · 15 comments
Assignees
Labels
2.6.0 stat:awaiting response Status - Awaiting response from author subtype:macOS macOS Build/Installation issues type:build/install Build and install issues

Comments

@0xA1B2
Copy link

0xA1B2 commented Aug 15, 2021

The genius command "pip install tensorflow" does not even work in Debian 11, so we have to compile from source. The instructions on the TF homepage do not work for the M1.

Has anyone compiled TF 2.6+ on the M1 and can share a guideline please ?

@0xA1B2 0xA1B2 added the type:build/install Build and install issues label Aug 15, 2021
@tilakrayal tilakrayal added 2.6.0 subtype:macOS macOS Build/Installation issues labels Aug 16, 2021
@tilakrayal tilakrayal assigned ymodak and tilakrayal and unassigned tilakrayal and ymodak Aug 16, 2021
@ymodak
Copy link
Contributor

ymodak commented Aug 17, 2021

This issue better raised on https://github.com/apple/tensorflow_macos/issues
Please refer a previous thread which discusses similar issue. Thanks!

@ymodak ymodak added the stat:awaiting response Status - Awaiting response from author label Aug 17, 2021
@0xA1B2
Copy link
Author

0xA1B2 commented Aug 18, 2021

Current Progress on MacOS 12 Beta 5 & default Python 3.9.6

Install from Developer site:
Xcode Command Line Tools 13.x
Xcode Gui 13.x # reboot

conda deactivate #exit Conda environment

pip3 install --upgrade pip

brew install bazel
nano .bazelversion # change to 4.2.0
cat .bazelversion # == 4.2.0
bazel --version # == 4.2.0

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
#git checkout master
#git pull --rebase

./configure

bazel build --config=macos_arm64 tensorflow/tools/pip_package:build_pip_package

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Result in:
/System/Volumes/Data/private/tmp/tensorflow_pkg/

tensorflow-2.7.0-cp39-cp39-macosx_12_0_arm64.whl

pip install *.whl


To get GPU support, we need to install the new Pluggable Device:
https://pypi.org/project/tensorflow-metal/#files

python3 -m pip install tensorflow-metal # 0.1.2

Those wheels are for TF 2.5, it works with TF 2.7 but slower. Apple needs to regularly update tensorflow-metal to match new TF main versions, and also release sources.

@0xA1B2 0xA1B2 changed the title Apple M1 - How to build 2.6 or Master Apple M1 - How to build 2.6 or Master (Fixed) Aug 19, 2021
@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Aug 20, 2021
@ymodak
Copy link
Contributor

ymodak commented Aug 23, 2021

Thanks for sharing your analysis. I will close this issue now.

@ymodak ymodak added the stat:awaiting response Status - Awaiting response from author label Aug 23, 2021
@asapsmc
Copy link

asapsmc commented Aug 24, 2021

Any way to make this work for a M1 inside a Conda environment?

@ymodak
Copy link
Contributor

ymodak commented Aug 24, 2021

@MR-T77 TF build install issues in Conda environment are supported on https://github.com/ContinuumIO/anaconda-issues/issues
Thanks!

@asapsmc
Copy link

asapsmc commented Aug 25, 2021

@ymodak sorry, I tried here because I can't find any way to have tensorflow working in my M1.

@ymodak ymodak closed this as completed Aug 25, 2021
@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@MuhTawfik
Copy link

I was having same problem what was missing is after installing miniforge you have to change the directory to it as below

cd /Users/<your_username>/miniforgeX. "don't forget to change<your_username> with your user name and to change minifrogX with version like miniforge3
example: cd /Users/mohamed/miniforge3

  • after that create env
    conda create -n data-science python=3.9
  • activate
    conda activate data-science
  • add apple chnnel
    conda config --prepend channels apple
  • install dependency
    conda install -c apple tensorflow-deps
  • then normal install
    pip install tensorflow-macos
    pip install tensorflow-metal

hope that help

@BenjaminDEMAILLE
Copy link

Current Progress on MacOS 12 Beta 5 & default Python 3.9.6

Install from Developer site: Xcode Command Line Tools 13.x Xcode Gui 13.x # reboot

conda deactivate #exit Conda environment

pip3 install --upgrade pip

brew install bazel nano .bazelversion # change to 4.2.0 cat .bazelversion # == 4.2.0 bazel --version # == 4.2.0

git clone https://github.com/tensorflow/tensorflow.git cd tensorflow #git checkout master #git pull --rebase

./configure

bazel build --config=macos_arm64 tensorflow/tools/pip_package:build_pip_package

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Result in: /System/Volumes/Data/private/tmp/tensorflow_pkg/

tensorflow-2.7.0-cp39-cp39-macosx_12_0_arm64.whl

pip install *.whl

To get GPU support, we need to install the new Pluggable Device: https://pypi.org/project/tensorflow-metal/#files

python3 -m pip install tensorflow-metal # 0.1.2

Those wheels are for TF 2.5, it works with TF 2.7 but slower. Apple needs to regularly update tensorflow-metal to match new TF main versions, and also release sources.

Don't work for me. macOS 12.6

@thealy
Copy link

thealy commented Oct 24, 2022

Above procedure died after compiling over 15K files:
ERROR: /Users/thealy/Downloads/tensorflow/tensorflow/python/BUILD:3250:24: Linking tensorflow/python/_pywrap_tensorflow_internal.so failed: (Aborted): cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh @bazel-out/darwin_arm64-opt/bin/tensorflow/python/_pywrap_tensorflow_internal.so-2.params

ld: malformed trie, node past end file 'bazel-out/darwin_arm64-opt/bin/_solib_darwin_arm64/libtensorflow_Slibtensorflow_Ucc.2.12.0.dylib'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1
external/local_config_cc/cc_wrapper.sh: line 69: 8045 Abort trap: 6 "$(/usr/bin/dirname "$0")"/wrapped_clang "$@"

Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.

INFO: Elapsed time: 2578.594s, Critical Path: 245.43s
INFO: 18477 processes: 4603 internal, 13874 local.
FAILED: Build did NOT complete successfully

@dorothykiz1
Copy link

dorothykiz1 commented Oct 28, 2022

Running this bazel build --config=macos_arm64 tensorflow/tools/pip_package:build_pip_package compiles for a very long time.

@karllessard
Copy link
Contributor

I'm also hitting the malformed trie, node past end file error.

This issue should not have been closed in the first place, we are still not able to build sources on an Apple Silicon, which is the main topic here. The tensorflow_macos binaries distributed by Apple only helps users using TensorFlow in Python, it is not a viable solution for those using other language bindings, such as Java, C++ or Go. We need at least to be able to compile it from sources, which does not seem to be possible at the moment.

@pooya-jannaty
Copy link

Having a similar malformed trie issue both on an M1 mac and Intel-based.

@karllessard
Copy link
Contributor

Downgrading Xcode CL Tools to 13.x did the trick for me, probably related to this: #58368

@Yanyan-Wang
Copy link

Yanyan-Wang commented Oct 4, 2023

@0xA1B2, Thanks! With many additional tips, it works for me on Mac Big Sur 11 with M1 and python 3.

I am a fresher of tensorflow and python and I came across several problems during the process, hope it helps buddies who have the same problems:

  1. Version of XCode should match your system, e.g. my Macos 11 does not support XCode 13 and higher versions.

  2. When configuring with ./configure , ROCm and Cuda should be both disabled. I have tried ROCm enabled and Cuda disabled (since I have no cuda on my mac), the next build command results in:

Error in fail: ERROR: Building with --config=rocm but TensorFlow is not configured to build with GPU support. Please re-run ./configure and enter 'Y' at the prompt to build with GPU support
  1. After installing the correct version of XCode, The building command bazel build --config=macos_arm64 tensorflow/tools/pip_package:build_pip_package resulted in:
Xcode version must be specified to use an Apple CROSSTOOL

And I found the solution here as:

bazel clean --expunge 
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license
bazel clean --expunge 
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
  1. The building command takes about one hour to finish………… be patient and do not terminate it

  2. After suffering so many difficulties, the last step pip install *.whl(before it, remember cd the directory /System/Volumes/Data/private/tmp/tensorflow_pkg/ where your .whl file at) came across:

ERROR: tensorflow-2.15.0-cp310-cp310-macosx_11_0_arm64.whl is not a supported wheel on this platform.

It is caused by wrong python version in my case. Checkout the file name of .whl: tensorflow-2.15.0-cp310-cp310-macosx_11_0_arm64, which means it should be ran with python 3.10 (cp310 in file name) and maxos 11 (maxcos_11) and arm64 architecture (arm64, which matches the M1 Mac).

And the command pip install *.whl will run with default python version in your computer, which is python 2 in mine. I also have python 3, to specify the python version, I ran python3 -m pip install *.whl instead. But it also failed, I found that python3 --version in my terminal resulted in 3.11 which does not match cp10. So I ran python3.10 -m pip install *.whl instead.

  1. Then, python3.10 -m pip install *.whl resulted in:
ERROR: No matching distribution found for tensorflow-io-gcs-filesystem>=0.23.1

I followed the answer here as:

  • clone the tensorflow/io repository
  • cd into it's directory
  • run: python3 setup.py -q bdist_wheel
  • and go back to /System/Volumes/Data/private/tmp/tensorflow_pkg/ (where your .whl file at)
  • run python3.10 -m pip install *.whl again

Finally works, it takes whole day!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.6.0 stat:awaiting response Status - Awaiting response from author subtype:macOS macOS Build/Installation issues type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests