Skip to content

Commit 278532c

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 9e855b7 commit 278532c

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
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
from vllm.utils import async_tensor_h2d, make_tensor_with_pad
3737

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

@@ -460,7 +460,7 @@ def advance_step(self,
460460
for i in range(num_queries):
461461
self.seq_lens[i] += 1
462462
self.max_decode_seq_len = max(self.seq_lens)
463-
if CUSTOM_OP_ENABLED:
463+
if enable_custom_op():
464464
#advance a step on NPU for existing inputs for a multi-step runner if custom ops is enabled
465465
torch.ops._C.advance_step_flashattn_ascendc(
466466
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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# This file is a part of the vllm-ascend project.
1616
#
1717

18-
import logging
19-
import os
2018
from typing import TYPE_CHECKING, Optional, Tuple
2119

2220
import torch
@@ -27,14 +25,6 @@
2725
from vllm_ascend.utils import ASCEND_QUATIZATION_METHOD, update_aclgraph_sizes
2826

2927
CUSTOM_OP_ENABLED = False
30-
try:
31-
# register custom ops into torch_library here
32-
import vllm_ascend.vllm_ascend_C # type: ignore # noqa: F401
33-
CUSTOM_OP_ENABLED = True
34-
except ImportError as e:
35-
logging.warning(
36-
"Failed to import 'vllm_ascend.vllm_ascend_C': %s. All custom ops will be disabled. ",
37-
e)
3828

3929
if TYPE_CHECKING:
4030
from vllm.config import ModelConfig, VllmConfig
@@ -44,8 +34,6 @@
4434
VllmConfig = None
4535
FlexibleArgumentParser = None
4636

47-
os.environ["RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES"] = "1"
48-
4937

5038
class NPUPlatform(Platform):
5139

vllm_ascend/utils.py

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

5656

57+
def enable_custom_op():
58+
CUSTOM_OP_ENABLED = False
59+
try:
60+
# register custom ops into torch_library here
61+
import vllm_ascend.vllm_ascend_C # type: ignore # noqa: F401
62+
63+
except ImportError:
64+
logger.warning(
65+
"Warning: Failed to register custom ops, all custom ops will be disabled"
66+
)
67+
else:
68+
CUSTOM_OP_ENABLED = True
69+
70+
return CUSTOM_OP_ENABLED
71+
72+
5773
def find_hccl_library() -> str:
5874
"""
5975
We either use the library file specified by the `HCCL_SO_PATH`

0 commit comments

Comments
 (0)