-
Notifications
You must be signed in to change notification settings - Fork 74.9k
Description
Issue Type
Bug
Source
binary
Tensorflow Version
tf 2.9.0-rc2
Custom Code
No
OS Platform and Distribution
Linux Ubuntu 20.04
Mobile device
No response
Python version
3.10
Bazel version
No response
GCC/Compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current Behaviour?
This issue is to give a warning (that might already be known in internal CI) that protobuf v4.21.0-rc1 which was released today (2022-05-11) causes breaking changes in messages between Python and C++ that affect TensorFlow and will crash with
AttributeError: module 'google._upb._message' has no attribute 'Message'. Did you mean: 'CMessage'?on import tensorflow.
This is somewhat noted in the protobuf release notes for Python
The C extension module for Python has been rewritten to use the upb library. This is expected to deliver significant performance benefits, especially when parsing large payloads. There are some minor breaking changes, but these should not impact most users. For more information see: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
where the Python Updates notes mentions
Applications that rely on sharing messages between Python and C++ break in the new version. Most developers won't be affected by this, but users of
Nucleus{.external}and possibly other libraries may be. As a workaround, you can set an environment variable that forces the library to preserve compatibility.
which finally in Sharing Messages Between Python and C++ tells us that
Prior to Python 4.21.0, Python apps could share messages with C++ using a native extension. Starting in Python 4.21.0, sharing messages between Python and C++ is not supported by the default install. To enable this capability when working with 4.x and later versions of the Python API, define the environment variable,
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp, and ensure that the Python/C++ extension is installed.
However,
$ export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cppjust now leads to an
ImportError: cannot import name '_message' from 'google.protobuf.pyext' (/venv/lib/python3.10/site-packages/google/protobuf/pyext/__init__.py)Additionally tagging @deannagarcia who released protobuf v4.21.0-rc1.
This was noticed in pyhf's nightly pre-release and HEAD of dependencies CI jobs.
Standalone code to reproduce the issue
Here's a python:3.10 Docker image example
Click to exapnd:
$ docker run --rm -ti python:3.10 /bin/bash
root@a0c6928654f7:/# python -m venv venv && . venv/bin/activate
(venv) root@a0c6928654f7:/# python -m pip --quiet install --upgrade pip setuptools wheel
(venv) root@a0c6928654f7:/# python -m pip --quiet install 'tensorflow==2.8.0' # First show this with stable release v2.8.0
(venv) root@a0c6928654f7:/# python -m pip list | grep 'tensorflow\|protobuf'
protobuf 3.20.1
tensorflow 2.8.0
tensorflow-io-gcs-filesystem 0.25.0
(venv) root@a0c6928654f7:/# python -c 'import tensorflow; print(tensorflow.__version__)'
2022-05-12 03:21:47.631420: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-05-12 03:21:47.631464: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2.8.0
(venv) root@a0c6928654f7:/# python -m pip --quiet install --pre --upgrade protobuf
(venv) root@a0c6928654f7:/# python -m pip show protobuf
Name: protobuf
Version: 4.21.0rc1
Summary:
Home-page:
Author:
Author-email:
License:
Location: /venv/lib/python3.10/site-packages
Requires:
Required-by: tensorboard, tensorflow
(venv) root@a0c6928654f7:/# python -c 'import tensorflow'
2022-05-12 03:23:19.770470: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-05-12 03:23:19.770491: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/venv/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/venv/lib/python3.10/site-packages/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/function_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 36, in <module>
_descriptor.FieldDescriptor(
File "/venv/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 560, in __new__
_message.Message._CheckCalledFromGeneratedFile()
AttributeError: module 'google._upb._message' has no attribute 'Message'. Did you mean: 'CMessage'?
(venv) root@a0c6928654f7:/# export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp # try protobuf environment variable suggestion
(venv) root@a0c6928654f7:/# python -c 'import tensorflow'
2022-05-12 03:23:50.884921: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-05-12 03:23:50.884945: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
/venv/lib/python3.10/site-packages/google/protobuf/internal/api_implementation.py:109: UserWarning: Selected implementation cpp is not available.
warnings.warn(
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/venv/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/venv/lib/python3.10/site-packages/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/function_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "/venv/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 51, in <module>
from google.protobuf.pyext import _message
ImportError: cannot import name '_message' from 'google.protobuf.pyext' (/venv/lib/python3.10/site-packages/google/protobuf/pyext/__init__.py)
(venv) root@a0c6928654f7:/# unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
(venv) root@a0c6928654f7:/# python -m pip --quiet install --pre --upgrade tensorflow # Try release candidate v2.9.0-rc2
(venv) root@a0c6928654f7:/# python -m pip show tensorflow
Name: tensorflow
Version: 2.9.0rc2
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: /venv/lib/python3.10/site-packages
Requires: absl-py, astunparse, flatbuffers, gast, google-pasta, grpcio, h5py, keras, keras-preprocessing, libclang, numpy, opt-einsum, packaging, protobuf, setuptools, six, tensorboard, tensorflow-estimator, tensorflow-io-gcs-filesystem, termcolor, typing-extensions, wrapt
Required-by
(venv) root@a0c6928654f7:/# python -c 'import tensorflow'
2022-05-12 03:26:20.957106: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-05-12 03:26:20.957131: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/venv/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/venv/lib/python3.10/site-packages/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/function_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 36, in <module>
_descriptor.FieldDescriptor(
File "/venv/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 560, in __new__
_message.Message._CheckCalledFromGeneratedFile()
AttributeError: module 'google._upb._message' has no attribute 'Message'. Did you mean: 'CMessage'?
(venv) root@a0c6928654f7:/# export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
(venv) root@a0c6928654f7:/# python -c 'import tensorflow'
2022-05-12 03:27:01.166115: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-05-12 03:27:01.166141: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
/venv/lib/python3.10/site-packages/google/protobuf/internal/api_implementation.py:109: UserWarning: Selected implementation cpp is not available.
warnings.warn(
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/venv/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/venv/lib/python3.10/site-packages/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/function_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "/venv/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 51, in <module>
from google.protobuf.pyext import _message
ImportError: cannot import name '_message' from 'google.protobuf.pyext' (/venv/lib/python3.10/site-packages/google/protobuf/pyext/__init__.py)Relevant log output
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/venv/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/venv/lib/python3.10/site-packages/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/function_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 36, in <module>
_descriptor.FieldDescriptor(
File "/venv/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 560, in __new__
_message.Message._CheckCalledFromGeneratedFile()
AttributeError: module 'google._upb._message' has no attribute 'Message'. Did you mean: 'CMessage'?/venv/lib/python3.10/site-packages/google/protobuf/internal/api_implementation.py:109: UserWarning: Selected implementation cpp is not available.
warnings.warn(
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/venv/lib/python3.10/site-packages/tensorflow/__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/venv/lib/python3.10/site-packages/tensorflow/python/__init__.py", line 37, in <module>
from tensorflow.python.eager import context
File "/venv/lib/python3.10/site-packages/tensorflow/python/eager/context.py", line 29, in <module>
from tensorflow.core.framework import function_pb2
File "/venv/lib/python3.10/site-packages/tensorflow/core/framework/function_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "/venv/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 51, in <module>
from google.protobuf.pyext import _message
ImportError: cannot import name '_message' from 'google.protobuf.pyext' (/venv/lib/python3.10/site-packages/google/protobuf/pyext/__init__.py)