Skip to content

Commit 3023c18

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 00e0243 commit 3023c18

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

tests/ops/test_rotary_embedding.py

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

13-
import vllm_ascend.platform # noqa: F401
13+
from vllm_ascend.utils import try_register_lib
14+
15+
try_register_lib(
16+
"vllm_ascend.vllm_ascend_C",
17+
exc_info="Warning: Failed to register custom ops, all custom ops will be disabled."
18+
)
1419

1520
# Only Neox style true scenario is supported for now
1621
IS_NEOX_STYLE = [True]

vllm_ascend/ops/rotary_embedding.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
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 try_register_lib
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+
try_register_lib(
30+
"vllm_ascend.vllm_ascend_C",
31+
exc_info="Warning: Failed to register custom ops, all custom ops will be disabled."
32+
)
33+
return query.dtype == torch.float16 and neox_style and head_size % 32 == 0
3034

3135

3236
def rope_forward_oot(

vllm_ascend/platform.py

Lines changed: 0 additions & 16 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,18 +25,6 @@
2725

2826
from vllm_ascend.utils import ASCEND_QUATIZATION_METHOD, update_aclgraph_sizes
2927

30-
CUSTOM_OP_ENABLED = False
31-
try:
32-
# register custom ops into torch_library here
33-
import vllm_ascend.vllm_ascend_C # type: ignore # noqa: F401
34-
35-
except ImportError:
36-
logging.warning(
37-
"Warning: Failed to register custom ops, all custom ops will be disabled"
38-
)
39-
else:
40-
CUSTOM_OP_ENABLED = True
41-
4228
if TYPE_CHECKING:
4329
from vllm.config import ModelConfig, VllmConfig
4430
from vllm.utils import FlexibleArgumentParser
@@ -47,8 +33,6 @@
4733
VllmConfig = None
4834
FlexibleArgumentParser = None
4935

50-
os.environ["RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES"] = "1"
51-
5236

5337
class NPUPlatform(Platform):
5438

vllm_ascend/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
ASCEND_QUATIZATION_METHOD = "ascend"
4242

4343

44-
def try_register_lib(lib_name: str, lib_info: str = ""):
44+
def try_register_lib(lib_name: str, lib_info: str = "", exc_info: str = ""):
4545
import importlib
4646
import importlib.util
4747
try:
@@ -51,6 +51,8 @@ def try_register_lib(lib_name: str, lib_info: str = ""):
5151
if lib_info:
5252
logger.info(lib_info)
5353
except Exception:
54+
if exc_info:
55+
logger.info(exc_info)
5456
pass
5557

5658

0 commit comments

Comments
 (0)