From 313fae3e89daeb7f5183064912933c328bbb6e48 Mon Sep 17 00:00:00 2001 From: Jee Jee Li Date: Wed, 15 Jul 2026 17:55:39 +0800 Subject: [PATCH] [Bugfix] Fix GLM5 config (#48711) Signed-off-by: Jee Jee Li --- vllm/transformers_utils/config.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vllm/transformers_utils/config.py b/vllm/transformers_utils/config.py index c0f3396b0b..bb72087a95 100644 --- a/vllm/transformers_utils/config.py +++ b/vllm/transformers_utils/config.py @@ -133,6 +133,14 @@ _SPECULATIVE_DECODING_CONFIGS: set[str] = {"eagle", "speculators", "medusa"} _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] = { "llm_config": "text_config", } @@ -206,6 +214,24 @@ def _patch_hf_transformers_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): def parse( self, @@ -248,6 +274,9 @@ class HFConfigParser(ConfigParserBase): if model_type in _PATCH_HF_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: config_class = _CONFIG_REGISTRY[model_type] config = config_class.from_pretrained(