Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions tests/config/test_model_arch_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

import pytest
from transformers import PretrainedConfig

from vllm.config import ModelConfig, ParallelConfig, SpeculativeConfig
from vllm.transformers_utils.model_arch_config_convertor import (
Expand Down Expand Up @@ -114,6 +115,22 @@ def _assert_model_config_methods(
assert model_config.get_head_size() == expected["head_size"]


def test_head_size_falls_back_when_head_dim_is_zero():
"""Regression test for configs that materialize missing head_dim as 0."""
hf_config = PretrainedConfig(
model_type="deepseek_vl_v2",
hidden_size=1280,
num_attention_heads=10,
num_key_value_heads=10,
head_dim=0,
kv_lora_rank=None,
)

convertor = ModelArchConfigConvertorBase(hf_config, hf_config)

assert convertor.get_head_size() == 128


@pytest.mark.parametrize("model", BASE_MODELS_TO_TEST)
def test_base_model_arch_config(model: str):
"""Test model architecture config for base models."""
Expand Down
9 changes: 6 additions & 3 deletions vllm/transformers_utils/model_arch_config_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ def get_head_size(self) -> int:
if qk_rope_head_dim and qk_nope_head_dim:
return qk_rope_head_dim + qk_nope_head_dim

# NOTE: Some configs may set head_dim=None in the config
if getattr(self.hf_text_config, "head_dim", None) is not None:
return self.hf_text_config.head_dim
# NOTE: Some config classes may set head_dim=None or materialize a missing
# head_dim as 0 (for example, DeepseekVLV2TextConfig).
if (
head_dim := getattr(self.hf_text_config, "head_dim", None)
) is not None and head_dim > 0:
Comment thread
roberteg16 marked this conversation as resolved.
return head_dim

# NOTE: Some models (such as PLaMo2.1) use `hidden_size_per_head`
if getattr(self.hf_text_config, "hidden_size_per_head", None) is not None:
Expand Down
Loading