Skip to content

Commit df773f0

Browse files
committed
rm RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES & add lazy init for vllm_ascend_C
Signed-off-by: zhuo97 <1103045176@qq.com>
1 parent 966557a commit df773f0

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

tests/singlecard/ops/test_rotary_embedding.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import torch
1111
import torch.nn as nn
1212

13-
import vllm_ascend.platform # noqa: F401
13+
import vllm_ascend.platform as pf
14+
15+
pf.CUSTOM_OP_ENABLED = True
1416

1517
# Only Neox style true scenario is supported for now
1618
IS_NEOX_STYLE = [True]

vllm_ascend/attention/attention.py

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

3737
from vllm_ascend.ascend_config import get_ascend_config
3838
from vllm_ascend.ops.cache import concat_and_cache_mla
39-
from vllm_ascend.platform import CUSTOM_OP_ENABLED
39+
from vllm_ascend.utils import enable_custom_op
4040
from vllm_ascend.worker.model_runner import (
4141
ModelInputForNPUBuilder, ModelInputForNPUWithSamplingMetadata)
4242

@@ -462,7 +462,7 @@ def advance_step(self,
462462
for i in range(num_queries):
463463
self.seq_lens[i] += 1
464464
self.max_decode_seq_len = max(self.seq_lens)
465-
if CUSTOM_OP_ENABLED:
465+
if enable_custom_op():
466466
#advance a step on NPU for existing inputs for a multi-step runner if custom ops is enabled
467467
torch.ops._C.advance_step_flashattn_ascendc(
468468
num_seqs=num_seqs,

vllm_ascend/ops/rotary_embedding.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
from vllm.model_executor.layers.rotary_embedding import (
2323
DeepseekScalingRotaryEmbedding, RotaryEmbedding)
2424

25-
from vllm_ascend.platform import CUSTOM_OP_ENABLED
25+
from vllm_ascend.utils import enable_custom_op
2626

2727

2828
def custom_rotary_embedding_enabled(query, neox_style, head_size):
29-
return query.dtype == torch.float16 and neox_style and head_size % 32 == 0 and CUSTOM_OP_ENABLED
29+
return query.dtype == torch.float16 and neox_style and head_size % 32 == 0 and enable_custom_op(
30+
)
3031

3132

3233
def rope_forward_oot(

vllm_ascend/platform.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#
1717

1818
import gc
19-
import logging
2019
import os
2120
from datetime import timedelta
2221
from typing import TYPE_CHECKING, Optional, Tuple
@@ -33,14 +32,6 @@
3332
from vllm_ascend.utils import ASCEND_QUATIZATION_METHOD, update_aclgraph_sizes
3433

3534
CUSTOM_OP_ENABLED = False
36-
try:
37-
# register custom ops into torch_library here
38-
import vllm_ascend.vllm_ascend_C # type: ignore # noqa: F401
39-
CUSTOM_OP_ENABLED = True
40-
except ImportError as e:
41-
logging.warning(
42-
"Failed to import 'vllm_ascend.vllm_ascend_C': %s. All custom ops will be disabled. ",
43-
e)
4435

4536
if TYPE_CHECKING:
4637
from vllm.config import ModelConfig, VllmConfig
@@ -50,7 +41,6 @@
5041
VllmConfig = None
5142
FlexibleArgumentParser = None
5243

53-
os.environ["RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES"] = "1"
5444
os.environ["ACL_OP_INIT_MODE"] = ascend_envs.VLLM_ASCEND_ACL_OP_INIT_MODE
5545

5646

vllm_ascend/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ def try_register_lib(lib_name: str, lib_info: str = ""):
6767
pass
6868

6969

70+
def enable_custom_op():
71+
CUSTOM_OP_ENABLED = False
72+
try:
73+
# register custom ops into torch_library here
74+
import vllm_ascend.vllm_ascend_C # type: ignore # noqa: F401
75+
76+
except ImportError:
77+
logger.warning(
78+
"Warning: Failed to register custom ops, all custom ops will be disabled"
79+
)
80+
else:
81+
CUSTOM_OP_ENABLED = True
82+
83+
return CUSTOM_OP_ENABLED
84+
85+
7086
def find_hccl_library() -> str:
7187
"""
7288
We either use the library file specified by the `HCCL_SO_PATH`

0 commit comments

Comments
 (0)