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

Fix Array defaults for struct.PyTreeNode #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

timoklein
Copy link

I've been working some on this and made a little progress at least: I'm fetching the default values for all jax.Arrays and setting a field with default_factory= lambda: default.

The problem is now that Python only remembers the last value for default from the loop, and thus will initialize all other Array attributes erroneously to this value.

@timoklein timoklein marked this pull request as draft October 26, 2024 10:32
@timoklein timoklein force-pushed the fix-array-dataclasses branch from 5c1d3c9 to 9195fcc Compare October 28, 2024 08:25
@timoklein
Copy link
Author

@epignatelli The code now passes all tests. The solution can probably be made more elegant.

What's the best way to test/benchmark that no funny business occurs during compilation?

I tried running some scripts under test/performance, but they threw errors for me, e.g.,

TypeError: scan body function carry input and carry output must have the same pytree structure, but they differ: The input carry component c.info is a <class 'dict'> with 0 child but the corresponding component of the carry output is a <class 'dict'> with 1 child, so the numbers of children do not match, with the symmetric difference of key sets: {'return'}.

when running python tests/performance/grid.py.

@timoklein timoklein force-pushed the fix-array-dataclasses branch from 9195fcc to 3e55461 Compare October 28, 2024 12:19
@timoklein timoklein changed the title WIP: Fix Array defaults for struct.PyTreeNode Fix Array defaults for struct.PyTreeNode Nov 12, 2024
@timoklein timoklein marked this pull request as ready for review November 12, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant