Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion vllm/triton_utils/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sys
import types
from abc import ABC
from importlib.util import find_spec

from vllm.logger import init_logger
Expand All @@ -25,6 +26,8 @@ def __init__(self):
self.autotune = self._dummy_decorator("autotune")
self.heuristics = self._dummy_decorator("heuristics")
self.language = TritonLanguagePlaceholder()
self.Config = self._dummy_decorator("Config")
self.__version__ = ""
logger.warning_once(
"Triton is not installed. Using dummy decorators. "
"Install it via `pip install triton` to enable kernel"
Expand All @@ -43,11 +46,36 @@ class TritonLanguagePlaceholder(types.ModuleType):

def __init__(self):
super().__init__("triton.language")
self.constexpr = None
self.constexpr = lambda x: x
self.dtype = None
self.extra = None
self.math = None
self.tensor = None

class TritonCompilerPlaceholder(types.ModuleType):

def __init__(self):
super().__init__("triton.compiler")
self.CompiledKernel = ABC

class TritonRuntimeAutotunerPlaceholder(types.ModuleType):

def __init__(self):
super().__init__("triton.runtime.autotuner")
self.OutOfResources = ABC

class TritonRuntimeJitPlaceholder(types.ModuleType):

def __init__(self):
super().__init__("triton.runtime.jit")
self.KernelInterface = ABC

sys.modules['triton'] = TritonPlaceholder()
sys.modules['triton.language'] = TritonLanguagePlaceholder()
sys.modules['triton.compiler'] = TritonCompilerPlaceholder()
sys.modules[
'triton.runtime.autotuner'] = TritonRuntimeAutotunerPlaceholder()
sys.modules['triton.runtime.jit'] = TritonRuntimeJitPlaceholder()

if 'triton' in sys.modules:
logger.info("Triton module has been replaced with a placeholder.")