Add tree-mode support for nnx.shard_map#5238
Merged
copybara-service[bot] merged 1 commit intomainfrom Feb 12, 2026
Merged
Conversation
dd29b8e to
7a6fc17
Compare
Extends nnx.shard_map with a `graph` parameter (defaulting to True for backward compatibility). When graph=False, shard_map operates in tree-mode using pytree-based state propagation, mirroring the existing tree-mode for nnx.jit. Tree-mode assumes referential transparency, doesn't propagate graph updates (only Variable updates are propagated), StateSharding is not supported / needed. Tree-mode offers a simpler, more JAX-native usage pattern that treats Modules as simple stateless pytrees, and only Variables state is automatically handled. PiperOrigin-RevId: 869026486
7a6fc17 to
0bfe50a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add tree-mode support for nnx.shard_map
Extends nnx.shard_map with a
graphparameter (defaulting to True forbackward compatibility). When graph=False, shard_map operates in tree-mode
using pytree-based state propagation, mirroring the existing tree-mode
for nnx.jit. Tree-mode assumes referential transparency, doesn't propagate graph updates (only Variable updates are propagated), StateSharding is not supported / needed.
Tree-mode offers a simpler, more JAX-native usage pattern that treats Modules as simple stateless pytrees, and only Variables state is automatically handled.