Fix: Refactor LoRA checkpoint restoration and simplify NNX weight extraction #4050
Open
RexBearIU wants to merge 1 commit into
Open
Fix: Refactor LoRA checkpoint restoration and simplify NNX weight extraction #4050RexBearIU wants to merge 1 commit into
RexBearIU wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
f4f21e3 to
ad7fe65
Compare
… updating base and LoRA checkpoints
ad7fe65 to
7c0b0f6
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.
… updating base and LoRA checkpoints
Description
This PR introduces robust post-training LoRA checkpoint conversion and restoration, specifically optimized for scanned layer designs (like Gemma 3).
• main only supported 2D/3D unscanned matrices.
• This branch adds a generalized contraction helper ( _get_lora_delta ) in to_huggingface.py to handle 3D/4D scanned layer weight matrices
(handling layer dimensions at axis 0/1) for seamless HuggingFace adapter exports.
• main only loaded a single checkpoint directory.
• This branch updates load_orbax_checkpoint to dynamically load and recursively merge a base model checkpoint and a separate LoRA-only adapter
checkpoint without overwriting keys.
• Replaced slow whole-tree to_pure_dict calls in lora_utils.py with detect_and_extract_checkpoint for fast, flat parameter lookups.
• Removed list-traversal path normalization in utils.py to rely on standard JAX flat-attribute naming.
Tests
The changes have been thoroughly verified with the unit test suite:
```bash
JAX_PLATFORMS=cpu PYTHONPATH=src python -m pytest tests/unit/hf_checkpoint_conversion_test.py tests/post_training/unit/lora_utils_test.py
tests/unit/lora_utils_nnx_test.py
All 29 tests passed successfully.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.