Add Triton recompile detection (#45631)
Signed-off-by: Thien Tran <gau.nernst@yahoo.com.sg>
This commit is contained in:
@@ -206,6 +206,14 @@ def test_get_kwargs():
|
||||
assert kwargs["nested_config"]["type"]('{"field": 2}') == NestedConfig(2) # type: ignore[call-arg]
|
||||
|
||||
|
||||
def test_jit_monitor_verbose_arg():
|
||||
parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
|
||||
args = parser.parse_args(["--jit-monitor-verbose"])
|
||||
|
||||
assert args.jit_monitor_verbose
|
||||
assert EngineArgs(model="test", jit_monitor_verbose=True).jit_monitor_verbose
|
||||
|
||||
|
||||
def test_hf_token_get_kwargs():
|
||||
kwargs = get_kwargs(ModelConfig)["hf_token"]
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import os
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from types import SimpleNamespace
|
||||
from unittest import mock
|
||||
|
||||
@@ -14,8 +15,10 @@ from vllm.triton_utils import jit_monitor
|
||||
def _reset_monitor():
|
||||
"""Reset global monitor state between tests."""
|
||||
jit_monitor._active = False
|
||||
jit_monitor._verbose = False
|
||||
yield
|
||||
jit_monitor._active = False
|
||||
jit_monitor._verbose = False
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -30,10 +33,15 @@ def _make_fake_knobs(*, autotuning_print=False, jit_hook=None):
|
||||
return SimpleNamespace(autotuning=autotuning, runtime=runtime)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def _patch_triton_knobs(fake_knobs):
|
||||
"""Context manager that makes ``from triton import knobs`` return *fake_knobs*."""
|
||||
fake_triton = SimpleNamespace(knobs=fake_knobs)
|
||||
return mock.patch.dict(sys.modules, {"triton": fake_triton})
|
||||
with (
|
||||
mock.patch.dict(sys.modules, {"triton": fake_triton}),
|
||||
mock.patch.object(jit_monitor, "HAS_TRITON", True),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -108,7 +116,10 @@ class TestJitHook:
|
||||
hook = fake.runtime.jit_post_compile_hook
|
||||
mock_fn = SimpleNamespace(name="test_kernel")
|
||||
|
||||
with mock.patch.object(jit_monitor.logger, "warning") as m:
|
||||
with (
|
||||
mock.patch.object(jit_monitor.logger, "warning_once") as m,
|
||||
mock.patch.object(jit_monitor.logger, "warning") as warning,
|
||||
):
|
||||
hook(
|
||||
key="some_key",
|
||||
repr="some_repr",
|
||||
@@ -119,6 +130,7 @@ class TestJitHook:
|
||||
)
|
||||
|
||||
m.assert_called_once()
|
||||
warning.assert_not_called()
|
||||
msg = m.call_args[0][0] % m.call_args[0][1:]
|
||||
assert "Triton kernel JIT compilation during inference" in msg
|
||||
assert "test_kernel" in msg
|
||||
@@ -206,9 +218,9 @@ if _HAS_TRITON:
|
||||
tl.store(out_ptr + offs, x + y, mask=mask)
|
||||
|
||||
|
||||
def _run_add_kernel(n: int, block: int = 256) -> None:
|
||||
def _run_add_kernel(n: int, block: int = 256, offset: int = 0) -> None:
|
||||
"""Launch ``_add_kernel`` with vectors of length *n*."""
|
||||
x = torch.randn(n, device="cuda")
|
||||
x = torch.randn(n + offset, device="cuda")[offset:] # affect alignment
|
||||
y = torch.randn(n, device="cuda")
|
||||
out = torch.empty(n, device="cuda")
|
||||
grid = ((n + block - 1) // block,)
|
||||
@@ -224,7 +236,7 @@ class TestTritonJitHookIntegration:
|
||||
_run_add_kernel(1024)
|
||||
|
||||
jit_monitor.activate()
|
||||
with mock.patch.object(jit_monitor.logger, "warning") as w:
|
||||
with mock.patch.object(jit_monitor.logger, "warning_once") as w:
|
||||
_run_add_kernel(1024)
|
||||
w.assert_not_called()
|
||||
|
||||
@@ -232,9 +244,21 @@ class TestTritonJitHookIntegration:
|
||||
_run_add_kernel(1024, block=256)
|
||||
|
||||
jit_monitor.activate()
|
||||
with mock.patch.object(jit_monitor.logger, "warning") as w:
|
||||
with mock.patch.object(jit_monitor.logger, "warning_once") as w:
|
||||
# Different BLOCK (a tl.constexpr) forces recompilation.
|
||||
_run_add_kernel(1024, block=512)
|
||||
w.assert_called()
|
||||
msg = w.call_args[0][0] % w.call_args[0][1:]
|
||||
assert "_add_kernel" in msg
|
||||
|
||||
def test_verbose_warning_on_each_new_pointer_alignment(self):
|
||||
_run_add_kernel(1024)
|
||||
|
||||
jit_monitor.activate(verbose=True)
|
||||
with (
|
||||
mock.patch.object(jit_monitor.logger, "warning") as w,
|
||||
mock.patch.object(jit_monitor.logger, "warning_once") as w_once,
|
||||
):
|
||||
_run_add_kernel(1024, offset=1)
|
||||
assert w.called
|
||||
w_once.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user