Skip to content

Commit 5af2bea

Browse files
committed
Use Base test
Signed-off-by: Yikun Jiang <yikunkero@gmail.com>
1 parent 641a4e6 commit 5af2bea

File tree

8 files changed

+208
-25
lines changed

8 files changed

+208
-25
lines changed

docs/source/developer_guide/contribution/testing.md

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,48 @@ The fastest way to setup test environment is to use the main branch container im
99
:::::{tab-set}
1010
:sync-group: e2e
1111

12-
::::{tab-item} Single card
12+
::::{tab-item} Local (CPU)
1313
:selected:
14+
:sync: cpu
15+
16+
You can run the unit tests on CPU with the following steps:
17+
18+
```{code-block} bash
19+
:substitutions:
20+
21+
cd ~/vllm-project/
22+
# ls
23+
# vllm vllm-ascend
24+
25+
# Use mirror to speedup download
26+
# docker pull quay.nju.edu.cn/ascend/cann:|cann_image_tag|
27+
export IMAGE=quay.io/ascend/cann:|cann_image_tag|
28+
docker run --rm --name vllm-ascend-ut \
29+
-v $(pwd):/vllm-project \
30+
-v ~/.cache:/root/.cache \
31+
-ti $IMAGE bash
32+
33+
# (Optional) Configure mirror to speedup download
34+
pip config set global.index-url https://mirrors.huaweicloud.com/repository/pypi/simple/
35+
36+
apt-get update -y
37+
apt-get install -y python3-pip git vim wget net-tools gcc g++ cmake libnuma-dev curl gnupg2
38+
39+
# Install vllm
40+
cd /vllm-project/vllm
41+
VLLM_TARGET_DEVICE=empty python3 -m pip -v install .
42+
43+
# Install vllm-ascend
44+
cd /vllm-project/vllm-ascend
45+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/Ascend/ascend-toolkit/latest/$(uname -m)-linux/devlib
46+
python3 -m pip install -r requirements-dev.txt
47+
export PIP_EXTRA_INDEX_URL=https://mirrors.huaweicloud.com/ascend/repos/pypi
48+
python3 -m pip install -v .
49+
```
50+
51+
::::
52+
53+
::::{tab-item} Single card
1454
:sync: single
1555

1656
```{code-block} bash
@@ -36,6 +76,16 @@ docker run --rm \
3676
-it $IMAGE bash
3777
```
3878

79+
After starting the container, you should install the required packages:
80+
81+
```bash
82+
# Prepare
83+
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
84+
85+
# Install required packages
86+
pip install -r requirements-dev.txt
87+
```
88+
3989
::::
4090

4191
::::{tab-item} Multi cards
@@ -63,9 +113,6 @@ docker run --rm \
63113
-p 8000:8000 \
64114
-it $IMAGE bash
65115
```
66-
::::
67-
68-
:::::
69116

70117
After starting the container, you should install the required packages:
71118

@@ -77,6 +124,10 @@ pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/si
77124
pip install -r requirements-dev.txt
78125
```
79126

127+
::::
128+
129+
:::::
130+
80131
## Running tests
81132

82133
### Unit test
@@ -89,14 +140,48 @@ There are several principles to follow when writing unit tests:
89140
- Example: [tests/ut/test_ascend_config.py](https://github.com/vllm-project/vllm-ascend/blob/main/tests/ut/test_ascend_config.py).
90141
- You can run the unit tests using `pytest`:
91142

92-
```bash
93-
cd /vllm-workspace/vllm-ascend/
94-
# Run all single card the tests
95-
pytest -sv tests/ut
143+
:::::{tab-set}
144+
:sync-group: e2e
96145

97-
# Run
98-
pytest -sv tests/ut/test_ascend_config.py
99-
```
146+
::::{tab-item} Local (CPU)
147+
:sync: cpu
148+
149+
```bash
150+
# Run unit tests
151+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/Ascend/ascend-toolkit/latest/$(uname -m)-linux/devlib
152+
VLLM_USE_V1=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 pytest -sv tests/ut
153+
```
154+
155+
::::
156+
157+
::::{tab-item} Single card
158+
:selected:
159+
:sync: single
160+
161+
```bash
162+
cd /vllm-workspace/vllm-ascend/
163+
# Run all single card the tests
164+
pytest -sv tests/ut
165+
166+
# Run single test
167+
pytest -sv tests/ut/test_ascend_config.py
168+
```
169+
::::
170+
171+
::::{tab-item} Multi cards test
172+
:sync: multi
173+
174+
```bash
175+
cd /vllm-workspace/vllm-ascend/
176+
# Run all single card the tests
177+
pytest -sv tests/ut
178+
179+
# Run single test
180+
pytest -sv tests/ut/test_ascend_config.py
181+
```
182+
::::
183+
184+
:::::
100185

101186
### E2E test
102187

@@ -106,6 +191,12 @@ locally.
106191
:::::{tab-set}
107192
:sync-group: e2e
108193

194+
::::{tab-item} Local (CPU)
195+
:sync: cpu
196+
197+
You can't run e2e test on CPU.
198+
::::
199+
109200
::::{tab-item} Single card
110201
:selected:
111202
:sync: single

tests/ut/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# This file is a part of the vllm-ascend project.
14+
#
15+
116
import unittest
217

318
from vllm_ascend.utils import adapt_patch

tests/ut/distributed/test_parallel_state.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
import unittest
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# This file is a part of the vllm-ascend project.
14+
#
15+
216
from unittest.mock import MagicMock, patch
317

418
import pytest
519
from vllm.distributed.parallel_state import GroupCoordinator
620

721
import vllm_ascend
22+
from tests.ut.base import TestBase
823
from vllm_ascend.distributed.parallel_state import (
924
destory_ascend_model_parallel, get_ep_group, get_etp_group,
1025
init_ascend_model_parallel, model_parallel_initialized)
1126

1227

13-
class TestParallelState(unittest.TestCase):
28+
class TestParallelState(TestBase):
1429

1530
@patch('vllm_ascend.distributed.parallel_state._EP',
1631
new_callable=lambda: MagicMock(spec=GroupCoordinator))

tests/ut/ops/test_expert_load_balancer.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# This file is a part of the vllm-ascend project.
14+
#
15+
116
# fused moe ops test will hit the infer_schema error, we need add the patch
217
# here to make the test pass.
318
import vllm_ascend.patch.worker.patch_common.patch_utils # type: ignore[import] # isort: skip # noqa
419

520
import json
6-
import unittest
721
from typing import List, TypedDict
822
from unittest import mock
923

1024
import torch
1125

26+
from tests.ut.base import TestBase
1227
from vllm_ascend.ops.expert_load_balancer import ExpertLoadBalancer
1328

1429

@@ -47,7 +62,7 @@ class MockData(TypedDict):
4762
}
4863

4964

50-
class TestExpertLoadBalancer(unittest.TestCase):
65+
class TestExpertLoadBalancer(TestBase):
5166

5267
def setUp(self):
5368
json_file = "expert_map.json"
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# This file is a part of the vllm-ascend project.
14+
#
15+
116
from tests.ut.base import TestBase
17+
from vllm_ascend.patch.worker.patch_common.patch_distributed import \
18+
GroupCoordinatorPatch
19+
20+
# import GroupCoordinator after GroupCoordinatorPatch to make base work
21+
from vllm.distributed.parallel_state import GroupCoordinator # noqa isort:skip
222

323

424
class TestPatchDistributed(TestBase):
525

626
def test_GroupCoordinator_patched(self):
7-
from vllm.distributed.parallel_state import GroupCoordinator
8-
9-
from vllm_ascend.patch.worker.patch_common.patch_distributed import \
10-
GroupCoordinatorPatch
11-
1227
self.assertIs(GroupCoordinator, GroupCoordinatorPatch)

tests/ut/patch/worker/patch_common/test_patch_sampler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import importlib
22
import os
3-
import unittest
43
from unittest import mock
54

65
import torch
76
from vllm.v1.sample.ops import topk_topp_sampler
87

8+
from tests.ut.base import TestBase
99

10-
class TestTopKTopPSamplerOptimize(unittest.TestCase):
10+
11+
class TestTopKTopPSamplerOptimize(TestBase):
1112

1213
@mock.patch.dict(os.environ, {"VLLM_ASCEND_ENABLE_TOPK_OPTIMIZE": "1"})
1314
@mock.patch("torch_npu.npu_top_k_top_p")

tests/ut/test_ascend_config.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# This file is a part of the vllm-ascend project.
14+
#
15+
116
import os
2-
import unittest
317
from unittest import mock
418

519
from transformers import PretrainedConfig
620
from vllm.config import ModelConfig, VllmConfig
721

22+
from tests.ut.base import TestBase
823
from vllm_ascend.ascend_config import (check_ascend_config,
924
clear_ascend_config, get_ascend_config,
1025
init_ascend_config)
1126

1227

13-
class TestAscendConfig(unittest.TestCase):
28+
class TestAscendConfig(TestBase):
1429

1530
@staticmethod
1631
def _clean_up_ascend_config(func):

tests/ut/test_utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# This file is a part of the vllm-ascend project.
14+
#
15+
116
import math
217
import os
318
import unittest
@@ -8,10 +23,11 @@
823
from vllm.config import (CompilationConfig, ModelConfig, ParallelConfig,
924
VllmConfig)
1025

26+
from tests.ut.base import TestBase
1127
from vllm_ascend import utils
1228

1329

14-
class TestUtils(unittest.TestCase):
30+
class TestUtils(TestBase):
1531

1632
def test_is_310p(self):
1733
utils._IS_310P = None

0 commit comments

Comments
 (0)