Skip to content

Commit d7e1110

Browse files
authored
Re-patch TritonPlaceholder on main to make CI happy (#753)
### What this PR does / why we need it? Re-patch TritonPlaceholder on main to make CI happy - Add triton patch back until vllm-project/vllm#17446 resolved - Move patch_main before patch_common to resolve minicpm triton import issue - Add `0.8.5` and `0.8.5.post1` to make patch work on 0.8.5 all versions Related: - #704 - #690 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? All CI passed include main Signed-off-by: Yikun Jiang <yikunkero@gmail.com>
1 parent d2ead05 commit d7e1110

File tree

6 files changed

+92
-5
lines changed

6 files changed

+92
-5
lines changed

vllm_ascend/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ def register():
2323

2424

2525
def register_model():
26+
# TODO: fixme when TritonPlaceholder fixed
27+
from vllm_ascend.utils import vllm_version_is
28+
if not (vllm_version_is("0.8.5") or vllm_version_is("0.8.5.post1")):
29+
import vllm_ascend.patch.worker.patch_main.patch_tritonplaceholder # noqa
2630
from .models import register_model
2731
register_model()

vllm_ascend/patch/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,15 @@
158158
# - https://github.com/vllm-project/vllm-ascend/pull/395
159159
# Future Plan:
160160
# Revert it when the related pr is merged in vllm and vllm-ascend.
161-
#
161+
#
162+
# ** File: worker/patch_main/patch_tritonplaceholder.py **
163+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164+
# 1. `triton` Module
165+
# Why:
166+
# Triton is not supported on npu currently, importing triton will break vllm-ascend
167+
# How:
168+
# ditto
169+
# Related PR (if no, explain why): vllm haven't support yet
170+
# TritonPlaceholder is only available in vllm>0.8.5.post1
171+
# Future Plan:
172+
# https://github.com/vllm-project/vllm/pull/17446

vllm_ascend/patch/platform/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from vllm_ascend.utils import vllm_version_is
1818

1919
# Import specific patches for different versions
20-
if vllm_version_is("0.8.5"):
20+
if vllm_version_is("0.8.5") or vllm_version_is("0.8.5.post1"):
2121
from vllm_ascend.patch.platform import patch_0_8_5 # noqa: F401
2222
from vllm_ascend.patch.platform import patch_common # noqa: F401
2323
else:

vllm_ascend/patch/worker/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
from vllm_ascend.utils import vllm_version_is
1919

2020
# Import specific patches for different versions
21-
if vllm_version_is("0.8.5"):
21+
if vllm_version_is("0.8.5") or vllm_version_is("0.8.5.post1"):
2222
from vllm_ascend.patch.worker import patch_0_8_5 # noqa: F401
2323
from vllm_ascend.patch.worker import patch_common # noqa: F401
2424
else:
25+
from vllm_ascend.patch.worker import patch_main # noqa: F401 # isort:skip
2526
from vllm_ascend.patch.worker import patch_common # noqa: F401
26-
from vllm_ascend.patch.worker import patch_main # noqa: F401

vllm_ascend/patch/worker/patch_main/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
#
16+
#
17+
import vllm_ascend.patch.worker.patch_main.patch_tritonplaceholder # noqa
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#
2+
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
3+
# Copyright 2023 The vLLM team.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
# This file is a part of the vllm-ascend project.
17+
# Adapted from vllm/triton_utils/importing.py
18+
#
19+
20+
import importlib
21+
import sys
22+
import types
23+
from importlib.util import find_spec
24+
25+
from vllm.logger import logger
26+
27+
HAS_TRITON = (
28+
find_spec("triton") is not None
29+
or find_spec("pytorch-triton-xpu") is not None # Not compatible
30+
)
31+
32+
if not HAS_TRITON:
33+
logger.info("Triton not installed or not compatible; certain GPU-related"
34+
" functions will not be available.")
35+
36+
class TritonPlaceholder(types.ModuleType):
37+
38+
def __init__(self):
39+
super().__init__("triton")
40+
self.jit = self._dummy_decorator("jit")
41+
self.autotune = self._dummy_decorator("autotune")
42+
self.heuristics = self._dummy_decorator("heuristics")
43+
self.language = TritonLanguagePlaceholder()
44+
self.__spec__ = importlib.machinery.ModuleSpec(
45+
name="triton", loader=None, origin="placeholder")
46+
logger.warning_once(
47+
"Triton is not installed. Using dummy decorators. "
48+
"Install it via `pip install triton` to enable kernel"
49+
" compilation.")
50+
51+
def _dummy_decorator(self, name):
52+
53+
def decorator(func=None, **kwargs):
54+
if func is None:
55+
return lambda f: f
56+
return func
57+
58+
return decorator
59+
60+
class TritonLanguagePlaceholder(types.ModuleType):
61+
62+
def __init__(self):
63+
super().__init__("triton.language")
64+
self.constexpr = None
65+
self.dtype = None
66+
67+
sys.modules['triton'] = TritonPlaceholder()
68+
sys.modules['triton.language'] = TritonLanguagePlaceholder()
69+
70+
if 'triton' in sys.modules:
71+
logger.info("Triton module has been replaced with a placeholder.")

0 commit comments

Comments
 (0)