rust icon indicating copy to clipboard operation
rust copied to clipboard

Does not work on M1 Mac.

Open zzeee opened this issue 3 years ago • 14 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.

zzeee avatar Jan 03 '22 19:01 zzeee

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 https://github.com/tensorflow/tfjs/issues/4514#issuecomment-826591952
  • 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?

dskkato avatar Jan 05 '22 23:01 dskkato

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

zzeee avatar Jan 06 '22 09:01 zzeee

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.

dskkato avatar Jan 06 '22 11:01 dskkato

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..

zzeee avatar Jan 06 '22 16:01 zzeee

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.

sigma-andex avatar Jan 06 '22 21:01 sigma-andex

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 avatar Jan 06 '22 21:01 sigma-andex

@sigma-andex did u manage to get it work?

@dskkato

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 avatar Jan 24 '22 09:01 lnshi

@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 avatar Jan 24 '22 10:01 sigma-andex

@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'

lnshi avatar Jan 24 '22 12:01 lnshi

Are you using 2.7.0 or master?

sigma-andex avatar Jan 24 '22 12:01 sigma-andex

@sigma-andex * (HEAD detached at v2.7.0)

lnshi avatar Jan 24 '22 12:01 lnshi

@lnshi

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

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 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?

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.

https://github.com/tensorflow/rust/blob/d74f5124f79b396676474a51417447321cb04c94/tensorflow-sys/build.rs#L409-L411

dskkato avatar Jan 25 '22 00:01 dskkato

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 🎉🎉🎉

lnshi avatar Mar 26 '22 05:03 lnshi

😁 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

LCrossman avatar Jul 03 '23 12:07 LCrossman