2025-10-21 00:30:10 -07:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2026-02-13 05:59:00 -08:00
|
|
|
from vllm.config.model import ModelConfig
|
2025-10-21 00:30:10 -07:00
|
|
|
from vllm.config.multimodal import MultiModalConfig
|
2026-01-09 16:10:24 -05:00
|
|
|
from vllm.v1.attention.backends.registry import AttentionBackendEnum
|
2025-10-21 00:30:10 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_mm_encoder_attn_backend_str_conversion():
|
|
|
|
|
config = MultiModalConfig(mm_encoder_attn_backend="FLASH_ATTN")
|
2025-11-11 06:40:44 -06:00
|
|
|
assert config.mm_encoder_attn_backend == AttentionBackendEnum.FLASH_ATTN
|
2025-10-21 00:30:10 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_mm_encoder_attn_backend_invalid():
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
|
MultiModalConfig(mm_encoder_attn_backend="not_a_backend")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_mm_encoder_attn_backend_hash_updates():
|
|
|
|
|
base_hash = MultiModalConfig().compute_hash()
|
|
|
|
|
overridden_hash = MultiModalConfig(
|
2025-11-11 06:40:44 -06:00
|
|
|
mm_encoder_attn_backend=AttentionBackendEnum.FLASH_ATTN
|
2025-10-21 00:30:10 -07:00
|
|
|
).compute_hash()
|
|
|
|
|
assert base_hash != overridden_hash
|
2026-02-13 05:59:00 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_language_model_only_does_not_affect_mm_hash():
|
|
|
|
|
"""language_model_only does not affect the ViT computation graph,
|
|
|
|
|
so it should not change the multimodal config hash."""
|
|
|
|
|
base_hash = MultiModalConfig().compute_hash()
|
|
|
|
|
lm_only_hash = MultiModalConfig(language_model_only=True).compute_hash()
|
|
|
|
|
assert base_hash == lm_only_hash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_language_model_only_affects_model_hash():
|
|
|
|
|
"""language_model_only affects the LM computation graph,
|
|
|
|
|
so it should change the model config hash."""
|
|
|
|
|
model = "llava-hf/llava-1.5-7b-hf"
|
|
|
|
|
base_hash = ModelConfig(model).compute_hash()
|
|
|
|
|
lm_only_hash = ModelConfig(model, language_model_only=True).compute_hash()
|
|
|
|
|
assert base_hash != lm_only_hash
|