Does not work on M1 Mac.
zzeee opened this issue Β· comments
ERROR: The project you're trying to build requires Bazel 3.7.2 (specified in /Users/andrey/.cargo/registry/src/github.com-1ecc6299db9ec823/tensorflow-sys-0.20.0/target/source-v2.5.0/.bazelversion), but it wasn't found in /opt/homebrew/Cellar/bazel/4.2.2/libexec/bin.
Needs bazel 3.7.2. Which is not available for M1 Macs.
Versions starting from 4.1 are available.
I don't have the M1 mac, so I think we need the support of other users on this matter.
- Is prebuild image available for that target with the Rosetta 2 since the official site only provides libtensorflow for x86_64 now.
- Is it possible to build from the source? ref tensorflow/tfjs#4514 (comment)
- Or can you use HomeBrew to install the libtensorflow?
- If this problem was triggered due to bazel version mismatch, could you try downgrade the bazel by some means?
The problem is in bazel and it can not be downgraded to version 3.7.2 because it does not support Apple Silicon.
Fresh versions of bazel support Apple Silicon.
So the question is that - is it possible to use more fresh Bazel
Bazel version is specified in tensorflow-sys, and is set according to the one that officially tested configuration.
What you can do is to try building libtensorflow manually and link to it. In that case, you can use any bazel version, but there is no guarantee to build successfully. Please refer to Manual TensorFlow Compilation
section in the tensorflow-sys.
while
brew install libtensorflow --build-from-source
Last 15 lines from /Users/andrey/Library/Logs/Homebrew/libtensorflow/02.bazel:
This most likely indicates that SDK version [10.10] for platform [MacOSX] is unsupported for the target version of xcode.
Process exited with status 1
stdout: stderr: objc[30434]: Class AMS
it looks like that need to have more fresh bazel in project or older MacOs without M1..
It is possible to build bazel 3.7.2 for Apple M1 and with that build libtensorflow (can see if I find that link again...). I got this running, but I guess the better way would be to update the bazel version.
Ok found it. In this gist it is shown how bazel 3.7.2 can be build for m1, once you got this, you can build libtensorflow.
@sigma-andex did u manage to get it work?
i was able to compile TensorFlow 2.5.0
with bazel 3.7.2
on my m1, but only got 3 libtensorflow*.so files in the bazel-bin
dir, there is no libtensorflow_framework.so
as indicated here
then i found this repo which compiled TF for darwin-arm64
in *.dylib
format, but after putting them in the /usr/local/lib
still NOT able to get the cargo run/build
work (cargo still insist to compile/build the tensorflow-sys v0.20.0
)...
could you pls help to provide a full instructions here for M1?
@lnshi I put a little gist together with the steps I recall:
https://gist.github.com/sigma-andex/9888586a676d2d9ee2ed24cf5bcc1f20
This might be incomplete as it is already some time ago, I haven't written down my process and it was quite a bit of fiddling around and trial&error. Would be great if you can fill in the gaps.
Note though, that I compiled tensorflow 2.7.0, as I think there was some patch to make M1 work at all. So I would recommend you to use 2.7.0, because I think you will run into problems with 2.5.0...
@sigma-andex thank for the info
i am only able to run the build like this: bazel build --compilation_mode=opt --copt=-march=native --jobs=10 tensorflow:libtensorflow.so
with urs: bazel build --compilation_mode=opt --jobs=10 --config=macos_arm64 tensorflow:libtensorflow.so
got error:
ERROR: /private/var/tmp/_bazel_leonard/dbb496db86443ebdf640b47e39125a9a/external/local_config_cc/BUILD:48:19: in cc_toolchain_suite rule @local_config_cc//:toolchain: cc_toolchain_suite '@local_config_cc//:toolchain' does not contain a toolchain for cpu 'darwin_arm64'
Are you using 2.7.0 or master?
@sigma-andex * (HEAD detached at v2.7.0)
i was able to compile
TensorFlow 2.5.0
withbazel 3.7.2
on my m1, but only got 3 libtensorflow*.so files in thebazel-bin
dir, there is nolibtensorflow_framework.so
as indicated here
When I tried it on my Intel CPU mac, it generated dylib format files, but did the M1 build only generate so format files?
then i found this repo which compiled TF for
darwin-arm64
in*.dylib
format, but after putting them in the/usr/local/lib
still NOT able to get thecargo run/build
work (cargo still insist to compile/build thetensorflow-sys v0.20.0
)...could you pls help to provide a full instructions here for M1?
We use the build script to indicate the location of the library. If you want to change the location of the library, run cargo clean
once and try to build again.
Lines 409 to 411 in d74f512
i eventually make everything work on my M1, if anyone still stuck on this issue, i build a gist here, should be able to help u out πππ
π
Got this to work on M2 Mac in ARM64 Ventura as well - there was a java error in bazel but fix was to add
startup --host_jvm_args=--add-opens=java.base/java.lang=ALL-UNNAMED
before any build options in the .bazelrc