text: Errors building tensorflow-text on apple silicon even when using matching versions of tensorflow 2.10

I’m trying to build the tensorflow-text on a M1 Mac because tensorflow-text is not released for Apple silicon.

When compiling using ./oss_scripts/run_build.sh I see following errors:

In file included from tensorflow_text/core/kernels/byte_splitter_tflite.cc:18:
external/org_tensorflow/tensorflow/lite/kernels/shim/tflite_op_shim.h:128:35: error: no member named 'OpName' in 'tensorflow::text::ByteSplitterWithOffsetsOp<tflite::shim::Runtime::kTfLite>'
    resolver->AddCustom(ImplType::OpName(), GetTfLiteRegistration());
                        ~~~~~~~~~~^
tensorflow_text/core/kernels/byte_splitter_tflite.cc:28:53: note: in instantiation of member function 'tflite::shim::TfLiteOpKernel<tensorflow::text::ByteSplitterWithOffsetsOp>::Add' requested here
      tensorflow::text::ByteSplitterWithOffsetsOp>::Add(resolver);

I would also love to know if anyone is able to get tensorflow-text 2.10 to work on apple silicon.

Setup and reproduce

Tensorflow is installed via conda

conda install -c apple tensorflow-deps=2.10.0
python -m pip install tensorflow-macos==2.10.0
python -m pip install tensorflow-metal==0.6

Bazel is installed from home-brew

brew install bazelisk

Tensorflow-text is downloaded from release page

wget https://github.com/tensorflow/text/archive/refs/tags/v2.10.0.zip

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 54 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Whoever hitting this problem, here’s the solution for everybody using MacOS 13 and want to build tensorflow-text. This is the kind of thing that should not be this hard. Thanks to @DuongTSon and https://medium.com/@murphy.crosby/building-tensorflow-and-tensorflow-text-on-a-m1-mac-9b90d55e92df

Please make sure:

  1. Use conda. Because you will need tensorflow-metal, tensorflow-deps and tensorflow-macos
  2. Download Xcode 13.1 from here. Even though you won’t be able to install Xcode 13.1, you still need the older version ld to workaround the issue mentioned here

Following are the steps.

Create a conda environment:

conda create -p ./venv python=3.10
conda activate ./venv

Install tensorflow macOS dependencies:

conda install -c apple tensorflow-deps=2.10.0
python -m pip install tensorflow-macos==2.10.0
python -m pip install 'tensorflow-metal==0.6.0'

clone the tensorflow-text repo and checkout 2.10.0 branch

git clone https://github.com/tensorflow/text.git
git checkout 2.10

Comment out following lines in oss_scripts/run_build.sh:

# if [[ $osname != "darwin" ]] || [[ ! $(sysctl -n machdep.cpu.brand_string) =~ "Apple" ]]; then
#  source oss_scripts/prepare_tf_dep.sh
#fi

Backup you ld and replace it with the older version of ld in Xcode 13.1. Here I assume you downloaded Xcode 13 in ~/Downloads folder.

sudo mv /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld ./ld.backup
sudo cp ~/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/

Run ld -v to make sure your ld version is ld64-711

Now run ./oss_scripts/run_build.sh and the wheel will be produced.

I really really hope the tensorflow team can improve the dev experience on Apple Silicon given the huge amount of devs using Mac and all new Macs are on Apple Silicon.

Finally, I have successfully built both the tensorflow-text 2.9 and 2.11. The tensorflow-macos version and the tensorflow-text version should be strictly matched. If you build the text V2.11, then you need to checkout to the 2.11 branch and install the tensorflow-macos=2.11.

  1. Install the bazelisk
brew install bazelisk
  1. Remove the auto-configuration in the oss_script/run_build.sh file. Currently, it will update the version to the latest version of Tensorflow which causes the major incompatibility.
# Remove or Disable those lines below
# Set tensorflow version
if [[ $osname != "Darwin" ]] || [[ ! $(sysctl -n machdep.cpu.brand_string) =~ "Apple" ]]; then
   source oss_scripts/prepare_tf_dep.sh
 fi
  1. Create a virtual env with the anaconda ARM version. For example, env name is tf2.11
conda create --name tf2.11 python=3.10
conda activate tf2.11
  1. Install tensorflow-macos and tensorflow-metal
pip install tensorflow-macos==2.11.0
pip install tensorflow-metal==0.7.1
  1. Run the build
./oss_scripts/run_build.sh

That’s very strange. If you are positive that it’s the lib you built, then you must be building it for the wrong architecture somehow. I think your best bet is Google for how to ensure you are building for the right architecture. For example, this page suggests you may have multiple architecture implementations of LLVM installed, check your clang target (clang -v), and possibly set ARCHPREFERENCE (if it is used).

But first, to double verify it is the build, I would unzip your package (just rename with a .zip extension and unzip), and then use the file command (file tflite_registrar.so) to verify they were built for the right architecture. Then you will know for certain whether your created package was built incorrectly or there was an installation issue.

No instruction from this thread worked for me, is there any clear instruction how to build and run it on arm64?

For example when I try to build I have following error:

# NOTE: Update Bazel version in tensorflow/tools/ci_build/release/common.sh.oss'
+ '[' 5.3.0 '!=' '5.3.0
# NOTE: Update Bazel version in tensorflow/tools/ci_build/release/common.sh.oss' ']'
+ echo 'Incorrect version of Bazel installed.'

Which says that 5.3.0 '!=' '5.3.0

I think you are using the master branch to build. I had this issue before, it was because of the error in the script oss_scripts/run_build.sh. You can use the stable versions by checking out at the stable branch such as 2.11, 2.10, etc…

No instruction from this thread worked for me, is there any clear instruction how to build and run it on arm64?

For example when I try to build I have following error:

# NOTE: Update Bazel version in tensorflow/tools/ci_build/release/common.sh.oss'
+ '[' 5.3.0 '!=' '5.3.0
# NOTE: Update Bazel version in tensorflow/tools/ci_build/release/common.sh.oss' ']'
+ echo 'Incorrect version of Bazel installed.'

Which says that 5.3.0 '!=' '5.3.0

Perfect., @DuongTSon , thank you. I guess this issue can be closed, by updating the README to highlight the current version working as well as the environment working.

@ethiel I manage to reproduce your error with the version 2.10 by using the XCode14.2. I guess there was an issue with the XCode 14.2 or clang 14.0. The environment that has worked for me is:

  • Xcode 13.4.1
  • Clang 13.1.6
  • tensorflow-macos==2.11.0
  • tensorflow-metal==0.6.0

Could I use I precompiled wheel for macos 13 and if yes could someone provide me one? I followed @DuongTSon instructions but when I build it gets stuck 😦

I am not sure whether my builds in MacOS Monterey can work on your computer but you can try. There are 3 versions of tensorflow-text 2.9, 2.10, 2.11 in the link below. https://1drv.ms/u/s!AmRjIZct7QZDg9xM-rf_kE_svoEcJA?e=IvpE7R

However, after manually executing prepare_tf_dep.sh I’m facing a different issue: error: no member named ‘OpName’ in ‘tensorflow::text::FastBertNormalizeOptflite::shim::Runtime::kTfLite’