tensorflow: typing_extensions >= 4.6.0 causes pip unit test failure
Click to expand!
Issue Type
Bug
Have you reproduced the bug with TF nightly?
Yes
Source
source
Tensorflow Version
git HEAD
Custom Code
No
OS Platform and Distribution
Ubuntu 20.04
Mobile device
n/a
Python version
3.10
Bazel version
5.3.0
GCC/Compiler version
10.2.1
CUDA/cuDNN version
n/a
GPU model and memory
n/a
Current Behaviour?
//bazel_pip/tensorflow/python/trackable:data_structures_test will fail with typing_extensions >= 4.6.0 installed when run as a pip test against an installed TensorFlow wheel.
Standalone code to reproduce the issue
bazel test --build_tests_only --cache_test_results=no --config=mkl_aarch64_threadpool --copt=-flax-vector-conversions --jobs=75 --test_env=TF_ENABLE_ONEDNN_OPTS=1 --test_env=TF2_BEHAVIOR=1 --define=no_tensorflow_py_deps=true --test_lang_filters=py --test_size_filters=small,medium --test_output=errors --verbose_failures=true //bazel_pip/tensorflow/python/trackable:data_structures_test
Relevant log output
======================================================================
ERROR: testFunctionCaching (__main__.MappingTests)
MappingTests.testFunctionCaching
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/execroot/org_tensorflow/bazel-out/aarch64-opt/bin/bazel_pip/tensorflow/python/trackable/data_structures_test.runfiles/org_tensorflow/bazel_pip/tensorflow/python/trackable/data_structures_test.py", line 507, in testFunctionCaching
second_trace = f.get_concrete_function(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1198, in get_concrete_function
concrete = self._get_concrete_function_garbage_collected(*args, **kwargs)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1189, in _get_concrete_function_garbage_collected
concrete = self._variable_creation_fn.get_concrete_function(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 197, in get_concrete_function
concrete_function, _ = self._maybe_define_concrete_function(args, kwargs)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 172, in _maybe_define_concrete_function
return self._maybe_define_function(args, kwargs)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 294, in _maybe_define_function
function_type_utils.make_canonicalized_monomorphic_type(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/function_type_utils.py", line 378, in make_canonicalized_monomorphic_type
function_type_lib.canonicalize_to_monomorphic(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/core/function/polymorphism/function_type.py", line 481, in canonicalize_to_monomorphic
_make_validated_mono_param(name, arg, poly_parameter.kind,
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/core/function/polymorphism/function_type.py", line 421, in _make_validated_mono_param
mono_type = trace_type.from_value(value, type_context)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/core/function/trace_type/trace_type_builder.py", line 142, in from_value
elif isinstance(value, trace.SupportsTracingProtocol):
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/typing_extensions.py", line 605, in __instancecheck__
val = inspect.getattr_static(instance, attr)
File "/usr/lib/python3.8/inspect.py", line 1596, in getattr_static
instance_result = _check_instance(obj, attr)
File "/usr/lib/python3.8/inspect.py", line 1543, in _check_instance
instance_dict = object.__getattribute__(obj, "__dict__")
TypeError: this __dict__ descriptor does not support '_DictWrapper' objects
======================================================================
ERROR: testFunctionCaching (__main__.TupleTests)
TupleTests.testFunctionCaching
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/execroot/org_tensorflow/bazel-out/aarch64-opt/bin/bazel_pip/tensorflow/python/trackable/data_structures_test.runfiles/org_tensorflow/bazel_pip/tensorflow/python/trackable/data_structures_test.py", line 716, in testFunctionCaching
second_trace = f.get_concrete_function(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1198, in get_concrete_function
concrete = self._get_concrete_function_garbage_collected(*args, **kwargs)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1189, in _get_concrete_function_garbage_collected
concrete = self._variable_creation_fn.get_concrete_function(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 197, in get_concrete_function
concrete_function, _ = self._maybe_define_concrete_function(args, kwargs)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 172, in _maybe_define_concrete_function
return self._maybe_define_function(args, kwargs)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 294, in _maybe_define_function
function_type_utils.make_canonicalized_monomorphic_type(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/python/eager/polymorphic_function/function_type_utils.py", line 378, in make_canonicalized_monomorphic_type
function_type_lib.canonicalize_to_monomorphic(
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/core/function/polymorphism/function_type.py", line 481, in canonicalize_to_monomorphic
_make_validated_mono_param(name, arg, poly_parameter.kind,
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/core/function/polymorphism/function_type.py", line 421, in _make_validated_mono_param
mono_type = trace_type.from_value(value, type_context)
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/tensorflow/core/function/trace_type/trace_type_builder.py", line 142, in from_value
elif isinstance(value, trace.SupportsTracingProtocol):
File "/workspace/pip_test/venv_clean/lib/python3.8/site-packages/typing_extensions.py", line 605, in __instancecheck__
val = inspect.getattr_static(instance, attr)
File "/usr/lib/python3.8/inspect.py", line 1596, in getattr_static
instance_result = _check_instance(obj, attr)
File "/usr/lib/python3.8/inspect.py", line 1543, in _check_instance
instance_dict = object.__getattribute__(obj, "__dict__")
TypeError: this __dict__ descriptor does not support '_TupleWrapper' objects
----------------------------------------------------------------------
Ran 74 tests in 1.021s
FAILED (errors=2, skipped=4)
================================================================================
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (5 by maintainers)
Commits related to this issue
- Limit the version of wrapt to be used to prevent unit test failures A change in the behaviour of wrapt ends up in a unit test failure for TensorFlow. This can be removed once mitigation in TensorFlow... — committed to elfringham/tensorflow by elfringham 3 years ago
- Remove pin on typing_extensions. Fixes https://github.com/tensorflow/probability/issues/1753 See also https://github.com/tensorflow/tensorflow/issues/60687 and https://github.com/tensorflow/tensorfl... — committed to tensorflow/probability by ColCarroll 3 years ago
- Remove pin on typing_extensions. Fixes https://github.com/tensorflow/probability/issues/1753 See also https://github.com/tensorflow/tensorflow/issues/60687 and https://github.com/tensorflow/tensorfl... — committed to tensorflow/probability by ColCarroll 3 years ago
@tommyzieba You can see from https://github.com/tensorflow/tensorflow/pull/61387 that there is no longer an upper limit on typing-extensions in git HEAD and that this will be picked up by the next release of TensorFlow which will be 2.14.0.
A consequence of this is that Tensorflow is not compatible with Pydantic V2 due to the restraints on typing_extensions Is there any roadmap to loosen this?
Is this issue still active? It looks like it is about to cause an issue for keras-core with the 2.14 release, probably other things affected as well.
https://colab.research.google.com/gist/mattdangerw/019d1ebcec746d6f7424248911cf16ae/tf-2-14-bug.ipynb
More directly, with keras out of the picture, I think the minimal repro below will cause failures in the tensorflow 2.14 docker images (which have a more recent
typing_extensions).Is anything being done to loosen the upper bound on typing-extensions here? This continues to cause issues on macOS.
I have a Pipfile which includes
pydantic,pydantic-settings, andtensorflowas packages. Locking packages with a pre-release flag using pipenv works fine with pre-release tag2.13.0-rc1. However I cannot include tensorflow in this project without using the pre-release. Here is the output from pipenv when manually installing the latest pydantic-settings, which indicates thattensorflow-macosis the problem which seems to be related to the upperbound of typing-extensions versions here. Everything installs just fine on a Windows OS with the most recent versions of packages and without a pre-release flag.The rough cause of error is here. The current getattribute for dictwrapper can return TypeError. When an attribute is not found it’s instead expected to return AttributeError. Finding place that produces TypeError and replacing it with AttributeError should fix typing extensions incompatibility. typing 4.6 uses inspect.getattr_static which expects that failed attribute access using getattribute only triggers attribute error.
This particular error will also be an error if you try to run tensorflow on python 3.12. The typing extensions change was motivated from here.
edit: Minimal version of this error is,
The last line raises TypeError. On other hand
t.__dict__properly raises AttributeError. DictWrapper’s custom getattribute is rough area that needs bug fix.The error message comes from here. I’ve cross posted in cpython side as unsure whether this tensorflow bug or cpython bug.