sun1638650145 / Libraries-and-Extensions-for-TensorFlow-for-Apple-Silicon

This Repo will provide TensorFlow libraries and extended build tutorials that require compilation to build, as well as pre-compiled wheel files.
115 stars 9 forks source link

Error regarding tflite_registrar.so #10

Closed nilpath closed 2 years ago

nilpath commented 2 years ago

hi

so with your help on my previous issue I were able to build and install the tensorflow-text whl.

However, I noticed when continuing working on this, that I still seem to have some problems when importing and using tensorflow-text. This issue do not happen when I install and use the wheel that you have provided.

Any ideas on what may be the issue?

from tensorflow_text.core.pybinds import tflite_registrar
E   ImportError: dlopen(python3.8/site-packages/tensorflow_text/core/pybinds/tflite_registrar.so, 0x0002): tried: 'python3.8/site-packages/tensorflow_text/core/pybinds/tflite_registrar.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))
sun1638650145 commented 2 years ago

Did you use this command(conda install -c apple tensorflow-deps==2.8.0)? Usually this problem occurs when the version of protobuf does not match (greater than 3.19.x).

nilpath commented 2 years ago

Hi!

apparently I were using tensorflow-deps==2.9.0 so I downgraded that

however I get this unrelated error when trying to run my service that is using tensorflow

TypeError: Descriptors cannot not be created directly.
E   If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
E   If you cannot immediately regenerate your protos, some other possible workarounds are:
E    1. Downgrade the protobuf package to 3.20.x or lower.
E    2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
E
E   More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

previously i solved it by manuall installing protobuf==3.20.0 which then results in the first error

nilpath commented 2 years ago

~hmm could there be an issue that the service I install tensorflow-text into requires me to install 3.20.0 while it wants 3.19.5?~

nah did not help to downgrade it

nilpath commented 2 years ago

looks like tensorflow-deps 2.8.0 and tensorflow-macos installs different versions of protobuf might have some

sun1638650145 commented 2 years ago

@nilpath Things are a little confusing, and we need to keep our heads up.

  1. The major versions of tensorflow-macos, tensorflow-text and tensorflow-deps need to be the same. For example tensorflow-macos 2.8.0, tensorflow-text 2.8.0 and tensorflow-deps 2.8.0, I told you to install tensorflow-deps 2.8.0 because of the previous issue. Now it seems that you need to use 2.9.0.
  2. Build and use are not the same, please do not build and use in the same environment, it is easy to cause unknown errors. Here I strongly recommend that you re-create a new environment to build.
  3. protobuf is automatically matched by tensorflow-deps, and there is no need to manually change it yourself. protobuf depends on the C library of libprotobuf, and manual installation often produces mismatch errors (you can find import protobuf errors).
  4. To build text 2.9.0 please switch to branch v2.9, now it seems that you did not read this tutorial clearly, completely referring to this tutorial should not cause the problem of manually modifying protobuf.
sun1638650145 commented 2 years ago

I hope you can provide conda environment and package information for the build.

nilpath commented 2 years ago

@nilpath Things are a little confusing, and we need to keep our heads up.

  1. The major versions of tensorflow-macos, tensorflow-text and tensorflow-deps need to be the same. For example tensorflow-macos 2.8.0, tensorflow-text 2.8.0 and tensorflow-deps 2.8.0, I told you to install tensorflow-deps 2.8.0 because of the previous issue. Now it seems that you need to use 2.9.0.

Yeah, I'm still aiming for a tf text version that should work with tensorflow 2.8.x 😄

  1. Build and use are not the same, please do not build and use in the same environment, it is easy to cause unknown errors. Here I strongly recommend that you re-create a new environment to build.

Yes I have a separate environment for the service in which I'm installing and using the *.whl

  1. protobuf is automatically matched by tensorflow-deps, and there is no need to manually change it yourself. protobuf depends on the C library of libprotobuf, and manual installation often produces mismatch errors (you can find import protobuf errors).

The issue with protobuf, both in the build and usage environments, is that it complains about the version when i try to import tensorflow. (tensorflow-macos 2.8.0 installed)

  1. To build text 2.9.0 please switch to branch v2.9, now it seems that you did not read this tutorial clearly, completely referring to this tutorial should not cause the problem of manually modifying protobuf.

No I've read it multiple of times, and I switched out 2.9.0 for 2.8.0 and checkout the branch v2.8. (some feedback though would be to update step 4 to actually mention checking out the branch and not download the taged release as using the tags was casing me issue initially)

nilpath commented 2 years ago

these are the conda and pip packages installed in the build environment which includes a downgrade of protobuf in both conda and pip list

pre downgrading protobuf it seems to be set to protobuf==4.21.7

conda packages

# packages in environment at /Users/.../miniforge3/envs/tensorflow-macos:
#
# Name                    Version                   Build  Channel
absl-py                   1.2.0                    pypi_0    pypi
astunparse                1.6.3                    pypi_0    pypi
bzip2                     1.0.8                h3422bc3_4    conda-forge
c-ares                    1.18.1               h3422bc3_0    conda-forge
ca-certificates           2022.9.24            h4653dfc_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cachetools                5.2.0                    pypi_0    pypi
certifi                   2022.9.24                pypi_0    pypi
charset-normalizer        2.1.1                    pypi_0    pypi
flatbuffers               22.9.24                  pypi_0    pypi
gast                      0.5.3                    pypi_0    pypi
google-auth               2.12.0                   pypi_0    pypi
google-auth-oauthlib      0.4.6                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpc-cpp                  1.48.1               h55edf5b_1    conda-forge
grpcio                    1.48.1           py38h9dcc83b_1    conda-forge
h5py                      3.6.0           nompi_py38hacf61ce_100    conda-forge
hdf5                      1.12.1          nompi_hd9dbc9e_104    conda-forge
idna                      3.4                      pypi_0    pypi
importlib-metadata        5.0.0                    pypi_0    pypi
keras                     2.8.0                    pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
krb5                      1.19.3               he492e65_0    conda-forge
libabseil                 20220623.0      cxx17_h28b99d4_4    conda-forge
libblas                   3.9.0           16_osxarm64_openblas    conda-forge
libcblas                  3.9.0           16_osxarm64_openblas    conda-forge
libclang                  14.0.6                   pypi_0    pypi
libcurl                   7.85.0               h1c293e1_0    conda-forge
libcxx                    14.0.6               h2692d47_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h642e427_1    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgfortran               5.0.0           11_3_0_hd922786_25    conda-forge
libgfortran5              11.3.0              hdaf2cc0_25    conda-forge
liblapack                 3.9.0           16_osxarm64_openblas    conda-forge
libnghttp2                1.47.0               h519802c_1    conda-forge
libopenblas               0.3.21          openmp_hc731615_3    conda-forge
libprotobuf               3.21.7               hb5ab8b9_0    conda-forge
libsqlite                 3.39.4               h76d750c_0    conda-forge
libssh2                   1.10.0               h7a5bd25_3    conda-forge
libzlib                   1.2.12               h03a7124_4    conda-forge
llvm-openmp               14.0.4               hd125106_0    conda-forge
markdown                  3.4.1                    pypi_0    pypi
markupsafe                2.1.1                    pypi_0    pypi
ncurses                   6.3                  h07bb92c_1    conda-forge
numpy                     1.21.6           py38hf29d37f_0    conda-forge
oauthlib                  3.2.1                    pypi_0    pypi
openssl                   3.0.5                h03a7124_2    conda-forge
opt-einsum                3.3.0                    pypi_0    pypi
pip                       22.2.2             pyhd8ed1ab_0    conda-forge
protobuf                  3.19.4                   pypi_0    pypi
pyasn1                    0.4.8                    pypi_0    pypi
pyasn1-modules            0.2.8                    pypi_0    pypi
python                    3.8.13          hd3575e6_0_cpython    conda-forge
python_abi                3.8                      2_cp38    conda-forge
re2                       2022.06.01           h9a09cb3_0    conda-forge
readline                  8.1.2                h46ed386_0    conda-forge
requests                  2.28.1                   pypi_0    pypi
requests-oauthlib         1.3.1                    pypi_0    pypi
rsa                       4.9                      pypi_0    pypi
setuptools                65.4.1             pyhd8ed1ab_0    conda-forge
six                       1.15.0                   pypi_0    pypi
sqlite                    3.39.4               h2229b38_0    conda-forge
tensorboard               2.8.0                    pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1                    pypi_0    pypi
tensorflow-deps           2.8.0                         0    apple
tensorflow-macos          2.8.0                    pypi_0    pypi
tensorflow-metal          0.5.0                    pypi_0    pypi
termcolor                 2.0.1                    pypi_0    pypi
tf-estimator-nightly      2.8.0.dev2021122109          pypi_0    pypi
tk                        8.6.12               he1e0b03_0    conda-forge
typing-extensions         4.4.0                    pypi_0    pypi
urllib3                   1.26.12                  pypi_0    pypi
werkzeug                  2.2.2                    pypi_0    pypi
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
wrapt                     1.14.1                   pypi_0    pypi
xz                        5.2.6                h57fd34a_0    conda-forge
zipp                      3.9.0                    pypi_0    pypi
zlib                      1.2.12               h03a7124_4    conda-forge

pip packages

Package                 Version
----------------------- -------------------
absl-py                 1.2.0
astunparse              1.6.3
cached-property         1.5.2
cachetools              5.2.0
certifi                 2022.9.24
charset-normalizer      2.1.1
flatbuffers             22.9.24
gast                    0.5.3
google-auth             2.12.0
google-auth-oauthlib    0.4.6
google-pasta            0.2.0
grpcio                  1.48.1
h5py                    3.6.0
idna                    3.4
importlib-metadata      5.0.0
keras                   2.8.0
Keras-Preprocessing     1.1.2
libclang                14.0.6
Markdown                3.4.1
MarkupSafe              2.1.1
numpy                   1.21.6
oauthlib                3.2.1
opt-einsum              3.3.0
pip                     22.2.2
protobuf                3.19.4
pyasn1                  0.4.8
pyasn1-modules          0.2.8
requests                2.28.1
requests-oauthlib       1.3.1
rsa                     4.9
setuptools              65.4.1
six                     1.15.0
tensorboard             2.8.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit  1.8.1
tensorflow-macos        2.8.0
tensorflow-metal        0.5.0
termcolor               2.0.1
tf-estimator-nightly    2.8.0.dev2021122109
typing_extensions       4.4.0
urllib3                 1.26.12
Werkzeug                2.2.2
wheel                   0.37.1
wrapt                   1.14.1
zipp                    3.9.0
nilpath commented 2 years ago

I've noticed a weird issue in conda though that after installing tensorflow-deps 2.8.0 it switches my python version from 3.8 to 3.10.. deactivating and activating the conda env fixes it though

sun1638650145 commented 2 years ago

There are several questions based on the available information.

  1. The version of tensorflow-metal does not match, it should be 0.4.
  2. tensorflow-macos 2.8.0 only supports Python 3.8 and 3.9.
sun1638650145 commented 2 years ago

I've noticed a weird issue in conda though that after installing tensorflow-deps 2.8.0 it switches my python version from 3.8 to 3.10.. deactivating and activating the conda env fixes it though

Did you update to the latest conda?

sun1638650145 commented 2 years ago

I forgot a very important information, have you cleaned the cache of bazel? The path is in /private/var/tmp/_bazel_your_username/. bazel will use the compile cache to speed up the compilation, but it will also cause the previous error is reserved.

nilpath commented 2 years ago

I've noticed a weird issue in conda though that after installing tensorflow-deps 2.8.0 it switches my python version from 3.8 to 3.10.. deactivating and activating the conda env fixes it though

Did you update to the latest conda?

yes i did

nilpath commented 2 years ago

still same results

  1. reinstalled conda and used brew instead (solved issue with conda switching versions on me, only using 3.8.13)
  2. used tensorflow-metal 0.4.0 instead (although i don't understand how one should know to use this one instead?)
  3. cleared the contents of /private/var/tmp/_bazel_your_username/

still have the same issue

nilpath commented 2 years ago

I now notice that we might have missunderstood each other regarding the branch checkout...

I thought we were discussing which branch to checkout in tensorflow-text but I now realise that you might have ment to checkout the v2.8 branch in this repo?

nilpath commented 2 years ago

Ok I got it working

I started over from scratch and reinstalled miniforge and bazel and followed your instructions in your v2.8 branch with the additional instructions to install tensorflow-macos 2.8.0 and tensorflow-metal 0.4.0 as well as protobuf 3.20.3

however, I got stuck at a build error and had to follow these instructions https://github.com/tensorflow/text/issues/823#issuecomment-1030305965

after making that fix and reuning the build it I was got a working whl that also were importable in my service

wijnanduu commented 2 years ago

I had similar error messages related to mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'), it was solved for me by following the tutorial using mamba instead of conda.