mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-09 20:34:58 +08:00
- **Add SPDX license headers to python source files**
- **Check for SPDX headers using pre-commit**
commit 9d7ef44c3cfb72ca4c32e1c677d99259d10d4745
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:18:24 2025 -0500
Add SPDX license headers to python source files
This commit adds SPDX license headers to python source files as
recommended to
the project by the Linux Foundation. These headers provide a concise way
that is
both human and machine readable for communicating license information
for each
source file. It helps avoid any ambiguity about the license of the code
and can
also be easily used by tools to help manage license compliance.
The Linux Foundation runs license scans against the codebase to help
ensure
we are in compliance with the licenses of the code we use, including
dependencies. Having these headers in place helps that tool do its job.
More information can be found on the SPDX site:
- https://spdx.dev/learn/handling-license-info/
Signed-off-by: Russell Bryant <rbryant@redhat.com>
commit 5a1cf1cb3b80759131c73f6a9dddebccac039dea
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:36:32 2025 -0500
Check for SPDX headers using pre-commit
Signed-off-by: Russell Bryant <rbryant@redhat.com>
---------
Signed-off-by: Russell Bryant <rbryant@redhat.com>
100 lines
3.9 KiB
Python
100 lines
3.9 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import warnings
|
|
|
|
import pytest
|
|
import torch.cuda
|
|
|
|
from vllm.model_executor.models import (is_pooling_model,
|
|
is_text_generation_model,
|
|
supports_multimodal)
|
|
from vllm.model_executor.models.adapters import (as_classification_model,
|
|
as_embedding_model,
|
|
as_reward_model)
|
|
from vllm.model_executor.models.registry import (_MULTIMODAL_MODELS,
|
|
_SPECULATIVE_DECODING_MODELS,
|
|
_TEXT_GENERATION_MODELS,
|
|
ModelRegistry)
|
|
from vllm.platforms import current_platform
|
|
|
|
from ..utils import fork_new_process_for_each_test
|
|
from .registry import HF_EXAMPLE_MODELS
|
|
|
|
|
|
@pytest.mark.parametrize("model_arch", ModelRegistry.get_supported_archs())
|
|
def test_registry_imports(model_arch):
|
|
model_info = HF_EXAMPLE_MODELS.get_hf_info(model_arch)
|
|
model_info.check_transformers_version(on_fail="skip")
|
|
|
|
# Ensure all model classes can be imported successfully
|
|
model_cls, _ = ModelRegistry.resolve_model_cls(model_arch)
|
|
|
|
if model_arch in _SPECULATIVE_DECODING_MODELS:
|
|
return # Ignore these models which do not have a unified format
|
|
|
|
if (model_arch in _TEXT_GENERATION_MODELS
|
|
or model_arch in _MULTIMODAL_MODELS):
|
|
assert is_text_generation_model(model_cls)
|
|
|
|
# All vLLM models should be convertible to a pooling model
|
|
assert is_pooling_model(as_classification_model(model_cls))
|
|
assert is_pooling_model(as_embedding_model(model_cls))
|
|
assert is_pooling_model(as_reward_model(model_cls))
|
|
|
|
if model_arch in _MULTIMODAL_MODELS:
|
|
assert supports_multimodal(model_cls)
|
|
|
|
|
|
@fork_new_process_for_each_test
|
|
@pytest.mark.parametrize("model_arch,is_mm,init_cuda,is_ce", [
|
|
("LlamaForCausalLM", False, False, False),
|
|
("MllamaForConditionalGeneration", True, False, False),
|
|
("LlavaForConditionalGeneration", True, True, False),
|
|
("BertForSequenceClassification", False, False, True),
|
|
("RobertaForSequenceClassification", False, False, True),
|
|
("XLMRobertaForSequenceClassification", False, False, True),
|
|
])
|
|
def test_registry_model_property(model_arch, is_mm, init_cuda, is_ce):
|
|
assert ModelRegistry.is_multimodal_model(model_arch) is is_mm
|
|
|
|
assert ModelRegistry.is_cross_encoder_model(model_arch) is is_ce
|
|
|
|
if init_cuda and current_platform.is_cuda_alike():
|
|
assert not torch.cuda.is_initialized()
|
|
|
|
ModelRegistry.resolve_model_cls(model_arch)
|
|
if not torch.cuda.is_initialized():
|
|
warnings.warn(
|
|
"This model no longer initializes CUDA on import. "
|
|
"Please test using a different one.",
|
|
stacklevel=2)
|
|
|
|
|
|
@fork_new_process_for_each_test
|
|
@pytest.mark.parametrize("model_arch,is_pp,init_cuda", [
|
|
("MLPSpeculatorPreTrainedModel", False, False),
|
|
("DeepseekV2ForCausalLM", True, False),
|
|
("Qwen2VLForConditionalGeneration", True, True),
|
|
])
|
|
def test_registry_is_pp(model_arch, is_pp, init_cuda):
|
|
assert ModelRegistry.is_pp_supported_model(model_arch) is is_pp
|
|
|
|
if init_cuda and current_platform.is_cuda_alike():
|
|
assert not torch.cuda.is_initialized()
|
|
|
|
ModelRegistry.resolve_model_cls(model_arch)
|
|
if not torch.cuda.is_initialized():
|
|
warnings.warn(
|
|
"This model no longer initializes CUDA on import. "
|
|
"Please test using a different one.",
|
|
stacklevel=2)
|
|
|
|
|
|
def test_hf_registry_coverage():
|
|
untested_archs = (ModelRegistry.get_supported_archs() -
|
|
HF_EXAMPLE_MODELS.get_supported_archs())
|
|
|
|
assert not untested_archs, (
|
|
"Please add the following architectures to "
|
|
f"`tests/models/registry.py`: {untested_archs}")
|