Skip to content

Commit 103654c

Browse files
[Misc] Remove redundant imported envs, using envs_ascend instead (#2193)
### What this PR does / why we need it? Remove redundant imported `envs`, using `envs_ascend` instead. ```python import vllm.envs as envs_vllm import vllm_ascend.envs as envs_ascend ``` - vLLM version: v0.10.0 - vLLM main: vllm-project/vllm@71683ca --------- Signed-off-by: shen-shanshan <[email protected]>
1 parent 55d0790 commit 103654c

File tree

14 files changed

+46
-46
lines changed

14 files changed

+46
-46
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import vllm
66
from pytest_mock import MockerFixture
77

8+
import vllm_ascend.envs as envs_ascend
89
from tests.ut.base import PytestBase
9-
from vllm_ascend import envs
1010
from vllm_ascend.patch.worker.patch_common import patch_linear
1111

1212

@@ -158,10 +158,10 @@ def test_calc_output(
158158
assert torch.allclose(ret, expected)
159159

160160
def test_enable_allreduce_matmul(self, mocker: MockerFixture):
161-
mocker.patch.object(envs,
161+
mocker.patch.object(envs_ascend,
162162
"VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE",
163163
new=True)
164164
reload(patch_linear)
165-
assert envs.VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE
165+
assert envs_ascend.VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE
166166
assert id(vllm.model_executor.layers.linear.RowParallelLinear) == id(
167167
patch_linear.AscendRowParallelLinear)

tests/ut/test_envs.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@
1515
import inspect
1616
import os
1717

18+
import vllm_ascend.envs as envs_ascend
1819
from tests.ut.base import TestBase
19-
from vllm_ascend import envs
2020

2121

2222
class TestEnvVariables(TestBase):
2323

2424
def setUp(self):
25-
self.env_vars = list(envs.env_variables.keys())
25+
self.env_vars = list(envs_ascend.env_variables.keys())
2626

2727
def test_env_vars_behavior(self):
2828
for var_name in self.env_vars:
2929
with self.subTest(var=var_name):
3030
original_val = os.environ.get(var_name)
31-
var_handler = envs.env_variables[var_name]
31+
var_handler = envs_ascend.env_variables[var_name]
3232

3333
try:
3434
if var_name in os.environ:
3535
del os.environ[var_name]
36-
self.assertEqual(getattr(envs, var_name), var_handler())
36+
self.assertEqual(getattr(envs_ascend, var_name),
37+
var_handler())
3738

3839
handler_source = inspect.getsource(var_handler)
3940
if 'int(' in handler_source:
@@ -45,7 +46,7 @@ def test_env_vars_behavior(self):
4546

4647
for test_val in test_vals:
4748
os.environ[var_name] = test_val
48-
self.assertEqual(getattr(envs, var_name),
49+
self.assertEqual(getattr(envs_ascend, var_name),
4950
var_handler())
5051

5152
finally:
@@ -55,7 +56,7 @@ def test_env_vars_behavior(self):
5556
os.environ[var_name] = original_val
5657

5758
def test_dir_and_getattr(self):
58-
self.assertEqual(sorted(envs.__dir__()), sorted(self.env_vars))
59+
self.assertEqual(sorted(envs_ascend.__dir__()), sorted(self.env_vars))
5960
for var_name in self.env_vars:
6061
with self.subTest(var=var_name):
61-
getattr(envs, var_name)
62+
getattr(envs_ascend, var_name)

vllm_ascend/ascend_forward_context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
get_tensor_model_parallel_world_size)
1010
from vllm.forward_context import get_forward_context, set_forward_context
1111

12-
import vllm_ascend.envs as envs
12+
import vllm_ascend.envs as envs_ascend
1313
from vllm_ascend.distributed.moe_comm_method import MoECommMethod
1414

1515

@@ -27,15 +27,15 @@ def _get_fused_moe_state(ep_size: int, with_prefill: bool,
2727
is_deepseek_v3_r1: bool):
2828
# the fusion operator torch_npu.npu_grouped_matmul_finalize_routing called by allgather ep
2929
# only supports deepseek v3/r1
30-
if (envs.VLLM_ENABLE_FUSED_EXPERTS_ALLGATHER_EP and ep_size > 1
30+
if (envs_ascend.VLLM_ENABLE_FUSED_EXPERTS_ALLGATHER_EP and ep_size > 1
3131
and is_deepseek_v3_r1):
3232
return FusedMoEState.AllGatherEP
3333
elif ep_size == 1:
3434
if with_prefill:
3535
return FusedMoEState.NaiveMulticast
3636
else:
3737
return FusedMoEState.AllGather
38-
elif envs.VLLM_ASCEND_ENABLE_MOE_ALL2ALL_SEQ:
38+
elif envs_ascend.VLLM_ASCEND_ENABLE_MOE_ALL2ALL_SEQ:
3939
# MC2 Dispatch/Combine performs better than alltoall_seq in decoding stage.
4040
return (FusedMoEState.All2AllSeq if
4141
(ep_size < 16 or with_prefill) else FusedMoEState.MC2)

vllm_ascend/attention/mla_v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
UnquantizedLinearMethod)
1515
from vllm.utils import cdiv, round_down
1616

17-
from vllm_ascend import envs
17+
import vllm_ascend.envs as envs_ascend
1818
from vllm_ascend.ascend_config import get_ascend_config
1919
from vllm_ascend.attention.attention_v1 import AscendAttentionState
2020
from vllm_ascend.multistream.base import MSAttentionMetadataSplitConfig
@@ -1054,7 +1054,7 @@ def _forward_decode(
10541054
# be removed after the torch_npu contains `torch_npu.atb.npu_multi_head_latent_attention` become
10551055
# public available
10561056
assert len(kv_c_and_k_pe_cache) > 1
1057-
if envs.VLLM_ASCEND_MLA_PA:
1057+
if envs_ascend.VLLM_ASCEND_MLA_PA:
10581058
attn_output = torch_npu.atb.npu_multi_head_latent_attention(
10591059
q_nope, q_pe, kv_c_and_k_pe_cache[0],
10601060
kv_c_and_k_pe_cache[1], attn_metadata.decode.block_table,

vllm_ascend/compilation/piecewise_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import torch
2525
import torch.fx as fx
26-
import vllm.envs as envs
26+
import vllm.envs as envs_vllm
2727
from vllm.compilation.backends import VllmBackend
2828
from vllm.compilation.counter import compilation_counter
2929
from vllm.compilation.monitor import end_monitoring_torch_compile
@@ -93,7 +93,7 @@ def __init__(self, graph: fx.GraphModule, vllm_config: VllmConfig,
9393

9494
self.sym_shape_indices = sym_shape_indices
9595

96-
self.is_debugging_mode = envs.VLLM_LOGGING_LEVEL == "DEBUG"
96+
self.is_debugging_mode = envs_vllm.VLLM_LOGGING_LEVEL == "DEBUG"
9797

9898
# the entries for different shapes that we need to either
9999
# compile or capture aclgraph

vllm_ascend/distributed/llmdatadist_c_mgr_connector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from vllm.v1.core.sched.output import SchedulerOutput
2828
from vllm.v1.request import Request, RequestStatus
2929

30-
from vllm_ascend import envs
30+
import vllm_ascend.envs as envs_ascend
3131
from vllm_ascend.utils import AscendSocVersion, get_ascend_soc_version
3232

3333
TORCH_DTYPE_TO_NPU_DTYPE = {
@@ -181,7 +181,7 @@ def __init__(self, vllm_config: VllmConfig, engine_id: Optional[str]):
181181
dp_rank_local = self.vllm_config.parallel_config.data_parallel_rank_local
182182
tp_size = self.vllm_config.parallel_config.tensor_parallel_size
183183

184-
self.port = dp_rank_local * tp_size + envs.VLLM_LLMDD_RPC_PORT if dp_rank_local is not None else tp_size + envs.VLLM_LLMDD_RPC_PORT
184+
self.port = dp_rank_local * tp_size + envs_ascend.VLLM_LLMDD_RPC_PORT if dp_rank_local is not None else tp_size + envs_ascend.VLLM_LLMDD_RPC_PORT
185185

186186
self._reqs_need_recv: dict[str, tuple[Request, list[int]]] = {}
187187

@@ -344,7 +344,7 @@ def __init__(self, vllm_config: VllmConfig):
344344

345345
def listen_for_agent_metadata_req(self, event: threading.Event):
346346
assert self.local_agent_metadata is not None
347-
port = envs.VLLM_LLMDD_RPC_PORT + self.local_dp_rank * self.tp_size + self.tp_rank if self.local_dp_rank is not None else envs.VLLM_LLMDD_RPC_PORT + self.tp_size + self.tp_rank
347+
port = envs_ascend.VLLM_LLMDD_RPC_PORT + self.local_dp_rank * self.tp_size + self.tp_rank if self.local_dp_rank is not None else envs_ascend.VLLM_LLMDD_RPC_PORT + self.tp_size + self.tp_rank
348348
url = f"tcp://0.0.0.0:{port}"
349349
msg_encoder = msgspec.msgpack.Encoder()
350350
msg_decoder = msgspec.msgpack.Decoder()
@@ -427,9 +427,9 @@ def init_llm_datadist(self):
427427

428428
def read_offline_rank_table(self):
429429
assert (
430-
envs.DISAGGREGATED_PREFILL_RANK_TABLE_PATH
430+
envs_ascend.DISAGGREGATED_PREFILL_RANK_TABLE_PATH
431431
), "Please set path of rank_table to env variable DISAGGREGATED_PREFILL_RANK_TABLE_PATH"
432-
rank_table_path = envs.DISAGGREGATED_PREFILL_RANK_TABLE_PATH
432+
rank_table_path = envs_ascend.DISAGGREGATED_PREFILL_RANK_TABLE_PATH
433433
with open(rank_table_path, "r", encoding="utf-8") as f:
434434
global_rank_table = json.load(f)
435435
decode_device_list = global_rank_table["decode_device_list"]

vllm_ascend/models/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from vllm import ModelRegistry
22

3-
import vllm_ascend.envs as envs
3+
import vllm_ascend.envs as envs_ascend
44

55

66
def register_model():
@@ -21,7 +21,7 @@ def register_model():
2121
"Qwen2VLForConditionalGeneration",
2222
"vllm_ascend.models.qwen2_vl:AscendQwen2VLForConditionalGeneration")
2323

24-
if envs.USE_OPTIMIZED_MODEL:
24+
if envs_ascend.USE_OPTIMIZED_MODEL:
2525
ModelRegistry.register_model(
2626
"Qwen2_5_VLForConditionalGeneration",
2727
"vllm_ascend.models.qwen2_5_vl:AscendQwen2_5_VLForConditionalGeneration"
@@ -32,7 +32,7 @@ def register_model():
3232
"vllm_ascend.models.qwen2_5_vl_without_padding:AscendQwen2_5_VLForConditionalGeneration_Without_Padding"
3333
)
3434

35-
if envs.VLLM_ASCEND_ENABLE_DBO:
35+
if envs_ascend.VLLM_ASCEND_ENABLE_DBO:
3636
ModelRegistry.register_model(
3737
"DeepseekV2ForCausalLM",
3838
"vllm_ascend.models.deepseek_dbo:CustomDeepseekDBOForCausalLM")

vllm_ascend/patch/platform/patch_common/patch_distributed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# This file is a part of the vllm-ascend project.
1919

2020
import torch
21-
import vllm.envs as envs
21+
import vllm.envs as envs_vllm
2222
from vllm.config import ParallelConfig
2323

2424
from vllm_ascend.utils import is_310p
@@ -37,7 +37,7 @@ def parallel_config_get_dp_port(self) -> int:
3737
self.data_parallel_master_port += 1
3838

3939
# NOTE: Get port from envs directly when using torchrun
40-
port = envs.VLLM_DP_MASTER_PORT if envs.VLLM_DP_MASTER_PORT else answer
40+
port = envs_vllm.VLLM_DP_MASTER_PORT if envs_vllm.VLLM_DP_MASTER_PORT else answer
4141
return port
4242

4343

vllm_ascend/patch/worker/patch_common/patch_linear.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from vllm.logger import logger
2929
from vllm.model_executor.layers.linear import RowParallelLinear
3030

31-
from vllm_ascend import envs
31+
import vllm_ascend.envs as envs_ascend
3232

3333
_HCOMM_INFO = None
3434

@@ -142,6 +142,6 @@ def calc_output(self, input_parallel: torch.Tensor) -> torch.Tensor:
142142
return output
143143

144144

145-
if envs.VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE:
145+
if envs_ascend.VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE:
146146
logger.info("AscendRowParallelLinear: Matmul all-reduce is enabled. ")
147147
vllm.model_executor.layers.linear.RowParallelLinear = AscendRowParallelLinear

vllm_ascend/platform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from typing import TYPE_CHECKING, Optional, Tuple
2121

2222
import torch
23-
import vllm.envs as envs
23+
import vllm.envs as envs_vllm
2424
from torch.distributed import ProcessGroup
2525
from torch.distributed.distributed_c10d import PrefixStore
2626
from vllm.logger import logger
@@ -116,7 +116,7 @@ def clear_npu_memory(cls):
116116

117117
@classmethod
118118
def check_and_update_config(cls, vllm_config: VllmConfig) -> None:
119-
if not envs.VLLM_USE_V1:
119+
if not envs_vllm.VLLM_USE_V1:
120120
raise ValueError("vLLM Ascend does not support V0 engine.")
121121
# initialize ascend config from vllm additional_config
122122
ascend_config = init_ascend_config(vllm_config)

0 commit comments

Comments
 (0)