Signed-off-by: Minjang Kim <minjang@meta.com> Co-authored-by: Autopilot Bot <noreply+1608173377072046@fb.com> Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
co-authored by
Autopilot Bot
OpenAI Codex
parent
8fe9317f2e
commit
af119619c4
@@ -1,13 +1,46 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
import types
|
||||
from unittest import mock
|
||||
|
||||
from vllm.triton_utils import importing as triton_importing
|
||||
from vllm.triton_utils.importing import TritonLanguagePlaceholder, TritonPlaceholder
|
||||
|
||||
|
||||
def _has_triton_for_backends(**drivers: bool) -> bool:
|
||||
"""Re-evaluate ``HAS_TRITON`` against a synthetic ``triton.backends`` map.
|
||||
|
||||
``drivers`` maps backend name to whether its driver reports itself active.
|
||||
"""
|
||||
backends = {}
|
||||
for name, is_active in drivers.items():
|
||||
driver = mock.Mock()
|
||||
driver.is_active.return_value = is_active
|
||||
backend = mock.Mock()
|
||||
backend.driver = driver
|
||||
backends[name] = backend
|
||||
|
||||
triton_mod = types.ModuleType("triton")
|
||||
triton_mod.__spec__ = importlib.machinery.ModuleSpec("triton", None)
|
||||
backends_mod = types.ModuleType("triton.backends")
|
||||
backends_mod.__dict__["backends"] = backends
|
||||
triton_mod.__dict__["backends"] = backends_mod
|
||||
|
||||
patched_modules = {"triton": triton_mod, "triton.backends": backends_mod}
|
||||
try:
|
||||
with (
|
||||
mock.patch.dict(sys.modules, patched_modules),
|
||||
mock.patch.dict("os.environ", {}, clear=True),
|
||||
):
|
||||
return importlib.reload(triton_importing).HAS_TRITON
|
||||
finally:
|
||||
# Restore the module state derived from the real environment.
|
||||
importlib.reload(triton_importing)
|
||||
|
||||
|
||||
def test_triton_placeholder_is_module():
|
||||
triton = TritonPlaceholder()
|
||||
assert isinstance(triton, types.ModuleType)
|
||||
@@ -77,6 +110,24 @@ def test_triton_placeholder_language_from_parent():
|
||||
assert isinstance(lang, TritonLanguagePlaceholder)
|
||||
|
||||
|
||||
def test_cpu_backend_does_not_disable_triton():
|
||||
# The cpu backend's driver is always active, so counting it alongside a GPU
|
||||
# backend used to yield 2 active drivers and disable Triton entirely.
|
||||
assert _has_triton_for_backends(amd=True, cpu=True) is True
|
||||
|
||||
|
||||
def test_single_gpu_backend_keeps_triton():
|
||||
assert _has_triton_for_backends(amd=True) is True
|
||||
|
||||
|
||||
def test_multiple_active_gpu_backends_disable_triton():
|
||||
assert _has_triton_for_backends(amd=True, nvidia=True) is False
|
||||
|
||||
|
||||
def test_cpu_backend_alone_disables_triton():
|
||||
assert _has_triton_for_backends(cpu=True) is False
|
||||
|
||||
|
||||
def test_no_triton_fallback():
|
||||
# clear existing triton modules
|
||||
sys.modules.pop("triton", None)
|
||||
|
||||
@@ -23,8 +23,15 @@ if HAS_TRITON:
|
||||
# It's generally expected that x.driver exists and has
|
||||
# an is_active method.
|
||||
# The `x.driver and` check adds a small layer of safety.
|
||||
# The "cpu" backend's driver reports itself active unconditionally, so
|
||||
# it must be excluded here or every GPU host looks like it has 2 active
|
||||
# drivers. Triton's own driver selection skips it for the same reason
|
||||
# (see triton.runtime.driver._create_driver): CPU is only ever used
|
||||
# when explicitly selected.
|
||||
active_drivers = [
|
||||
x.driver for x in backends.values() if x.driver and x.driver.is_active()
|
||||
x.driver
|
||||
for name, x in backends.items()
|
||||
if name != "cpu" and x.driver and x.driver.is_active()
|
||||
]
|
||||
|
||||
# Check if we're in a distributed environment where CUDA_VISIBLE_DEVICES
|
||||
|
||||
Reference in New Issue
Block a user