wrapt: this __dict__ descriptor does not support '_DictWrapper' objects \ since version 1.15.0

Using tf2onnx with the following requirements I ran into a to me unexplainable error. The problem came out of no where, as the same code worked only days before.

requirements:

- opencv-python==4.7.0.68
- segmentation-models==1.0.1
- tensorflow==2.7.4
- numpy==1.24.2
- tensorflow-addons==0.15.0
- pandas==1.3.5
- Pillow==9.4.0
- scikit-image==0.18.3
- tqdm==4.62.3
- fire==0.5.0
- tf2onnx==1.12.1

Error Traceback

File "steps/tf_onnx_conversion.py", line 39, in convert_tf_to_onnx
   convert_tf2onnx()
 File "/databricks/conda/envs/mlflow-.../lib/python3.8/site-packages/tf2onnx/convert.py", line 238, in main
   graph_def, inputs, outputs, initialized_tables, tensors_to_rename = tf_loader.from_saved_model(
 File "/databricks/conda/envs/mlflow-.../lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 614, in from_saved_model
   _from_saved_model_v2(model_path, input_names, output_names,
 File "/databricks/conda/envs/mlflow-.../lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 598, in _from_saved_model_v2
   frozen_graph, initialized_tables = from_trackable(imported, concrete_func, inputs, outputs, large_model)
 File "/databricks/conda/envs/mlflow-.../lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 232, in from_trackable
   _get_hash_table_info_from_trackable(trackable, table_info,
 File "/databricks/conda/envs/mlflow-.../lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 467, in _get_hash_table_info_from_trackable
   for t in r.__dict__.values() if hasattr(r, '__dict__') else []:
 File "/databricks/conda/envs/mlflow-.../lib/python3.8/site-packages/tensorflow/python/training/tracking/data_structures.py", line 828, in __getattribute__
   return super(_DictWrapper, self).__getattribute__(name)
TypeError: this __dict__ descriptor does not support '_DictWrapper' objects

I pinned the problem down to one unfrozen dependency in tensorflow: wrapt>=1.11.0 While the old unproblematic runs had 1.14.1 installed, the new failed runs installed 1.15.0 By freezing this to wrapt==1.14.1 I was able to solve the issue.

There are other users reporting similar problems on stackoverflow and the tf2onnx issues.

@GrahamDumpleton Maybe this is an issue with the new release?

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 22 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Also, the error message TypeError: this __dict__ descriptor does not support '_DictWrapper' objects is raised from CPython, typeobject.c.

So the best TensorFlow can do is to catch it and reraise as an Attribute error, like this:

try:
  return super().__getattribute__(name)
except TypeError as e:
  raise AttributeError from e

Or something similar along the lines.

I tried that and the test case in https://github.com/GrahamDumpleton/wrapt/issues/231#issuecomment-1456979294 finished without that error.

The pattern was used in several child classes of wrapt objects in data_structures.py in TensorFlow. If this change looks good to you. I can patch them all up. Although I am still quite puzzled (and I am in general puzzled) by the getattribute behavior in Python.

To summarise at this point as I don’t think I can do anything more.

The behaviour of wrapt changed for the C extension when a bug in wrapt was fixed that caused suppression of exceptions when they should have been raised. With wrapt code now behaving correctly, that resulted in tensorflow acting a bit differently likely due to some inner works of how Python __getattribute__ works when it sees exceptions on trying to look up attributes. This caused tensorflow code which overrides __getattribute__ to see types.MappingProxyType objects when it didn’t previously but it’s code doesn’t handle that case and started failing. The reason that the pure Python version of wrapt always worked is because the layers of calls when you have Python implementations of things does result in Python core operating a bit differently and so it uses a different code path to achieve the same end, and in that case it used a path which meant didn’t see the problem.

At this point I really need someone in tensorflow community of authors to try with the code above which raises an AttributeError for the specific case of accessing __dict__ on __dict__ and see if their code all still works as expected.