fix: remove manual rope parameters injection in PretrainedConfig (#23910)
This commit is contained in:
@@ -136,41 +136,18 @@ def _ensure_gguf_version():
|
||||
|
||||
|
||||
def _patch_rope_parameters_validation():
|
||||
"""Fix rope_parameters validation for unregistered model types.
|
||||
"""Guard ``standardize_rope_params()`` against missing
|
||||
``max_position_embeddings``.
|
||||
|
||||
For unregistered model types (e.g. ``deepseek_v32``), the generic
|
||||
``PretrainedConfig`` lacks a ``rope_parameters`` field so the conversion
|
||||
that injects ``rope_theta`` from the top-level config is skipped.
|
||||
Additionally, ``standardize_rope_params()`` accesses
|
||||
For ``PretrainedConfig``, ``standardize_rope_params()`` accesses
|
||||
``self.max_position_embeddings`` during ``__post_init__`` before extra
|
||||
kwargs are set as attributes, causing ``AttributeError``.
|
||||
|
||||
Fix: (1) patch ``from_dict`` to inject ``rope_theta`` into
|
||||
``rope_scaling``, (2) guard ``standardize_rope_params`` against missing
|
||||
Fix: guard ``standardize_rope_params`` against missing
|
||||
``max_position_embeddings``.
|
||||
|
||||
TODO(upstream): remove once unregistered model types handle rope
|
||||
standardization correctly in transformers.
|
||||
"""
|
||||
from transformers import PretrainedConfig
|
||||
|
||||
original = PretrainedConfig.from_dict.__func__
|
||||
|
||||
@classmethod # type: ignore[misc]
|
||||
def patched(cls, config_dict, **kwargs):
|
||||
rope_scaling = config_dict.get("rope_scaling")
|
||||
rope_theta = config_dict.get("rope_theta")
|
||||
if (
|
||||
isinstance(rope_scaling, dict)
|
||||
and rope_theta is not None
|
||||
and "rope_theta" not in rope_scaling
|
||||
):
|
||||
config_dict = config_dict.copy()
|
||||
config_dict["rope_scaling"] = {**rope_scaling, "rope_theta": rope_theta}
|
||||
return original(cls, config_dict, **kwargs)
|
||||
|
||||
PretrainedConfig.from_dict = patched
|
||||
|
||||
# standardize_rope_params accesses self.max_position_embeddings before
|
||||
# __post_init__ sets extra kwargs — skip when the attribute is absent.
|
||||
if hasattr(PretrainedConfig, "standardize_rope_params"):
|
||||
|
||||
Reference in New Issue
Block a user