Repository navigation
convert : handle per_layer_config in Gemma4 (transformers 5.15) - #26882
Conversation
Gemma-4 E4B models have global_head_dim inside text_config rather than at the top level. Add fallback to support both layouts.
|
Your problem must be something else, Lines 1113 to 1115 in d0c407e |
Ah yes, huggingface/transformers#47384 changed the behavior of this entry, it now lives in Please update fallback accordingly. |
Now it tries text_config.global_head_dim -> per_layer_config[*].head_dim -> head_dim default. It works well on my laptop, logs at https://invent.kde.org/-/snippets/3862 Please take a look. |
That's still not quite right, as mentioned you should not read |
|
Additionally, the same PR also moved |
|
I understand that Lines 2313 to 2322 in d0c407e Lines 304 to 315 in d0c407e Lines 353 to 357 in d0c407e The same applies to the other one. |
…g and num_global_key_value_heads compatibility
|
Updated to only read head_dim from full_attention layers in per_layer_config, and added fallback for num_global_key_value_heads as well. |
These are parameters for the |
You forgot to push that I think. |
Oh thanks for the reminder! I forgot to save the file before pushing😅. Just pushed the update with fallback for num_global_key_value_heads. |
You're right, but I'm converting the main model (Gemma4Model), and in that case, it occur the error that says text_config does not get merged into root hparams. I think when extracting only the vision/audio encoder, only Gemma4VisionAudioModel is used, where the merge does not happen, occuring the weird keyerror. I think the current version is robust to run. |
No, that's not the reason, |
Thanks for the clarification, but I'm afraid I may not install other versions of python-transformers package on my computer to verify your clarification. Now that fallback solutions have been added for head_dim_full and num_key_value_heads_full, is there anything that needs to be done before merging? |
I can verify that for you.
Yes, |
Done. Updated to read them directly from root hparams. Really appreciate your detailed review and explanations! :) |
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * origin/master: (383 commits) cmake : introduce semantic versioning (ggml-org#26839) gguf : harden loader against malformed tensor dims and metadata types (ggml-org#25596) kleidiai: Add runtime feature detection mechanism for aarch64/kleidiai (ggml-org#26076) model : disallow integer dflash sliding_window_pattern (ggml-org#26900) sync : ggml cmake : add config version support (ggml/1582) server : support slot save/restore with media inputs (ggml-org#26640) ui: add read_media tool (ggml-org#25877) opencl: default FA c8 cluster width to 16 on X1E (ggml-org#26433) tests : update speculative params (ggml-org#26925) vulkan: add TQ2_0 (ternary) support (ggml-org#25850) wavtokenizer-dec : bound posnet/convnext block_count against n_layer_all (ggml-org#26892) convert : handle per_layer_config in Gemma4 (transformers 5.15) (ggml-org#26882) opencl: use flat mv q5_k when weight exceeds image1d_buffer_t limit (ggml-org#26880) chat : fix muse-glimmer detection of tool calls after EOM (ggml-org#26879) ci : add missing release check (ggml-org#26923) CUDA: only disable CUDA graphs when mul_mat_id actually needs a stream sync (ggml-org#26802) cuda : add warp-per-row wkv7 kernel for single-token decode (ggml-org#26111) spec : update speculative-simple (ggml-org#26904) chat : tighten bare function parsing for Qwen models (ggml-org#26793) ...
…-org#26882) * fix: handle nested global_head_dim in Gemma4 config Gemma-4 E4B models have global_head_dim inside text_config rather than at the top level. Add fallback to support both layouts. * fix: add fallback for global_head_dim to support per_layer_config format * fix: read head_dim only from full_attention layers in per_layer_config and num_global_key_value_heads compatibility * fix: added fallback for num_global_key_value_heads * fix: read per_layer_config from root hparams * fix: delete unused text_config * cleanup and fixes --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
…-org#26882) * fix: handle nested global_head_dim in Gemma4 config Gemma-4 E4B models have global_head_dim inside text_config rather than at the top level. Add fallback to support both layouts. * fix: add fallback for global_head_dim to support per_layer_config format * fix: read head_dim only from full_attention layers in per_layer_config and num_global_key_value_heads compatibility * fix: added fallback for num_global_key_value_heads * fix: read per_layer_config from root hparams * fix: delete unused text_config * cleanup and fixes --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
…-org#26882) * fix: handle nested global_head_dim in Gemma4 config Gemma-4 E4B models have global_head_dim inside text_config rather than at the top level. Add fallback to support both layouts. * fix: add fallback for global_head_dim to support per_layer_config format * fix: read head_dim only from full_attention layers in per_layer_config and num_global_key_value_heads compatibility * fix: added fallback for num_global_key_value_heads * fix: read per_layer_config from root hparams * fix: delete unused text_config * cleanup and fixes --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
…-org#26882) * fix: handle nested global_head_dim in Gemma4 config Gemma-4 E4B models have global_head_dim inside text_config rather than at the top level. Add fallback to support both layouts. * fix: add fallback for global_head_dim to support per_layer_config format * fix: read head_dim only from full_attention layers in per_layer_config and num_global_key_value_heads compatibility * fix: added fallback for num_global_key_value_heads * fix: read per_layer_config from root hparams * fix: delete unused text_config * cleanup and fixes --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
Gemma-4 E4B models have global_head_dim inside text_config rather than at the top level. Add fallback to support both layouts.
Overview
This PR adds fallback logic for the
global_head_dimfield when converting the Gemma-4 E4B model. In the Google Gemma-4 E4Bconfig.json, this parameter is stored insidetext_configrather than at the top level ofconfig.json. The current script raises aKeyErrorwhen the field is not found inhparams.This fix first checks
text_config, then falls back tohparams, and sets a reasonable default value of 256. This ensures compatibility with both the official Google model and its derivatives.Additional information
Link affected: https://huggingface.co/google/gemma-4-E4B-it/resolve/main/config.json
Requirements