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

Chex dataclass throws an exception in Python 3.9 #10

Closed
dionhaefner opened this issue Feb 5, 2021 · 1 comment
Closed

Chex dataclass throws an exception in Python 3.9 #10

dionhaefner opened this issue Feb 5, 2021 · 1 comment

Comments

@dionhaefner
Copy link

$ python --version
Python 3.9.1
In [1]: import chex

In [2]: @chex.dataclass
   ...: class Parameters:
   ...:   x: chex.ArrayDevice
   ...:   y: chex.ArrayDevice
   ...:
   ...: parameters = Parameters(
   ...:     x=jnp.ones((2, 2)),
   ...:     y=jnp.ones((1, 2)),
   ...: )
   ...:
   ...: # Dataclasses can be treated as JAX pytrees
   ...: jax.tree_map(lambda x: 2.0 * x, parameters)
   ...:
   ...: # and as mappings by dm-tree
   ...: tree.flatten(parameters)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-3461a2700932> in <module>
      1 @chex.dataclass
----> 2 class Parameters:
      3   x: chex.ArrayDevice
      4   y: chex.ArrayDevice
      5

~/.virtualenvs/science/lib/python3.9/site-packages/chex/_src/dataclass.py in dataclass(cls, init, repr, eq, order, unsafe_hash, frozen, mappable_dataclass, restricted_inheritance)
    104   if cls is None:
    105     return dcls
--> 106   return dcls(cls)
    107
    108

~/.virtualenvs/science/lib/python3.9/site-packages/chex/_src/dataclass.py in __call__(self, cls)
    147
    148     if self.mappable_dataclass:
--> 149       dcls = mappable_dataclass(dcls, self.restricted_inheritance)
    150
    151     def _from_tuple(args):

~/.virtualenvs/science/lib/python3.9/site-packages/chex/_src/dataclass.py in mappable_dataclass(cls, restricted_inheritance)
     81   if cls.__bases__ == (object,):
     82     # `collections.Mapping` is incompatible with `object`
---> 83     cls.__bases__ = (collections.Mapping,)
     84   else:
     85     cls.__bases__ += (collections.Mapping,)

TypeError: __bases__ assignment: 'Mapping' deallocator differs from 'object'
@hbq1
Copy link
Collaborator

hbq1 commented Feb 8, 2021

Thanks a lot for filing this bug! It should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants