NNX migration prep (2/N): NNX utils and sharding utilities#3470
Draft
ecnal-cienet wants to merge 2 commits intomainfrom
Draft
NNX migration prep (2/N): NNX utils and sharding utilities#3470ecnal-cienet wants to merge 2 commits intomainfrom
ecnal-cienet wants to merge 2 commits intomainfrom
Conversation
- pure_nnx: a flag to to choose pure NNX logic when NNX and linen models co-exist. - init_state_fn: a function to initialize the model state for the training. It will be set to different function for NNX and Linen.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
7669e8e to
4fc37b6
Compare
- Add utils to manipulate the NNX shardings with abstract state of a
model
- also add unit tests for the utils
- Extract mesh creation function to maxtext_utils.get_mesh_from_config()
- also add unit tests for this func
Note:
flax v0.12 has DeprecationWarning in multiple places:
- DeprecationWarning: '.value' access is now deprecated. Use
variable.get_value() or variable[...] (for [Array]).
- DeprecationWarning: 'VariableState' was removed, this is just
an alias to 'Variable'. Plase use 'Variable' directly instead.
But since the code needs to work with post-training, which currently
requires flax v0.11, we didn't change code for these warnings.
4fc37b6 to
722386f
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.
Description
maxtext_utils_nnx.py) — Functions to manipulate NNX model shardings using abstract model state:get_named_sharding_nnx,set_named_sharding_nnx,get_partition_spec_nnx, and memory movement helpers (move_memory_to_host/move_memory_to_device).get_abstract_stateNNX path — Addedget_abstract_state_nnxtomaxtext_utils.py, which usesnnx.get_abstract_modelto return a flatnnx.State(rather than a fullTrainStateNNX), and updatedget_abstract_stateto dispatch to it whenpure_nnx=True.maxtext_utils.get_mesh_from_config()— Extracted mesh creation into a standalone function with unit tests.tests/unit/maxtext_utils_nnx_test.pyand extendedtests/unit/maxtext_utils_test.pyto cover the new mesh and sharding utilities.Note on Flax deprecation warnings:
Flax v0.12 emits
DeprecationWarningfor.valueaccess andVariableState. These are intentionally left unaddressed because post-training currently requires Flax v0.11 compatibility.Tests
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.