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] make State generic #3964

Merged
merged 1 commit into from
Jun 6, 2024
Merged

[nnx] make State generic #3964

merged 1 commit into from
Jun 6, 2024

Conversation

cgarciae
Copy link
Collaborator

@cgarciae cgarciae commented Jun 4, 2024

What does this PR do?

Fixes #3955.

  • Makes State generic as State[K, V].
  • State annotations in graph are redifined as GraphState = State[Key, StateLeaf].

Comment on lines +53 to +55
StateLeaf = tp.Union[VariableState[tp.Any], np.ndarray, jax.Array]
GraphState = State[Key, StateLeaf]
GraphFlatState = FlatState[StateLeaf]
Copy link
Collaborator

@chiamp chiamp Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for clarification, GraphState is a State, but StateLeaf, FlatState and GraphFlatState are not State's?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, State[K, V] is now a generic mapping, GraphState is a type alias for a specific type of State as returned by the graph APIs, and LeafState is a union describing the possible types of leaves you find in GraphState.

@copybara-service copybara-service bot merged commit 89c0802 into main Jun 6, 2024
21 checks passed
@copybara-service copybara-service bot deleted the nnx-generalize-state branch June 6, 2024 10:44
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.

optax.multi_transform + nnx.State/nnx.Optimizer troubles
2 participants