fix: preserve rotary_pct across save/load cycle in GPTNeoX configs#44985
Merged
zucchini-nlp merged 2 commits intohuggingface:mainfrom Mar 27, 2026
Merged
Conversation
Use setdefault instead of unconditional assignment for partial_rotary_factor in GPTNeoXConfig and GPTNeoXJapaneseConfig, so the value saved in rope_parameters is not overwritten with the default on reload.
Member
|
LGTM! cc @zucchini-nlp to confirm |
| # Standardize and validate the correctness of rotary position embeddings parameters | ||
| # Model uses non-standard naming for rope params, overwrite! | ||
| self.rope_parameters.setdefault("rope_theta", kwargs.pop("rotary_emb_base", self.default_theta)) | ||
| self.rope_parameters["partial_rotary_factor"] = kwargs.pop("rotary_pct", 0.25) |
Member
There was a problem hiding this comment.
nit: self.rope_parameters.setdefault("partial_rotary_factor", kwargs.pop("rotary_pct", 0.25)) does the same no?
Replace the 4-line if/else block with a single setdefault call, matching the pattern already used for rope_theta on the line above. As suggested by @zucchini-nlp in PR review.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: gpt_neox, gpt_neox_japanese |
|
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. |
zucchini-nlp
pushed a commit
to zucchini-nlp/transformers
that referenced
this pull request
Mar 27, 2026
…uggingface#44985) * fix: preserve rotary_pct across save/load cycle in GPTNeoX configs Use setdefault instead of unconditional assignment for partial_rotary_factor in GPTNeoXConfig and GPTNeoXJapaneseConfig, so the value saved in rope_parameters is not overwritten with the default on reload. * refactor: simplify partial_rotary_factor to use setdefault per review Replace the 4-line if/else block with a single setdefault call, matching the pattern already used for rope_theta on the line above. As suggested by @zucchini-nlp in PR review.
NielsRogge
pushed a commit
to NielsRogge/transformers
that referenced
this pull request
Mar 30, 2026
…uggingface#44985) * fix: preserve rotary_pct across save/load cycle in GPTNeoX configs Use setdefault instead of unconditional assignment for partial_rotary_factor in GPTNeoXConfig and GPTNeoXJapaneseConfig, so the value saved in rope_parameters is not overwritten with the default on reload. * refactor: simplify partial_rotary_factor to use setdefault per review Replace the 4-line if/else block with a single setdefault call, matching the pattern already used for rope_theta on the line above. As suggested by @zucchini-nlp in PR review.
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.
Summary
Fixes #44913
When creating a
GPTNeoXConfig(orGPTNeoXJapaneseConfig) with a non-defaultrotary_pct, the value is lost after asave_pretrained/from_pretrainedround-trip. This happens becauseconvert_rope_params_to_dictunconditionally overwritespartial_rotary_factorwithkwargs.pop("rotary_pct", <default>). On reload,rotary_pctis absent from kwargs (it was saved insiderope_parameters), so the default silently replaces the correct value.The fix uses the same
setdefaultpattern recommended by @zucchini-nlp frommodeling_rope_utils.pyL646-648: only setpartial_rotary_factorifrotary_pctis explicitly passed; otherwise, usesetdefaultto preserve any value already present inrope_parameters.Both
GPTNeoXConfigandGPTNeoXJapaneseConfighad the same bug and are fixed together.Changes
src/transformers/models/gpt_neox/configuration_gpt_neox.py: usesetdefaultforpartial_rotary_factorinstead of unconditional assignmentsrc/transformers/models/gpt_neox_japanese/configuration_gpt_neox_japanese.py: same fix (default 1.0 instead of 0.25)Test plan
rotary_pct=0.5survives save/load round-trip for bothGPTNeoXConfigandGPTNeoXJapaneseConfigrotary_pct(0.25 for GPTNeoX, 1.0 for Japanese) survives save/load round-trippytest tests/models/gpt_neox/test_modeling_gpt_neox.py -k config-- all passedpytest tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py -k config-- all passedruff checkandruff format --checkpass on both filesAI assistance was used in drafting; all changes and tests were reviewed and validated by the submitter.