[Bugfix] Fix GLM5 config (#48711)
Signed-off-by: Jee Jee Li <jeejeelee@inferact.ai>
Jee Jee Li committed
Jul 15, 2026 at 17:55 UTC
313fae3e89daeb7f5183064912933c328bbb6e48
1 file changed
+29
vllm/transformers_utils/config.py
+29
@@ -133,6 +133,14 @@ _SPECULATIVE_DECODING_CONFIGS: set[str] = {"eagle", "speculators", "medusa"}
133
134
_PATCH_HF_VALIDATE_ROPE: set[str] = {"sarvam_mla"}
135
136
+# Model types whose checkpoints declare `layer_types` entries that upstream
137
+# transformers has not added to `ALLOWED_LAYER_TYPES` yet, so its strict config
138
+# validation rejects them (e.g. GLM-5.2 `glm_moe_dsa` use
139
+# `deepseek_sparse_attention`). Extend the allowed set for these model types.
140
+_PATCH_HF_ALLOWED_LAYER_TYPES: dict[str, tuple[str, ...]] = {
141
+ "glm_moe_dsa": ("deepseek_sparse_attention",),
142
+}
143
+
144
_CONFIG_ATTRS_MAPPING: dict[str, str] = {
145
"llm_config": "text_config",
146
}
@@ -206,6 +214,24 @@ def _patch_hf_transformers_validate_rope():
214
PretrainedConfig.validate_rope = patched_validate_rope
215
216
217
+def _patch_hf_transformers_allowed_layer_types(
218
+ extra_layer_types: tuple[str, ...],
219
+) -> None:
220
+ """Extend transformers' ``ALLOWED_LAYER_TYPES`` so its strict config
221
+ validation accepts layer types (e.g. ``deepseek_sparse_attention``) that a
222
+ checkpoint declares but upstream transformers has not registered yet.
223
+ """
224
+ import transformers.configuration_utils as hf_configuration_utils
225
+
226
+ missing = tuple(
227
+ layer_type
228
+ for layer_type in extra_layer_types
229
+ if layer_type not in hf_configuration_utils.ALLOWED_LAYER_TYPES
230
+ )
231
+ if missing:
232
+ hf_configuration_utils.ALLOWED_LAYER_TYPES += missing
233
+
234
+
235
class HFConfigParser(ConfigParserBase):
236
def parse(
237
self,
@@ -248,6 +274,9 @@ class HFConfigParser(ConfigParserBase):
274
if model_type in _PATCH_HF_VALIDATE_ROPE:
275
_patch_hf_transformers_validate_rope()
276
277
+ if extra_layer_types := _PATCH_HF_ALLOWED_LAYER_TYPES.get(model_type):
278
+ _patch_hf_transformers_allowed_layer_types(extra_layer_types)
279
+
280
if model_type in _SPECULATIVE_DECODING_CONFIGS:
281
config_class = _CONFIG_REGISTRY[model_type]
282
config = config_class.from_pretrained(