[Bugfix] Fix GLM5 config (#48711)
Signed-off-by: Jee Jee Li <jeejeelee@inferact.ai>
This commit is contained in:
@@ -133,6 +133,14 @@ _SPECULATIVE_DECODING_CONFIGS: set[str] = {"eagle", "speculators", "medusa"}
|
|||||||
|
|
||||||
_PATCH_HF_VALIDATE_ROPE: set[str] = {"sarvam_mla"}
|
_PATCH_HF_VALIDATE_ROPE: set[str] = {"sarvam_mla"}
|
||||||
|
|
||||||
|
# Model types whose checkpoints declare `layer_types` entries that upstream
|
||||||
|
# transformers has not added to `ALLOWED_LAYER_TYPES` yet, so its strict config
|
||||||
|
# validation rejects them (e.g. GLM-5.2 `glm_moe_dsa` use
|
||||||
|
# `deepseek_sparse_attention`). Extend the allowed set for these model types.
|
||||||
|
_PATCH_HF_ALLOWED_LAYER_TYPES: dict[str, tuple[str, ...]] = {
|
||||||
|
"glm_moe_dsa": ("deepseek_sparse_attention",),
|
||||||
|
}
|
||||||
|
|
||||||
_CONFIG_ATTRS_MAPPING: dict[str, str] = {
|
_CONFIG_ATTRS_MAPPING: dict[str, str] = {
|
||||||
"llm_config": "text_config",
|
"llm_config": "text_config",
|
||||||
}
|
}
|
||||||
@@ -206,6 +214,24 @@ def _patch_hf_transformers_validate_rope():
|
|||||||
PretrainedConfig.validate_rope = patched_validate_rope
|
PretrainedConfig.validate_rope = patched_validate_rope
|
||||||
|
|
||||||
|
|
||||||
|
def _patch_hf_transformers_allowed_layer_types(
|
||||||
|
extra_layer_types: tuple[str, ...],
|
||||||
|
) -> None:
|
||||||
|
"""Extend transformers' ``ALLOWED_LAYER_TYPES`` so its strict config
|
||||||
|
validation accepts layer types (e.g. ``deepseek_sparse_attention``) that a
|
||||||
|
checkpoint declares but upstream transformers has not registered yet.
|
||||||
|
"""
|
||||||
|
import transformers.configuration_utils as hf_configuration_utils
|
||||||
|
|
||||||
|
missing = tuple(
|
||||||
|
layer_type
|
||||||
|
for layer_type in extra_layer_types
|
||||||
|
if layer_type not in hf_configuration_utils.ALLOWED_LAYER_TYPES
|
||||||
|
)
|
||||||
|
if missing:
|
||||||
|
hf_configuration_utils.ALLOWED_LAYER_TYPES += missing
|
||||||
|
|
||||||
|
|
||||||
class HFConfigParser(ConfigParserBase):
|
class HFConfigParser(ConfigParserBase):
|
||||||
def parse(
|
def parse(
|
||||||
self,
|
self,
|
||||||
@@ -248,6 +274,9 @@ class HFConfigParser(ConfigParserBase):
|
|||||||
if model_type in _PATCH_HF_VALIDATE_ROPE:
|
if model_type in _PATCH_HF_VALIDATE_ROPE:
|
||||||
_patch_hf_transformers_validate_rope()
|
_patch_hf_transformers_validate_rope()
|
||||||
|
|
||||||
|
if extra_layer_types := _PATCH_HF_ALLOWED_LAYER_TYPES.get(model_type):
|
||||||
|
_patch_hf_transformers_allowed_layer_types(extra_layer_types)
|
||||||
|
|
||||||
if model_type in _SPECULATIVE_DECODING_CONFIGS:
|
if model_type in _SPECULATIVE_DECODING_CONFIGS:
|
||||||
config_class = _CONFIG_REGISTRY[model_type]
|
config_class = _CONFIG_REGISTRY[model_type]
|
||||||
config = config_class.from_pretrained(
|
config = config_class.from_pretrained(
|
||||||
|
|||||||
Reference in New Issue
Block a user