Skip to content

fix: refine scanned layers unroll logic for Gemma 3 - #4640

Open
mesakhcienet wants to merge 1 commit into
mainfrom
fix/train-rl-layers
Open

fix: refine scanned layers unroll logic for Gemma 3#4640
mesakhcienet wants to merge 1 commit into
mainfrom
fix/train-rl-layers

Conversation

@mesakhcienet

@mesakhcienet mesakhcienet commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

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

Unscanned layers

Config : scan_layers=false

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • 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.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@mesakhcienet
mesakhcienet force-pushed the fix/train-rl-layers branch from 06978d9 to 7095687 Compare July 28, 2026 10:35
@mesakhcienet
mesakhcienet force-pushed the fix/train-rl-layers branch from 7095687 to d751fe5 Compare July 29, 2026 00:40
@mesakhcienet mesakhcienet changed the title first change fix: gemma3 layers naming Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 7.69231% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...c/maxtext/integration/vllm/maxtext_vllm_rollout.py 7.69% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mesakhcienet mesakhcienet changed the title fix: gemma3 layers naming fix: update tunix scanned weights unroll on Gemma 3 Jul 29, 2026
@mesakhcienet mesakhcienet changed the title fix: update tunix scanned weights unroll on Gemma 3 fix: update scanned weights unroll on Gemma 3 Jul 29, 2026
@mesakhcienet
mesakhcienet marked this pull request as ready for review July 29, 2026 03:36
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@mesakhcienet mesakhcienet changed the title fix: update scanned weights unroll on Gemma 3 fix: refine scanned layers unroll logic for Gemma 3 Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant