[Bugfix] Fix triton import with local TritonPlaceholder (#17446)
Signed-off-by: Mengqing Cao <cmq0113@163.com>
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from vllm.triton_utils.importing import HAS_TRITON
|
||||
from vllm.triton_utils.importing import (HAS_TRITON, TritonLanguagePlaceholder,
|
||||
TritonPlaceholder)
|
||||
|
||||
__all__ = ["HAS_TRITON"]
|
||||
if HAS_TRITON:
|
||||
import triton
|
||||
import triton.language as tl
|
||||
else:
|
||||
triton = TritonPlaceholder()
|
||||
tl = TritonLanguagePlaceholder()
|
||||
|
||||
__all__ = ["HAS_TRITON", "triton", "tl"]
|
||||
|
||||
@@ -16,32 +16,34 @@ if not HAS_TRITON:
|
||||
logger.info("Triton not installed or not compatible; certain GPU-related"
|
||||
" functions will not be available.")
|
||||
|
||||
class TritonPlaceholder(types.ModuleType):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("triton")
|
||||
self.jit = self._dummy_decorator("jit")
|
||||
self.autotune = self._dummy_decorator("autotune")
|
||||
self.heuristics = self._dummy_decorator("heuristics")
|
||||
self.language = TritonLanguagePlaceholder()
|
||||
logger.warning_once(
|
||||
"Triton is not installed. Using dummy decorators. "
|
||||
"Install it via `pip install triton` to enable kernel"
|
||||
"compilation.")
|
||||
class TritonPlaceholder(types.ModuleType):
|
||||
|
||||
def _dummy_decorator(self, name):
|
||||
def __init__(self):
|
||||
super().__init__("triton")
|
||||
self.jit = self._dummy_decorator("jit")
|
||||
self.autotune = self._dummy_decorator("autotune")
|
||||
self.heuristics = self._dummy_decorator("heuristics")
|
||||
self.language = TritonLanguagePlaceholder()
|
||||
logger.warning_once(
|
||||
"Triton is not installed. Using dummy decorators. "
|
||||
"Install it via `pip install triton` to enable kernel"
|
||||
" compilation.")
|
||||
|
||||
def decorator(func=None, **kwargs):
|
||||
if func is None:
|
||||
return lambda f: f
|
||||
return func
|
||||
def _dummy_decorator(self, name):
|
||||
|
||||
return decorator
|
||||
def decorator(*args, **kwargs):
|
||||
if args and callable(args[0]):
|
||||
return args[0]
|
||||
return lambda f: f
|
||||
|
||||
class TritonLanguagePlaceholder(types.ModuleType):
|
||||
return decorator
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("triton.language")
|
||||
self.constexpr = None
|
||||
self.dtype = None
|
||||
self.int64 = None
|
||||
|
||||
class TritonLanguagePlaceholder(types.ModuleType):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("triton.language")
|
||||
self.constexpr = None
|
||||
self.dtype = None
|
||||
self.int64 = None
|
||||
|
||||
Reference in New Issue
Block a user