Convert formatting to use ruff instead of yapf + isort (#26247)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2025-10-05 15:06:22 +01:00
committed by GitHub
parent 17edd8a807
commit d6953beb91
1508 changed files with 115244 additions and 94146 deletions

View File

@@ -1,8 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from vllm.triton_utils.importing import (HAS_TRITON, TritonLanguagePlaceholder,
TritonPlaceholder)
from vllm.triton_utils.importing import (
HAS_TRITON,
TritonLanguagePlaceholder,
TritonPlaceholder,
)
if HAS_TRITON:
import triton

View File

@@ -21,15 +21,15 @@ if HAS_TRITON:
# an is_active method.
# The `x.driver and` check adds a small layer of safety.
active_drivers = [
x.driver for x in backends.values()
if x.driver and x.driver.is_active()
x.driver for x in backends.values() if x.driver and x.driver.is_active()
]
# Check if we're in a distributed environment where CUDA_VISIBLE_DEVICES
# might be temporarily empty (e.g., Ray sets it to "" during actor init)
cuda_visible_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
is_distributed_env = (cuda_visible_devices is not None
and len(cuda_visible_devices.strip()) == 0)
is_distributed_env = (
cuda_visible_devices is not None and len(cuda_visible_devices.strip()) == 0
)
# Apply lenient driver check for distributed environments
if is_distributed_env and len(active_drivers) == 0:
@@ -37,35 +37,41 @@ if HAS_TRITON:
# active later when CUDA context is properly initialized
logger.debug(
"Triton found 0 active drivers in distributed environment. "
"This is expected during initialization.")
"This is expected during initialization."
)
elif not is_distributed_env and len(active_drivers) != 1:
# Strict check for non-distributed environments
logger.info(
"Triton is installed but %d active driver(s) found "
"(expected 1). Disabling Triton to prevent runtime errors.",
len(active_drivers))
len(active_drivers),
)
HAS_TRITON = False
except ImportError:
# This can occur if Triton is partially installed or triton.backends
# is missing.
logger.warning(
"Triton is installed, but `triton.backends` could not be imported. "
"Disabling Triton.")
"Disabling Triton."
)
HAS_TRITON = False
except Exception as e:
# Catch any other unexpected errors during the check.
logger.warning(
"An unexpected error occurred while checking Triton active drivers:"
" %s. Disabling Triton.", e)
" %s. Disabling Triton.",
e,
)
HAS_TRITON = False
if not HAS_TRITON:
logger.info("Triton not installed or not compatible; certain GPU-related"
" functions will not be available.")
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.__version__ = "3.4.0"
@@ -76,7 +82,6 @@ class TritonPlaceholder(types.ModuleType):
self.language = TritonLanguagePlaceholder()
def _dummy_decorator(self, name):
def decorator(*args, **kwargs):
if args and callable(args[0]):
return args[0]
@@ -86,7 +91,6 @@ class TritonPlaceholder(types.ModuleType):
class TritonLanguagePlaceholder(types.ModuleType):
def __init__(self):
super().__init__("triton.language")
self.constexpr = None