2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2025-06-03 11:20:17 -07:00
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
2024-10-27 02:53:35 +09:00
|
|
|
import pytest
|
|
|
|
|
import torch
|
|
|
|
|
from transformers import AutoModelForSequenceClassification
|
|
|
|
|
|
2025-03-13 00:31:19 +08:00
|
|
|
from vllm.platforms import current_platform
|
|
|
|
|
|
2024-10-27 02:53:35 +09:00
|
|
|
|
2024-11-15 12:23:09 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"model",
|
|
|
|
|
[
|
|
|
|
|
pytest.param(
|
|
|
|
|
"jason9693/Qwen2.5-1.5B-apeach",
|
2025-09-12 13:36:50 -04:00
|
|
|
marks=[
|
|
|
|
|
pytest.mark.core_model,
|
|
|
|
|
pytest.mark.cpu_model,
|
|
|
|
|
pytest.mark.slow_test,
|
|
|
|
|
],
|
|
|
|
|
),
|
2026-03-13 11:23:53 +08:00
|
|
|
pytest.param("Forrest20231206/ernie-3.0-base-zh-cls"),
|
2024-11-15 12:23:09 +08:00
|
|
|
],
|
|
|
|
|
)
|
2025-03-13 00:31:19 +08:00
|
|
|
@pytest.mark.parametrize("dtype", ["half"] if current_platform.is_rocm() else ["float"])
|
2025-05-01 20:19:32 +08:00
|
|
|
def test_models(
|
2024-10-27 02:53:35 +09:00
|
|
|
hf_runner,
|
|
|
|
|
vllm_runner,
|
|
|
|
|
example_prompts,
|
|
|
|
|
model: str,
|
|
|
|
|
dtype: str,
|
|
|
|
|
) -> None:
|
2025-06-19 01:36:33 -03:00
|
|
|
with vllm_runner(model, max_model_len=512, dtype=dtype) as vllm_model:
|
2024-11-14 10:54:59 +08:00
|
|
|
vllm_outputs = vllm_model.classify(example_prompts)
|
2025-01-20 15:00:59 +08:00
|
|
|
|
2024-10-27 02:53:35 +09:00
|
|
|
with hf_runner(
|
|
|
|
|
model, dtype=dtype, auto_cls=AutoModelForSequenceClassification
|
|
|
|
|
) as hf_model:
|
|
|
|
|
hf_outputs = hf_model.classify(example_prompts)
|
|
|
|
|
|
|
|
|
|
# check logits difference
|
|
|
|
|
for hf_output, vllm_output in zip(hf_outputs, vllm_outputs):
|
|
|
|
|
hf_output = torch.tensor(hf_output)
|
|
|
|
|
vllm_output = torch.tensor(vllm_output)
|
|
|
|
|
|
2025-03-13 00:31:19 +08:00
|
|
|
# the tolerance value of 1e-2 is selected based on the
|
|
|
|
|
# half datatype tests in
|
2025-06-01 11:04:23 +08:00
|
|
|
# tests/models/language/pooling/test_embedding.py
|
2025-03-13 00:31:19 +08:00
|
|
|
assert torch.allclose(
|
2026-03-11 03:08:16 -07:00
|
|
|
hf_output,
|
|
|
|
|
vllm_output,
|
2026-03-13 11:23:53 +08:00
|
|
|
atol=1e-3 if dtype == "float" else 1e-2,
|
2026-03-11 03:08:16 -07:00
|
|
|
rtol=2e-3 if dtype == "float" else 1e-2,
|
2025-03-13 00:31:19 +08:00
|
|
|
)
|