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

[nnx] non-str State keys #3802

Merged
merged 1 commit into from
Apr 1, 2024
Merged

[nnx] non-str State keys #3802

merged 1 commit into from
Apr 1, 2024

Conversation

cgarciae
Copy link
Collaborator

@cgarciae cgarciae commented Mar 30, 2024

What does this PR do?

  • Graph node can now emit non-string keys, this helps to sort int keys such as to from list and tuple. In general they can emit any type that implement the Key protocol, which is any Hashable object that also implements __lt__.
  • State now contains Key keys.
  • State.flat_state now returns a dict[tuple[Key, ...], Any] instead of dict[str, Any] with keys as / separated strings.
  • State.from_flat_path now creates a State from a dict[tuple[Key, ...], Any].
  • _graph_node_* functions are now methods of GraphNode.
  • List now emits int keys. To implement the graph node protocol correctly it overrides a couple of _graph_node_* methods.
  • Fixed graph_pop bug.

@cgarciae cgarciae force-pushed the nnx-graph-non-str-keys branch 3 times, most recently from 0a6b17e to 3eea173 Compare March 30, 2024 13:10
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@cgarciae cgarciae force-pushed the nnx-graph-non-str-keys branch 2 times, most recently from 89d33e0 to c987dbb Compare March 30, 2024 13:18
@cgarciae cgarciae changed the base branch from main to nnx-static-goes-first March 30, 2024 13:21
@cgarciae cgarciae force-pushed the nnx-graph-non-str-keys branch 2 times, most recently from 59ffe8d to cc53978 Compare March 30, 2024 18:41
@cgarciae cgarciae marked this pull request as ready for review March 30, 2024 23:14
Base automatically changed from nnx-static-goes-first to main April 1, 2024 19:26
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 94.26230% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 60.34%. Comparing base (cc740d4) to head (1d5f718).

Files Patch % Lines
flax/experimental/nnx/nnx/graph_utils.py 94.44% 3 Missing ⚠️
flax/experimental/nnx/nnx/helpers.py 76.92% 3 Missing ⚠️
flax/typing.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3802   +/-   ##
=======================================
  Coverage   60.34%   60.34%           
=======================================
  Files         101      101           
  Lines       12862    12875   +13     
=======================================
+ Hits         7761     7769    +8     
- Misses       5101     5106    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@copybara-service copybara-service bot merged commit 30fb7ff into main Apr 1, 2024
21 checks passed
@copybara-service copybara-service bot deleted the nnx-graph-non-str-keys branch April 1, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants