Skip to content

Commit 3886d31

Browse files
[CI]Add model basic accuracy test(Qwen2.5-0.5B-Instruct)
Signed-off-by: hfadzxy <starmoon_zhang@163.com>
1 parent 5fa70b6 commit 3886d31

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ ignore_missing_imports = True
99
[mypy-transformers.*]
1010
ignore_missing_imports = True
1111

12+
[mypy-lm_eval.*]
13+
ignore_missing_imports = True

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
modelscope
33
pytest >= 6.0
44
pytest-asyncio
5+
lm-eval
6+
ray

tests/singlecard/test_accuracy.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
3+
# This file is a part of the vllm-ascend project.
4+
# Adapted from vllm-project/blob/main/tests/entrypoints/llm/test_accuracy.py
5+
# Copyright 2023 The vLLM team.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
import gc
21+
import multiprocessing
22+
from multiprocessing import Queue
23+
24+
import lm_eval
25+
import pytest
26+
import torch
27+
28+
# pre-trained model path on Hugging Face.
29+
MODEL_NAME = "Qwen/Qwen2.5-0.5B-Instruct"
30+
# Math reasoning benchmark (Grade School Math 8K).
31+
TASK = "gsm8k"
32+
# Answer validation requiring format consistency.
33+
FILTER = "exact_match,strict-match"
34+
# 3% relative tolerance for numerical accuracy.
35+
RTOL = 0.03
36+
# Baseline accuracy after VLLM optimization.
37+
EXPECTED_VALUE = 0.316
38+
39+
40+
def run_test(queue, more_args=None):
41+
model_args = f"pretrained={MODEL_NAME},max_model_len=4096"
42+
if more_args is not None:
43+
model_args = f"{model_args},{more_args}"
44+
results = lm_eval.simple_evaluate(
45+
model="vllm",
46+
model_args=model_args,
47+
tasks=TASK,
48+
batch_size="auto",
49+
)
50+
result = results["results"][TASK][FILTER]
51+
print("result:", result)
52+
queue.put(result)
53+
del results
54+
torch.npu.empty_cache()
55+
gc.collect()
56+
return
57+
58+
59+
def test_lm_eval_accuracy(monkeypatch: pytest.MonkeyPatch):
60+
with monkeypatch.context():
61+
result_queue: Queue[float] = multiprocessing.Queue()
62+
p = multiprocessing.Process(target=run_test, args=(result_queue, ))
63+
p.start()
64+
p.join()
65+
result = result_queue.get()
66+
assert (EXPECTED_VALUE - RTOL < result < EXPECTED_VALUE + RTOL), \
67+
f"Expected: {EXPECTED_VALUE}±{RTOL} | Measured: {result}"

0 commit comments

Comments
 (0)