-
Notifications
You must be signed in to change notification settings - Fork 343
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
Add Apple Silicon support. #756
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! There's been a lot of interest for this. :)
I'm not sure if we'll be able to update our builds to publish these to pypi yet, but this will at least allow others to build it themselves.
If the TensorFlow team and the community think that it is a better choice to continue using the standard version of TF on the x86-64 architecture Mac, I can also add the judgment of the architecture at compile time. However, in general, I think it is more important for Mac developers to use GPU acceleration than high compatibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delayed reply, I've been busy getting some last items ready for the 2.7 release.
@sun1638650145 were you able to compile via bazel 3.7.2 on the M1 or did you find some way to get past the issues running > 4.1 versions of bazel (i.e., #638)? I'm stuck here and am stumped. |
@TeoZosa I compiled the source code of bazel 3.7.2 because bazel 3.7.2 did not provide a pre-compiled package for M1. Currently compiling Tensorflow from source code must use bazel of 3.7.x, and bazel 4.x should not currently work. |
Ah I was afraid you'd say that (compiling Bazel has been a pain). Thank you! |
@TeoZosa Yes, Bazel officially recommends the use of pre-compiled packages.If you need it, I saved a compiled exec file (if you are using M1, you only need to add it to the environment variable to use). |
Hey @sun1638650145, sorry for getting back so late. I actually figured out how to get it built locally, but I appreciate the offer! Fingers crossed your PR gets merged in soon :) |
Could you provide the compiled exec file? I'm also stuck here. |
Was that for me or @sun1638650145 ? FYI In case it's useful to anyone, here are the source build instructions I used: |
Thanks, I already compiled the bazel 3.7.2 by myself without problems. But I still couldn't build tensorflow_text from source. I got the following error after executing
|
Ahh! Which branch are you building from? I had the same errors when building from |
I'm building from the master branch in this repo: https://github.com/sun1638650145/text#build-from-source-steps. What exact branch you checkout fix the issue? |
I built from the tensorflow/text Note: since @sun1638650145 's PR hasn't been merged yet, I had to manually patch the platform extension in |
You mean to replace |
I should have mentioned, that part is only so you can install the pip package after.
Did you try building from the |
I see, thanks. However I got new errors building from the
|
Which version of tensorflow are you using? FWIW, I also built tensorflow |
I'm using |
Have you done any patching for
|
Hm. That's an interesting one. Are you compiling with XLA? To compile TF I just used the default values for sudo bazel build --config=macos_arm64 //tensorflow/tools/pip_package:build_pip_package |
I tried both following your script and installing the tensorflow by myself using --config=macos_arm64 but still got the above error:
Not sure why. |
Thank you @sun1638650145. As per your instructions, I have created a new conda environment which uses tensorflow-macos.
I tried replacing the file as @broken mentioned in #823 but the output is still the same:
No |
hi, I have what looks like exact same issue as yuyuan20 environment:
cloned repo with the file outputs very long list, same as above, and at the end it breaks with:
I verified that contents of |
some additional findings after trying to solve the above:
|
Did a bit more tweaking to keep sed working as is -> installed GNU sed via brew and added it to path. So sed commands now pass without modification needed. Added this line to confirm version vs git version check: file: prepare_tf_dep.sh #!/bin/bash
set -e # fail and exit on any command erroring
set -x # print evaluated commands
if (which python) | grep -q "python"; then
installed_python="python"
elif (which python3) | grep -q "python3"; then
installed_python="python3"
fi
# update setup.nightly.py with tf version
tf_version=$($installed_python -c 'import tensorflow as tf; print(tf.__version__)')
echo "$tf_version"
sed -i "s/project_version = 'REPLACE_ME'/project_version = '${tf_version}'/" oss_scripts/pip_package/setup.nightly.py
# getting sed error `invalid command code o` Potential culprit is MAC using BSD Sed, and this being GNU?
# installed gsed via brew, added to path, to enable using GNU sed
echo "---------- checkpoint 1 ----------"
# update __version__
sed -i "s/__version__ = .*\$/__version__ = \"${tf_version}\"/" tensorflow_text/__init__.py
echo "---------- checkpoint 2 ----------"
# Get commit sha of installed tensorflow
echo "$installed_python"
echo "---------- check tf version and git version used ----------"
version_check=$($installed_python -c 'import tensorflow as tf; print("\nversion: {}".format(tf.__version__)); print("git_version: {}".format(tf.__git_version__))')
#echo "$version_check"
short_commit_sha=$($installed_python -c 'import tensorflow as tf; print(tf.__git_version__)' | tail -1 | grep -oP '(?<=-g)[0-9a-f]*$')
echo "---------- checkpoint 3 ----------"
commit_sha=$(curl -SsL https://github.com/tensorflow/tensorflow/commit/${short_commit_sha} | grep sha-block | grep commit | sed -e 's/.*\([a-f0-9]\{40\}\).*/\1/')
echo "---------- checkpoint 4 ----------"
# Update TF dependency to installed tensorflow
sed -i "s/strip_prefix = \"tensorflow-2\.[0-9]\+\.[0-9]\+\(-rc[0-9]\+\)\?\",/strip_prefix = \"tensorflow-${commit_sha}\",/" WORKSPACE
sed -i "s|\"https://github.com/tensorflow/tensorflow/archive/v.\+\.zip\"|\"https://github.com/tensorflow/tensorflow/archive/${commit_sha}.zip\"|" WORKSPACE
prev_shasum=$(grep -A 1 -e "strip_prefix.*tensorflow-" WORKSPACE | tail -1 | awk -F '"' '{print $2}')
sed -i "s/sha256 = \"${prev_shasum}\",//" WORKSPACE
|
Now it throws a different error.
Still can't figure out where the problem is :) |
Yeah that was because I installed gnu-sed from homebrew, even though I had one in-built. Now the error is as same as before: |
I'm able to bypass this by going back to Mac did you figure out how to get the version of tensorflow git? if you run can't get past that point... |
I responded on the bug, but I'll add context here in case somebody else runs across it, as it does pertain to building against M1. We added the script prepare_tf_dep.sh to the run_build script to make sure that manual builds of TF Text were built against the version of TF you have installed. This was especially important for those building against nightly, and has reduced confusion for those users. However, in the case of tensorflow-macos, it seems like Apple does not populate the git_version variable, and there is no tensorflow-macos-nightly for users to build against. Thus, the script is obsolete in this case. We'll update run_build to not run this script for these builds, but in the meantime, you can simply remove the line |
Thank you. Also please provide the link to the wheel so I do not have to go through the frustration to build it. I have successfully build it by directly downloading the wheel as @broken mentioned here #823 (comment)_ . The import and everything works fine but the code does not execute if tensorflow-metal(ver 0.3.0) is installed. So the only way to run this is to uninstall tensorflow-metal but that takes too much time to train a simple BERT model (approx 1 hour per epoch). I have reported this issue to tensorflow but they replied this issue is specific to macOS. Anyway, I have to see if the issue gets resolved by upgrading both tensorflow and text. Regards. |
Did not have time to test yet, but I have built the wheel: https://idealoom.org/wheelhouse/tensorflow_text-2.8.1-cp39-cp39-macosx_11_0_arm64.whl |
@yuyuan20 In fact, |
Yeah I know. Just mentioned to check if anyone faced the same issue or if the issue is really related to tensorflow-metal. |
Installed and tried to import it but getting this error:
|
Thanks for the report, and apologies for not having at least tested import. There was indeed an issue with my wheel, and I rebuilt it. Please try again (with the same URL). |
@yulsa @yuyuan20 I wrote a complete tutorial on building |
I have written a complete build tutorial, along with pre-compiled wheel, which I hope can help those who need it. |
The pre-compiled wheels have saved my days. Could a hero help make a tensorflow-text 2.6 pre-compiled wheel (cp39-cp39-macosx_11_0_arm64) please? |
Also: could a hero make an aarch64-manylinux wheel please? (cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64) |
@pz325 I have a |
The TensorFlow Text package requires use of a matching minor version of TensorFlow. In order to support Apple Silicon macs, Tensorflow Text chooses between the `tensorflow` and `tensorflow-macos` packages automatically based on system architecture. However, I believe that commit a7e1b5b accidentally wiped out this logic. Additionally, this commit failed to increment the minor version of the `tensorflow-macos` dependency. This typically isn't a problem for users installing TensorFlow Text using `pip` on non-Apple Silicon devices, since `pip` just tries to find the best set of packages for the current system. However, this _is_ a problem for package managers like Poetry, which create a deterministic lock file allowing a similar set of dependencies to be installed across different systems, modulo any architectural differences. Since Poetry needs to resolve a combination of dependencies that will work for _any_ system, it eagerly tries to identify a version of `tensorflow-macos` that will work on Apple Silicon devices. However, since the minor versions of the `tensorflow` and `tensorflow-macos` dependencies don't match, it's unable to find an appropriate version of `keras` that both can use. As a result, installing `tensorflow-text (>=2.8.0)` using Poetry is currently impossible. These changes restore the logic to automatically select between `tensorflow` and `tensorflow-macos` based on platform and architecture identifiers, and bump the version of the `tensorflow-macos` dependency to match the minor version of `tensorflow` and `tensorflow-text`.
@sun1638650145 Thanks for the precompiled wheels. It seems it is working :) Able to train BERT now. It is interesting one epochs is taking almost 20hrs . I do have lot of training data but with GPU I feel it is still long time. |
Description
Add Apple Silicon support. By installing tensorflow-macos 2.6.0 and tensorflow-metal 0.2.0, TF.Text can be compiled from source code(Currently Apple does not provide a preview version of tensorflow-macos and tf-nightly, so TF.Text can only build a stable version.).
Fixes #538