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

JAX backend doesn't use jax.tree_util #1785

Open
krzysztofrusek opened this issue Jan 27, 2024 · 1 comment
Open

JAX backend doesn't use jax.tree_util #1785

krzysztofrusek opened this issue Jan 27, 2024 · 1 comment

Comments

@krzysztofrusek
Copy link

In this part, expand_composites is set to False and this prevents jax.tree_util for kicking in.

def map_structure(func, *structure, **kwargs):
"""Add expand_composites support for JAX."""
expand_composites = kwargs.pop('expand_composites', False)
if expand_composites and JAX_MODE:
from jax import tree_util # pylint: disable=g-import-not-at-top
return tree_util.tree_map(func, *structure)
return dm_tree.map_structure(func, *structure, **kwargs)

The resulting problem is that we cannot use pytree incompatible with dm_tree

Herę is notebook reproducing the bug
https://colab.research.google.com/gist/krzysztofrusek/a9fa71ca2bf3952a9f18358309225107/eqx_tfp.ipynb

@SiegeLordEx
Copy link
Member

expand_composites should probably be set to True in that location. There are other locations of similar nature where it is set to True (e.g.

initial_state, expand_composites=True)
,
flat_p = tf.nest.flatten(proposed, expand_composites=True)
), so I don't see an obvious reason why it shouldn't be True here as well.

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