Fix per-layer rope_parameters misparsing when layer_types omits keys - #48411
Closed
Noxtimo wants to merge 1 commit into
Closed
Fix per-layer rope_parameters misparsing when layer_types omits keys#48411Noxtimo wants to merge 1 commit into
Noxtimo wants to merge 1 commit into
Conversation
Contributor
CI recapDashboard: View test results in Grafana |
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.
What does this PR do?
Fixes #48392.
Problem
Models that use heterogeneous attention layers (e.g.
Gemma3,Olmo3mixing sliding and full attention) populaterope_parameterswith entries for every possible layer type (sliding_attentionandfull_attention). However, when a model configuration is instantiated with fewer layers than the sliding window period (such asGemma3TextConfig(num_hidden_layers=2)orOlmo3Config(num_hidden_layers=2)),config.layer_typescontains only["sliding_attention", "sliding_attention"].Previously,
standardize_rope_paramsandvalidate_ropecheckedset(rope_parameters.keys()).issubset(layer_types). When not all layer types were instantiated, this check returnedFalse, causing the nested dictionary to be misclassified as a single flat config dict:Unrecognized keys in rope_parameters for 'rope_type'='default': {'full_attention', 'sliding_attention'}.config.rope_parameterswith top-level"rope_type": "default"and"rope_theta": Nonewhich was then persisted to disk onsave_pretrained.yarn,linear) for non-instantiated layer types.Solution
src/transformers/modeling_rope_utils.py, validate thatrope_parameterskeys are a subset ofallowed_layer_types(checking_rope_type_labelsif present, orALLOWED_LAYER_TYPESfromconfiguration_utils.py) rather than only currently instantiatedself.layer_types.standardize_rope_params, iterate overset(rope_parameters.keys())so all configured layer types are standardized.tests/utils/test_modeling_rope_utils.pyverifying clean standardization, warning suppression, validation, andsave_pretrained/from_pretrainedround-tripping for partial layer configurations.Before submitting checklist
Pull Request section?
to it if that's the case: Fixes Nested per-layer
rope_parametersis misparsed whenlayer_typesomits one of its keys聽#48392documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@zucchini-nlp @ArthurZucker @Cyrilvallez