Repository navigation
Use new per_layer_config for Gemma 4 so that heterogeneous attention config is explicit - #47384
Conversation
… config is explicit Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
ArthurZucker
left a comment
There was a problem hiding this comment.
nice, can we remove 1 if else?
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
vasqu
left a comment
There was a problem hiding this comment.
Ok I see the issue now that you guys meant. Left my 2 cents
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
Signed-off-by: Harry Mellor <[email protected]>
|
run-slow: diffusion_gemma, gemma4, gemma4_unified, llama |
|
This comment contains models: ["models/diffusion_gemma", "models/gemma4", "models/gemma4_unified", "models/llama"] |
CI ResultsCommit Info
The test failure analysis could not be completed. Please check the workflow run for details. |
2 similar comments
CI ResultsCommit Info
The test failure analysis could not be completed. Please check the workflow run for details. |
CI ResultsCommit Info
The test failure analysis could not be completed. Please check the workflow run for details. |
|
Seems like it introduced new failures on gemma4 unified, not sure if this is a diff between nightly and slow ci 👀 |
Signed-off-by: Harry Mellor <[email protected]>
|
[For maintainers] Suggested jobs to run (before merge) run-slow: diffusion_gemma, gemma4, gemma4_unified |
54a303e to
bdfc956
Compare
CI recapDashboard: View test results in Grafana |
|
run-slow: diffusion_gemma, gemma4, gemma4_unified |
|
This comment contains models: ["models/diffusion_gemma", "models/gemma4", "models/gemma4_unified"] |
… impls Gemma 4 does not load through its native implementations against Transformers main. Two separate causes: `_get_transformers_backend_cls` compares the root and text configs with `!=`, which walks every field and raises on a heterogeneous config. Compare identity instead, here and in the Transformers backend's `is_multimodal`: `get_hf_text_config` already treats identity as the nesting test, and a deep comparison of two configs is expensive and undefined for per-layer attributes. The native impls then read the `global_head_dim` and `num_global_key_value_heads` keys that huggingface/transformers#47384 deleted. gemma4.py, gemma4_mtp.py and gemma4_dspark.py now resolve per-layer geometry through one shared helper covering both config layouts. Also fixes two problems in the existing layout handling: - Detect the layout by whether `global_head_dim` is present, not by whether the heterogeneity mixin is. The mixin is on every config from Transformers 5.15.0 on, so keying off it sends old-layout configs -- which is what every published Gemma 4 checkpoint still uses -- down the per-layer path, where `per_layer_config` carries no overrides and silently returns the sliding attention head_dim (256) for full attention layers that need 512. - Iterate `per_layer_config` by index rather than by layer type. Indexing by type copies and compares every layer config of that type, and `layer_types` has one entry per layer rather than one per type, so `get_head_size()` took 47ms; per-layer resolution in `create_attention_instances` added 8.3s to startup for the 48-layer 12B. Now 0.3ms and 350ms. Verified on google/gemma-4-12B-it-qat-w4a16-ct against Transformers main: generation is correct both with and without the Transformers modelling backend. Co-authored-by: Claude <[email protected]> Signed-off-by: martin el cheikh <[email protected]>
…n config is explicit (huggingface#47384) * Use new `per_layer_config` for Gemma4 so that heterogeneous attention config is explicit Signed-off-by: Harry Mellor <[email protected]> * Remove the now legacy fields Signed-off-by: Harry Mellor <[email protected]> * Fix docstrings Signed-off-by: Harry Mellor <[email protected]> * Fix test harness Signed-off-by: Harry Mellor <[email protected]> * Magic default Signed-off-by: Harry Mellor <[email protected]> * Reinstate unused rope kwarg Signed-off-by: Harry Mellor <[email protected]> * Make `per_layer_config` more flexible/useful Signed-off-by: Harry Mellor <[email protected]> * Propagate with modular Signed-off-by: Harry Mellor <[email protected]> * Less ugly solution to heterogeneous values in `validate_architecture` Signed-off-by: Harry Mellor <[email protected]> * ruff Signed-off-by: Harry Mellor <[email protected]> * update test Signed-off-by: Harry Mellor <[email protected]> * Update test again Signed-off-by: Harry Mellor <[email protected]> * Fix tests Signed-off-by: Harry Mellor <[email protected]> * make fix-repo Signed-off-by: Harry Mellor <[email protected]> * update other tests Signed-off-by: Harry Mellor <[email protected]> --------- Signed-off-by: Harry Mellor <[email protected]>
…n config is explicit (huggingface#47384) * Use new `per_layer_config` for Gemma4 so that heterogeneous attention config is explicit Signed-off-by: Harry Mellor <[email protected]> * Remove the now legacy fields Signed-off-by: Harry Mellor <[email protected]> * Fix docstrings Signed-off-by: Harry Mellor <[email protected]> * Fix test harness Signed-off-by: Harry Mellor <[email protected]> * Magic default Signed-off-by: Harry Mellor <[email protected]> * Reinstate unused rope kwarg Signed-off-by: Harry Mellor <[email protected]> * Make `per_layer_config` more flexible/useful Signed-off-by: Harry Mellor <[email protected]> * Propagate with modular Signed-off-by: Harry Mellor <[email protected]> * Less ugly solution to heterogeneous values in `validate_architecture` Signed-off-by: Harry Mellor <[email protected]> * ruff Signed-off-by: Harry Mellor <[email protected]> * update test Signed-off-by: Harry Mellor <[email protected]> * Update test again Signed-off-by: Harry Mellor <[email protected]> * Fix tests Signed-off-by: Harry Mellor <[email protected]> * make fix-repo Signed-off-by: Harry Mellor <[email protected]> * update other tests Signed-off-by: Harry Mellor <[email protected]> --------- Signed-off-by: Harry Mellor <[email protected]>
transformers 5.15 (huggingface/transformers#47384) moves global_head_dim and num_global_key_value_heads into per_layer_config, and reading head_dim or num_key_value_heads on the global Gemma 4 text config raises AmbiguousGlobalPerLayerAttributeError. Read them per layer type instead, skip per-layer attributes in the generic config mapping, and pick the right head_dim_key for the full-attention proportional RoPE.
Gemma 4 contains a different
head_dimandnum_key_value_headsfor the full attention and sliding attention layers. Currently, which layers use which is implicit during model construction.This PR:
*global*keys and propagates the change to everywhere that used themThis will enable downstream libraries like vLLM to load Gemma 4 using the Transformers modelling backend more easily as this heterogeneity can be discovered via the config.