diff --git a/tests/test_triton_utils.py b/tests/test_triton_utils.py index 0ae4c0d6d6..7f6422466f 100644 --- a/tests/test_triton_utils.py +++ b/tests/test_triton_utils.py @@ -97,7 +97,8 @@ def test_triton_placeholder_language(): lang = TritonLanguagePlaceholder() assert isinstance(lang, types.ModuleType) assert lang.__name__ == "triton.language" - assert lang.constexpr is None + assert lang.constexpr(2**31 - 1) == 2**31 - 1 + assert lang.constexpr(1.5) == 1.5 assert lang.dtype is None assert lang.int64 is None assert lang.int32 is None @@ -143,3 +144,4 @@ def test_no_triton_fallback(): assert triton.__class__.__name__ == "TritonPlaceholder" assert triton.language.__class__.__name__ == "TritonLanguagePlaceholder" assert tl.__class__.__name__ == "TritonLanguagePlaceholder" + assert tl.constexpr(2**31 - 1) == 2**31 - 1 diff --git a/vllm/triton_utils/importing.py b/vllm/triton_utils/importing.py index 966ab55f32..e312564c0b 100644 --- a/vllm/triton_utils/importing.py +++ b/vllm/triton_utils/importing.py @@ -124,7 +124,7 @@ class TritonPlaceholder(types.ModuleType): class TritonLanguagePlaceholder(types.ModuleType): def __init__(self): super().__init__("triton.language") - self.constexpr = None + self.constexpr = lambda value: value self.dtype = None self.int64 = None self.int32 = None diff --git a/vllm/v1/worker/gpu/sample/gumbel.py b/vllm/v1/worker/gpu/sample/gumbel.py index 7220212369..44cbadb9e0 100644 --- a/vllm/v1/worker/gpu/sample/gumbel.py +++ b/vllm/v1/worker/gpu/sample/gumbel.py @@ -2,22 +2,20 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import torch -from vllm.triton_utils import HAS_TRITON, tl, triton +from vllm.triton_utils import tl, triton # Smallest positive value produced by Triton's fp32 `tl.rand`. Used by the # retained Philox helper for rejection sampling. # # Triton requires globals accessed from `@triton.jit` functions to be wrapped -# in `tl.constexpr(...)`. We can only do that when Triton is actually -# available — on the CPU worker path `tl` is a placeholder whose `constexpr` -# attribute is `None`, and `tl.constexpr(...)` would crash at import time. -_TL_RAND_MIN = tl.constexpr(4.6566127342e-10) if HAS_TRITON else 4.6566127342e-10 +# in `tl.constexpr(...)`. +_TL_RAND_MIN = tl.constexpr(4.6566127342e-10) # Offset salt keeping the draft's Gumbel noise disjoint from the target's. # Verification is a probability-ratio test, not a Gumbel coupling, so a proposal # and the residual it is resampled from must not share a noise vector. # Positions are int64 and never approach 2**30, so the streams cannot collide. -_DRAFT_NOISE_SALT = tl.constexpr(1 << 30) if HAS_TRITON else (1 << 30) +_DRAFT_NOISE_SALT = tl.constexpr(1 << 30) @triton.jit