Skip to content

Commit 10d3c8c

Browse files
author
chengyuan
committed
add ut for envs.py
Signed-off-by: chengyuan <[email protected]>
1 parent 359c157 commit 10d3c8c

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

tests/ut/test_envs.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
import os
16+
from unittest.mock import patch
17+
18+
from tests.ut.base import TestBase
19+
from vllm_ascend.envs import env_variables
20+
21+
22+
class TestEnvVariables(TestBase):
23+
_default_values = {
24+
"MAX_JOBS": None,
25+
"CMAKE_BUILD_TYPE": None,
26+
"COMPILE_CUSTOM_KERNELS": True,
27+
"CXX_COMPILER": None,
28+
"C_COMPILER": None,
29+
"SOC_VERSION": "ASCEND910B1",
30+
"VERBOSE": False,
31+
"ASCEND_HOME_PATH": None,
32+
"HCCN_PATH": "/usr/local/Ascend/driver/tools/hccn_tool",
33+
"HCCL_SO_PATH": None,
34+
"PROMPT_DEVICE_ID": None,
35+
"DECODE_DEVICE_ID": None,
36+
"LLMDATADIST_COMM_PORT": "26000",
37+
"LLMDATADIST_SYNC_CACHE_WAIT_TIME": "5000",
38+
"VLLM_VERSION": None,
39+
"VLLM_ASCEND_TRACE_RECOMPILES": False,
40+
"VLLM_ENABLE_FUSED_EXPERTS_ALLGATHER_EP": False,
41+
"VLLM_ASCEND_ENABLE_DBO": False,
42+
"VLLM_ASCEND_MODEL_EXECUTE_TIME_OBSERVE": False,
43+
"MOE_ALL2ALL_BUFFER": False,
44+
"USE_OPTIMIZED_MODEL": True,
45+
"SELECT_GATING_TOPK_SOTFMAX_EXPERTS": False,
46+
"VLLM_ASCEND_KV_CACHE_MEGABYTES_FLOATING_TOLERANCE": 64,
47+
"VLLM_ASCEND_ENABLE_TOPK_TOPP_OPTIMIZATION": False,
48+
"DISAGGREGATED_PREFILL_RANK_TABLE_PATH": None,
49+
"VLLM_ASCEND_LLMDD_RPC_IP": "0.0.0.0",
50+
"VLLM_LLMDD_RPC_PORT": 5557,
51+
"VLLM_ASCEND_MLA_PA": False,
52+
"VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE": False
53+
}
54+
55+
_test_values = {
56+
"MAX_JOBS": ("8", "8"),
57+
"CMAKE_BUILD_TYPE": ("Debug", "Debug"),
58+
"COMPILE_CUSTOM_KERNELS": ("0", False),
59+
"CXX_COMPILER": ("/usr/bin/g++", "/usr/bin/g++"),
60+
"C_COMPILER": ("/usr/bin/gcc", "/usr/bin/gcc"),
61+
"SOC_VERSION": ("ASCEND910A", "ASCEND910A"),
62+
"VERBOSE": ("1", True),
63+
"ASCEND_HOME_PATH": ("/opt/ascend", "/opt/ascend"),
64+
"HCCN_PATH": ("/custom/hccn_tool", "/custom/hccn_tool"),
65+
"HCCL_SO_PATH": ("libhccl_custom.so", "libhccl_custom.so"),
66+
"PROMPT_DEVICE_ID": ("1", "1"),
67+
"DECODE_DEVICE_ID": ("2", "2"),
68+
"LLMDATADIST_COMM_PORT": ("27000", "27000"),
69+
"LLMDATADIST_SYNC_CACHE_WAIT_TIME": ("6000", "6000"),
70+
"VLLM_VERSION": ("0.9.1", "0.9.1"),
71+
"VLLM_ASCEND_TRACE_RECOMPILES": ("1", True),
72+
"VLLM_ENABLE_FUSED_EXPERTS_ALLGATHER_EP": ("1", True),
73+
"VLLM_ASCEND_ENABLE_DBO": ("1", True),
74+
"VLLM_ASCEND_MODEL_EXECUTE_TIME_OBSERVE": ("1", True),
75+
"MOE_ALL2ALL_BUFFER": ("1", True),
76+
"USE_OPTIMIZED_MODEL": ("0", False),
77+
"SELECT_GATING_TOPK_SOTFMAX_EXPERTS": ("1", True),
78+
"VLLM_ASCEND_KV_CACHE_MEGABYTES_FLOATING_TOLERANCE": ("128", 128),
79+
"VLLM_ASCEND_ENABLE_TOPK_TOPP_OPTIMIZATION": ("1", True),
80+
"DISAGGREGATED_PREFILL_RANK_TABLE_PATH":
81+
("/path/to/rank_table.json", "/path/to/rank_table.json"),
82+
"VLLM_ASCEND_LLMDD_RPC_IP": ("192.168.1.1", "192.168.1.1"),
83+
"VLLM_LLMDD_RPC_PORT": ("5558", 5558),
84+
"VLLM_ASCEND_MLA_PA": ("1", True),
85+
"VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE": ("1", True)
86+
}
87+
88+
def setUp(self):
89+
env_keys = set(env_variables.keys())
90+
self.assertEqual(
91+
env_keys, set(self._default_values.keys())
92+
)
93+
self.assertEqual(
94+
env_keys, set(self._test_values.keys())
95+
)
96+
97+
def test_default_values(self):
98+
for var_name, getter in env_variables.items():
99+
with self.subTest(var_name=var_name):
100+
with patch.dict(os.environ, {}, clear=True):
101+
actual = getter()
102+
expected = self._default_values[var_name]
103+
self.assertEqual(
104+
actual, expected
105+
)
106+
107+
def test_set_values(self):
108+
for var_name, getter in env_variables.items():
109+
with self.subTest(var_name=var_name):
110+
input_val, expected = self._test_values[var_name]
111+
with patch.dict(os.environ, {var_name: input_val}):
112+
actual = getter()
113+
self.assertEqual(
114+
actual, expected
115+
)

0 commit comments

Comments
 (0)