Skip to content

Commit 861a0a0

Browse files
[Bugfix] Don't attempt to use triton if no driver is active (#19561)
1 parent bc956b3 commit 861a0a0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

vllm/triton_utils/importing.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@
1212
find_spec("triton") is not None
1313
or find_spec("pytorch-triton-xpu") is not None # Not compatible
1414
)
15+
if HAS_TRITON:
16+
try:
17+
from triton.backends import backends
18+
19+
# It's generally expected that x.driver exists and has
20+
# an is_active method.
21+
# The `x.driver and` check adds a small layer of safety.
22+
active_drivers = [
23+
x.driver for x in backends.values()
24+
if x.driver and x.driver.is_active()
25+
]
26+
if len(active_drivers) != 1:
27+
logger.info(
28+
"Triton is installed but %d active driver(s) found "
29+
"(expected 1). Disabling Triton to prevent runtime errors.",
30+
len(active_drivers))
31+
HAS_TRITON = False
32+
except ImportError:
33+
# This can occur if Triton is partially installed or triton.backends
34+
# is missing.
35+
logger.warning(
36+
"Triton is installed, but `triton.backends` could not be imported. "
37+
"Disabling Triton.")
38+
HAS_TRITON = False
39+
except Exception as e:
40+
# Catch any other unexpected errors during the check.
41+
logger.warning(
42+
"An unexpected error occurred while checking Triton active drivers:"
43+
" %s. Disabling Triton.", e)
44+
HAS_TRITON = False
1545

1646
if not HAS_TRITON:
1747
logger.info("Triton not installed or not compatible; certain GPU-related"

0 commit comments

Comments
 (0)