Fix Gemma 3 safetensor loading#987
Merged
copybara-service[bot] merged 1 commit intomainfrom Jan 20, 2026
Merged
Conversation
f58f130 to
b3e4e6e
Compare
b3e4e6e to
d615f1a
Compare
d615f1a to
80afe40
Compare
80afe40 to
8d7a270
Compare
8d7a270 to
3fa0891
Compare
3fa0891 to
b3abc90
Compare
b3abc90 to
6c8e4d3
Compare
6c8e4d3 to
6855312
Compare
6855312 to
3ade117
Compare
Loading Gemma 3 from safetensor weights fails due to two reasons: - Safetensor weights follow the pattern "language_model*". "language_model" was missing. - When we load weights, weights from the vision part of the model are automatically checked. Since they are absent from the key dict, an error is thrown. Colab: https://colab.research.google.com/gist/abheesht17/9e85a2f7d08b60712f42bd1b44481ee6/bug-fix-gemma-3-loading-tunix.ipynb Code snippet: ``` from tunix.models.gemma3 import params_safetensors as params_safetensors_lib from tunix.models.gemma3 import model as gemma_lib from flax import nnx model_config = gemma_lib.ModelConfig.gemma3_4b_it() MODEL_CP_PATH = local_model_path gemma3 = params_safetensors_lib.create_model_from_safe_tensors( MODEL_CP_PATH, (model_config), ) ``` Error: ``` ValueError: Only one key should be found: [] for language_model.model.embed_tokens.weight ``` PiperOrigin-RevId: 858377286
3ade117 to
059cfb0
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.
Fix Gemma 3 safetensor loading
Loading Gemma 3 from safetensor weights fails due to two reasons:
Since they are absent from the key dict, an error is thrown.
Colab: https://colab.research.google.com/gist/abheesht17/9e85a2f7d08b60712f42bd1b44481ee6/bug-fix-gemma-3-loading-tunix.ipynb
Code snippet:
Error: