Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions vllm/transformers_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ def __getitem__(self, key):

_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",
}
Expand Down Expand Up @@ -206,6 +214,24 @@ def patched_validate_rope(self, *args, **kwargs):
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,
Expand Down Expand Up @@ -248,6 +274,9 @@ def parse(
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(
Expand Down
Loading