Support to_huggingface checkpoint conversion for Gemma4#3813
Merged
copybara-service[bot] merged 1 commit intomainfrom May 6, 2026
Merged
Support to_huggingface checkpoint conversion for Gemma4#3813copybara-service[bot] merged 1 commit intomainfrom
copybara-service[bot] merged 1 commit intomainfrom
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
868e414 to
7376725
Compare
7376725 to
c7838c0
Compare
c7838c0 to
3fc8ce3
Compare
hengtaoguo
approved these changes
May 6, 2026
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
hf to_maxtext checkpoint conversion is already supported. Adding support for the other direction. The following changes are included to reduce frictions during the conversion:
use_multimodal=False, this cause error if the provided maxtext ckpt contains multimodal keys, while the user only want to convert the text-related weights to hf ckpt. I improved this logic to have param_mapping always load the full dict, but keep or skip multimodal keys later depends onuse_multimodalflagb/508269624
Tests
For gemma4-26b-a4b-it model:
26b/test_gemma4_to_hf.sh: the script runsto_huggingface.pyfor maxtext -> hf ckpt conversion, then validate the conversion byforward_pass_logit_checker.py. text-only resultsconvert_gemma4.sh, which runsto_maxtext.pyfor hf -> maxtext ckpt conversion, then validate byforward_pass_logit_checker.pytext-only resultsFor gemma4-31b:
31b/test_gemma_to_hf.sh: with image resultsChecklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.