[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: this __dict__ descriptor does not support '_DictWrapper' objects #62217

Open
mattdangerw opened this issue Oct 25, 2023 · 14 comments
Open
Assignees
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:bug Bug type:support Support issues

Comments

@mattdangerw
Copy link
Member
mattdangerw commented Oct 25, 2023

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

binary

TensorFlow version

nightly

Custom code

Yes

OS platform and distribution

Colab

Python version

3.10

Current behavior?

  • Install a clean tensorflow environment with the latest typing-extensions pip package.
  • Assign a dictionary to a tf.Module (will wrap it in a _DictWrapper for tracking).
  • Output that dictionary from a tf.function.
  • TypeError: this __dict__ descriptor does not support '_DictWrapper' objects.

This is somewhat of a zombie bug, see #60687.

This is important because it breaks all keras functional models with dictionary output, but is not a keras bug. This can be reproduced simply with low-level tensorflow.

We either need to continue pinning an older version of typing extensions, or fix tensorflow to work with the latest version of typing extension. The latter seems less likely to keep breaking.

Standalone code to reproduce the issue

https://colab.research.google.com/gist/mattdangerw/6904dc4ab29ff936ad3c3b966848f463/dict-output-bug.ipynb

Relevant log output

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-4a26ae41286e> in <cell line: 12>()
     10 x = tf.constant([2, 3])
     11 y = tf.constant([3, -2])
---> 12 f(x, y)

4 frames
/usr/local/lib/python3.10/dist-packages/tensorflow/python/util/traceback_utils.py in error_handler(*args, **kwargs)
    151     except Exception as e:
    152       filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153       raise e.with_traceback(filtered_tb) from None
    154     finally:
    155       del filtered_tb

/usr/local/lib/python3.10/dist-packages/tensorflow/core/function/trace_type/trace_type_builder.py in from_value(value, context)
    142   if context.is_legacy_signature and isinstance(value, trace.TraceType):
    143     return value
--> 144   elif isinstance(value, trace.SupportsTracingProtocol):
    145     generated_type = value.__tf_tracing_type__(context)
    146     if not isinstance(generated_type, trace.TraceType):

/usr/local/lib/python3.10/dist-packages/typing_extensions.py in __instancecheck__(cls, instance)
    601             for attr in cls.__protocol_attrs__:
    602                 try:
--> 603                     val = inspect.getattr_static(instance, attr)
    604                 except AttributeError:
    605                     break

/usr/lib/python3.10/inspect.py in getattr_static(obj, attr, default)
   1741         if (dict_attr is _sentinel or
   1742             type(dict_attr) is types.MemberDescriptorType):
-> 1743             instance_result = _check_instance(obj, attr)
   1744     else:
   1745         klass = obj

/usr/lib/python3.10/inspect.py in _check_instance(obj, attr)
   1688     instance_dict = {}
   1689     try:
-> 1690         instance_dict = object.__getattribute__(obj, "__dict__")
   1691     except AttributeError:
   1692         pass

TypeError: this __dict__ descriptor does not support '_DictWrapper' objects
@google-ml-butler google-ml-butler bot added type:bug Bug type:support Support issues labels Oct 25, 2023
mattdangerw added a commit to mattdangerw/keras that referenced this issue Oct 25, 2023
In keras-team#18507 we removed a hacky
workaround for functional models so dictionary output is not made a
trackable.

We actually still need this when calling `predict` on a functional with
dictionary output.

Added testing to plug the coverage gap. Still no idea what the status
of the underlying bug is :/, filed with tensorflow

tensorflow/tensorflow#62217
fchollet pushed a commit to keras-team/keras that referenced this issue Oct 25, 2023
In #18507 we removed a hacky
workaround for functional models so dictionary output is not made a
trackable.

We actually still need this when calling `predict` on a functional with
dictionary output.

Added testing to plug the coverage gap. Still no idea what the status
of the underlying bug is :/, filed with tensorflow

tensorflow/tensorflow#62217
@tilakrayal tilakrayal added the comp:apis Highlevel API related issues label Oct 26, 2023
@tilakrayal
Copy link
Contributor

@sachinprasadhs,
I was able to reproduce the issue on tf-nightly -2.16.0-dev20231026. Kindly find the gist of it here.

@plopresti
Copy link
Contributor

Is there an easy patch to fix this for TF2.15? E.g. can I just downrev typing_extensions in pip_package/setup.py?

@plopresti
Copy link
Contributor

To answer my own question: Yes. Just applying the change from #60688 fixes this for us.

@tilakrayal
Copy link
Contributor

@plopresti,
I tried to execute the code available on the colab with the latest tf-nightly(2.16.0-dev20240125) along with the keras3.0 version and it was executed without any issue/error. Kindly find the gist of it here. Thank you!

@tilakrayal tilakrayal added the stat:awaiting response Status - Awaiting response from author label Jan 26, 2024
@tilakrayal tilakrayal self-assigned this Jan 26, 2024
@tilakrayal tilakrayal removed the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jan 26, 2024
@plopresti
Copy link
Contributor

@tilakrayal Yes, our reproducer also passes on tf-nightly.

I wonder what change fixed it. Anyway this does not appear to be an issue with latest builds.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Jan 29, 2024
@tilakrayal
Copy link
Contributor

@plopresti,
Yeah the changes have happened with the respective PR keras-team/keras#18682.


 if backend() == "tensorflow":
            # This stop tensorflow from wrapping tf.function output in a
            # _DictWrapper object.
            _self_setattr_tracking = getattr(
                self, "_self_setattr_tracking", True
            )
            self._self_setattr_tracking = False

Thank you!

@tilakrayal tilakrayal added the stat:awaiting response Status - Awaiting response from author label Jan 30, 2024
@mihaimaruseac
Copy link
Collaborator

At this point, given that keras fixed it, this issue can be closed, I think

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Jan 30, 2024
@tilakrayal tilakrayal added the stat:awaiting response Status - Awaiting response from author label Jan 31, 2024
Copy link
github-actions bot commented Feb 8, 2024

This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Feb 8, 2024
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@plopresti
Copy link
Contributor

@tilakrayal

This issue is happening for us again with the r2.17 branch.

export WRAPT_DISABLE_EXTENSIONS=true (per #60687 (comment)) appears to work around it. But I am unsure what the knock-on effects of that might be.

Rebuilding TensorFlow after patching tensorflow/tools/pip_package/setup.py to force typing_extensions<4.6.0 also works around it.

I have confirmed our Keras version (3.3.3) has the change you cite above.

I am at a loss for how to proceed and would welcome any suggestion. Thank you!

@plopresti
Copy link
Contributor

Here is our trvial test program that blows up with TypeError: this __dict__ descriptor does not support '_DictWrapper' objects

#!/usr/bin/env python

import tensorflow as tf

@tf.function
def f(x, y):
  test = tf.Module()
  test.output = {
      "foo": x ** 2 + y,
      "bar": x ** 2 - y,
  }
  return test.output

x = tf.constant([2, 3])
y = tf.constant([3, -2])
f(x, y)

print('no bug!')`

@plopresti
Copy link
Contributor

@mihaimaruseac
Copy link
Collaborator

I'm going to reopen this issue since this definitely is not resolved

@mihaimaruseac mihaimaruseac reopened this Jun 13, 2024
@github-actions github-actions bot removed stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author labels Jun 14, 2024
@tilakrayal tilakrayal added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jun 14, 2024
@tilakrayal tilakrayal removed their assignment Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:bug Bug type:support Support issues
Projects
None yet
Development

No branches or pull requests

6 participants