PR #4640: fix: refine scanned layers unroll logic for Gemma 3 - #4693
Open
copybara-service[bot] wants to merge 1 commit into
Open
PR #4640: fix: refine scanned layers unroll logic for Gemma 3#4693copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
khatwanimohit,
parambole,
richjames0,
shralex,
shuningjin,
vipannalla and
xibinliu
as code owners
July 31, 2026 16:43
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Imported from GitHub PR #4640 # Description The `unroll_gemma_scanned_weights` workaround—specifically designed to unstack Gemma 3 scanned blocks due to Tunix's limitations—was previously formatting the unrolled keys incorrectly (using raw integers for the layer index). This PR fixes : 1. the key generation logic to correctly format the unrolled layers as strings (e.g., changing the tuple injection from `(0,)` to `("layers_0",)`), which aligns with the expected dictionary structure for downstream weight mapping. 2. it refines the `scan_length` detection to safely check for the `mlp.wi_0` architectural pattern. # Tests We run `train_rl.py` for both scanned and unscanned layers. Both should return normal sentences ## Scanned layers Config: `scan_layers=true` and `use_standalone_converter=True` - [internal link] - [internal link] ## Unscanned layers Config : `scan_layers=false` - [internal link] - [internal link] # Checklist Before submitting this PR, please make sure (put X in square brackets): - [x] I have performed a self-review of my code. For an optional AI review, add the `gemini-review` label. - [x] I have necessary comments in my code, particularly in hard-to-understand areas. - [x] I have run end-to-end tests tests and provided workload links above if applicable. - [x] I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in [our documentation](https://maxtext.readthedocs.io/en/latest/development.html#adding-new-documentation-files). Copybara import of the project: -- 8e1b8f3 by mesakhcienet <mesakh.christian@cienet.com>: Merging this change closes #4640 FUTURE_COPYBARA_INTEGRATE_REVIEW=#4640 from AI-Hypercomputer:fix/train-rl-layers 8e1b8f3 PiperOrigin-RevId: 955361604
copybara-service
Bot
force-pushed
the
test_955361604
branch
from
July 31, 2026 17:20
8e1e94b to
8b312f3
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.
PR #4640: fix: refine scanned layers unroll logic for Gemma 3
Imported from GitHub PR #4640
Description
The
unroll_gemma_scanned_weightsworkaround—specifically designed to unstack Gemma 3 scanned blocks due to Tunix's limitations—was previously formatting the unrolled keys incorrectly (using raw integers for the layer index). This PR fixes :(0,)to("layers_0",)), which aligns with the expected dictionary structure for downstream weight mapping.scan_lengthdetection to safely check for themlp.wi_0architectural pattern.Tests
We run
train_rl.pyfor both scanned and unscanned layers. Both should return normal sentencesScanned layers
Config:
scan_layers=trueanduse_standalone_converter=TrueUnscanned layers
Config :
scan_layers=falseChecklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.Copybara import of the project:
--
8e1b8f3 by mesakhcienet mesakh.christian@cienet.com:
Merging this change closes #4640
FUTURE_COPYBARA_INTEGRATE_REVIEW=#4640 from AI-Hypercomputer:fix/train-rl-layers 8e1b8f3