mscipio / mscipio.github.io

0 stars 0 forks source link

post/tf-on-m1/ #9

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

How to install TensorFlow and TensorFlow Probability (nightly) on Mac M1 Pro with Rosetta | The Unconscious Statistician

In this post, I will show how you can install tf-nightly and tfp-nightly on your Mac M1 Pro with Rosetta

https://www.theunconsciousstatistician.com/post/tf-on-m1/

jurgisp commented 2 years ago

Thanks for the post! It was the only resource I could find about getting TF+TFP to work, and it gave me hope that it's possible :)

I found one more way to do it though, perhaps it will be helpful:

1) Install the osx-arm64 conda env with TF 2.6 as per Apple tutorial. At this point TF works, but TFP from conda doesn't.

2) Install dm-tree directly from git source by running pip install git+git://github.com/deepmind/tree.git#egg=dm-tree as described in this issue. This is the dependency of TFP that fails to install in the normal way.

3) Now just install TFP with pip install tensorflow-probability==0.12.2.

gisilvs commented 2 years ago

Thank you so much! Now I can finally run TF and TFP on the M1 GPU, a dream comes true!

MichelleAppel commented 2 years ago

Thank you for the helpful and clear tutorial!

gshwang00 commented 1 year ago

Thanks for the tutorial. Can you explain more explicitly how I can proceed about this ("and then rename it by copying the following line in the file .zshrc: alias brow='/usr/local/bin/brew'.")? This is my first time to install brew, so if you can provide a bit more details, it would be greatly appreciated.

gshwang00 commented 1 year ago

I am also stuck in the step in "bazel build //tensorflow/tools/pip_package:build_pip_package". It says "Invalid python path: bazel build //tensorflow/tools/pip_package:build_pip_package cannot be found. Please specify the location of python. [Default is /usr/local/Caskroom/miniconda/base/envs/env_name/bin/python3]:" What am I supposed to do?

gisilvs commented 1 year ago

Hi @gshwang00! This tutorial is obsolete, as now there is a way more convenient way to use tensorflow and tfp on M1/M2.

You can simply install brew for M1 (it's fairly straightforward and there is plenty of tutorials online), then follow the steps in https://developer.apple.com/metal/tensorflow-plugin/ to install tensorflow. If you then need to use tfp, follow these steps

''' pip install cmake pip install git+git://github.com/deepmind/tree.git pip install tensorflow-probability '''

Hope this helps!

gshwang00 commented 1 year ago

Hi @gisilvs,

Thank you so much for your help. I was able to proceed to install tensor flow. Now, I am in the middle of installing tfp "pip install git+git://github.com/deepmind/tree.git", but I got this message. Would you be able to help?


Collecting git+git://github.com/deepmind/tree.git Cloning git://github.com/deepmind/tree.git to /private/var/folders/8q/64nlnsb12ys07lpw7dn6jhh12wrkpf/T/pip-req-build-2dr2jepb Running command git clone --filter=blob:none --quiet git://github.com/deepmind/tree.git /private/var/folders/8q/64nlnsb12ys07lpw7dn6jhh12wrkpf/T/pip-req-build-2dr2jepb fatal: unable to connect to github.com: github.com[0: 140.82.113.3]: errno=Operation timed out

error: subprocess-exited-with-error

× git clone --filter=blob:none --quiet git://github.com/deepmind/tree.git /private/var/folders/8q/64nlnsb12ys07lpw7dn6jhh12wrkpf/T/pip-req-build-2dr2jepb did not run successfully. │ exit code: 128 ╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error

× git clone --filter=blob:none --quiet git://github.com/deepmind/tree.git /private/var/folders/8q/64nlnsb12ys07lpw7dn6jhh12wrkpf/T/pip-req-build-2dr2jepb did not run successfully. │ exit code: 128 ╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

gisilvs commented 1 year ago

Seems to be a problem with git or dmtree. I would reccommend trying again later, or checking the dmtree repo to see if anyone filed a similar issue :)