mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-10 08:04: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>
104 lines
3.2 KiB
Python
104 lines
3.2 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
"""Compare the outputs of HF and vLLM for moe models using greedy sampling.
|
|
|
|
Run `pytest tests/models/test_phimoe.py`.
|
|
"""
|
|
import pytest
|
|
import torch
|
|
|
|
from vllm.platforms import current_platform
|
|
|
|
from ....utils import large_gpu_test
|
|
from ...utils import check_logprobs_close
|
|
|
|
MODELS = [
|
|
"microsoft/Phi-3.5-MoE-instruct",
|
|
]
|
|
|
|
|
|
def test_phimoe_routing_function():
|
|
from vllm.model_executor.models.phimoe import phimoe_routing_function
|
|
test_case = {
|
|
0: {
|
|
"hidden_states":
|
|
torch.tensor([1, 2, 3, 4, 5, 6, 7, 8],
|
|
dtype=torch.float32,
|
|
requires_grad=False).view(4, 2),
|
|
"gating_output":
|
|
torch.tensor([0.1, 0.2, 0.3, 0.4],
|
|
dtype=torch.float32,
|
|
requires_grad=False),
|
|
"topk":
|
|
2,
|
|
"renormalize":
|
|
False,
|
|
},
|
|
1: {
|
|
"hidden_states":
|
|
torch.tensor([1, 2, 3, 4, 5, 6, 7, 8],
|
|
dtype=torch.float32,
|
|
requires_grad=False).view(4, 2),
|
|
"gating_output":
|
|
torch.tensor([0.4, 0.2, 0.3, 0.4],
|
|
dtype=torch.float32,
|
|
requires_grad=False),
|
|
"topk":
|
|
2,
|
|
"renormalize":
|
|
False,
|
|
}
|
|
}
|
|
|
|
ground_truth = {
|
|
0: {
|
|
"topk_weights":
|
|
torch.tensor([1., 1.], dtype=torch.float32, requires_grad=False),
|
|
"topk_ids":
|
|
torch.tensor([3, 2], dtype=torch.long, requires_grad=False),
|
|
},
|
|
1: {
|
|
"topk_weights":
|
|
torch.tensor([0.5, 1.], dtype=torch.float32, requires_grad=False),
|
|
"topk_ids":
|
|
torch.tensor([0, 3], dtype=torch.long, requires_grad=False),
|
|
}
|
|
}
|
|
|
|
for test_id in test_case:
|
|
topk_weights, topk_ids = phimoe_routing_function(**test_case[test_id])
|
|
assert torch.allclose(topk_weights,
|
|
ground_truth[test_id]["topk_weights"])
|
|
assert torch.equal(topk_ids, ground_truth[test_id]["topk_ids"])
|
|
|
|
|
|
@pytest.mark.skipif(condition=current_platform.is_cpu(),
|
|
reason="This test takes a lot time to run on CPU, "
|
|
"and vllm CI's disk space is not enough for this model.")
|
|
@large_gpu_test(min_gb=80)
|
|
@pytest.mark.parametrize("model", MODELS)
|
|
@pytest.mark.parametrize("dtype", ["bfloat16"])
|
|
@pytest.mark.parametrize("max_tokens", [64])
|
|
@pytest.mark.parametrize("num_logprobs", [5])
|
|
def test_models(
|
|
hf_runner,
|
|
vllm_runner,
|
|
example_prompts,
|
|
model: str,
|
|
dtype: str,
|
|
max_tokens: int,
|
|
num_logprobs: int,
|
|
) -> None:
|
|
with hf_runner(model, dtype=dtype) as hf_model:
|
|
hf_outputs = hf_model.generate_greedy_logprobs_limit(
|
|
example_prompts, max_tokens, num_logprobs)
|
|
|
|
with vllm_runner(model, dtype=dtype) as vllm_model:
|
|
vllm_outputs = vllm_model.generate_greedy_logprobs(
|
|
example_prompts, max_tokens, num_logprobs)
|
|
check_logprobs_close(
|
|
outputs_0_lst=hf_outputs,
|
|
outputs_1_lst=vllm_outputs,
|
|
name_0="hf",
|
|
name_1="vllm",
|
|
)
|