Skip to content

Commit 5f95402

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

File tree

7 files changed

+121
-18
lines changed

7 files changed

+121
-18
lines changed

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: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
import importlib
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
import os
3-
import unittest
417
from unittest import mock
518

619
import torch
720
from vllm.v1.sample.ops import topk_topp_sampler
821

22+
from tests.ut.base import TestBase
23+
924

10-
class TestTopKTopPSamplerOptimize(unittest.TestCase):
25+
class TestTopKTopPSamplerOptimize(TestBase):
1126

1227
@mock.patch.dict(os.environ, {"VLLM_ASCEND_ENABLE_TOPK_OPTIMIZE": "1"})
1328
@mock.patch("torch_npu.npu_top_k_top_p")
1429
def test_npu_topk_topp_called_when_optimized(self, mock_npu_op):
15-
import vllm_ascend.patch.worker.patch_common.patch_sampler
16-
importlib.reload(vllm_ascend.patch.worker.patch_common.patch_sampler)
17-
1830
mock_npu_op.return_value = (torch.randn(1, 3))
1931
sampler = topk_topp_sampler.TopKTopPSampler()
2032

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)