94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
150 lines
5.2 KiB
Python
150 lines
5.2 KiB
Python
"""Async invariant probes — fire torch._assert_async without CPU sync.
|
|
|
|
All probes are gated on SGLANG_ENABLE_ASYNC_ASSERT (default off in prod).
|
|
When the gate is on, a violation surfaces as an assertion at the next CUDA
|
|
sync point instead of as a silent NaN cascade or illegal-address crash.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Optional
|
|
|
|
import torch
|
|
|
|
from sglang.srt.environ import envs
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class _AsyncNanWarner:
|
|
"""One-shot NaN monitor: device-side detection lands in pinned host
|
|
memory without any stream sync; the host reads the (slightly stale) flag
|
|
on a later call, warns once, and stops detecting."""
|
|
|
|
def __init__(self):
|
|
self._dev = None
|
|
self._host = None
|
|
self._warned = False
|
|
|
|
def check(self, tensor: torch.Tensor, msg: str):
|
|
if self._warned or not tensor.is_cuda:
|
|
return
|
|
if self._dev is None:
|
|
self._dev = torch.zeros(1, dtype=torch.int32, device=tensor.device)
|
|
self._host = torch.zeros(1, dtype=torch.int32, pin_memory=True)
|
|
|
|
# Report a hit enqueued on an earlier step (pinned read, no sync).
|
|
if int(self._host[0]):
|
|
logger.warning(
|
|
"NaN detected in %s; values were sanitized before sampling. "
|
|
"This usually indicates numerical overflow (e.g. fp16 "
|
|
"activations) or an upstream bug producing NaN. "
|
|
"Logged once; further occurrences are silent.",
|
|
msg,
|
|
)
|
|
self._warned = True
|
|
return
|
|
|
|
# Enqueue this step's detection (async, no sync).
|
|
self._dev.add_(torch.isnan(tensor).any().to(torch.int32))
|
|
self._host.copy_(self._dev, non_blocking=True)
|
|
|
|
|
|
_nan_warner = _AsyncNanWarner()
|
|
|
|
|
|
def maybe_warn_nan(tensor: Optional[torch.Tensor], msg: str = ""):
|
|
"""Non-fatal counterpart of maybe_detect_nan: throttled sync-free warning
|
|
instead of crashing. Callers sanitize the tensor themselves."""
|
|
if envs.SGLANG_ENABLE_ASYNC_ASSERT.get():
|
|
# The hard assert path already covers detection.
|
|
return
|
|
if tensor is None:
|
|
return
|
|
_nan_warner.check(tensor, msg)
|
|
|
|
|
|
def sanitize_nan_logits(logits: torch.Tensor, msg: str = ""):
|
|
"""Detect NaN (assert in CI, throttled warning in prod), then sanitize in
|
|
place: NaN logits (e.g. fp16 activation overflow) are undefined behavior
|
|
in sampling kernels and can come back as out-of-vocab token ids. +-1e30
|
|
rather than dtype min/max because callers divide logits by temperature,
|
|
which would overflow dtype min/max to +-Inf and softmax back to NaN."""
|
|
maybe_detect_nan(logits, msg)
|
|
if not envs.SGLANG_SANITIZE_NAN_LOGITS.get():
|
|
return
|
|
maybe_warn_nan(logits, msg)
|
|
torch.nan_to_num_(logits, nan=-1e30, posinf=1e30, neginf=-1e30)
|
|
|
|
|
|
def maybe_assert_async(cond: torch.Tensor, msg: str = ""):
|
|
if not envs.SGLANG_ENABLE_ASYNC_ASSERT.get():
|
|
return
|
|
torch._assert_async(cond, msg)
|
|
|
|
|
|
def maybe_detect_nan(tensor: Optional[torch.Tensor], msg: str = ""):
|
|
"""Async NaN check — no GPU-CPU sync, error surfaces at next sync point."""
|
|
if not envs.SGLANG_ENABLE_ASYNC_ASSERT.get():
|
|
return
|
|
# A None tensor means there is nothing to probe, e.g. hidden_states on
|
|
# capture_hidden_mode=NULL paths (STANDALONE speculative decoding).
|
|
if tensor is None:
|
|
return
|
|
torch._assert_async(~torch.any(torch.isnan(tensor)), f"NaN detected! {msg}")
|
|
|
|
|
|
def maybe_detect_inf(tensor: Optional[torch.Tensor], msg: str = ""):
|
|
"""Async Inf check — fp16 overflow surfaces as Inf before NaN."""
|
|
if not envs.SGLANG_ENABLE_ASYNC_ASSERT.get():
|
|
return
|
|
if tensor is None:
|
|
return
|
|
torch._assert_async(~torch.any(torch.isinf(tensor)), f"Inf detected! {msg}")
|
|
|
|
|
|
def maybe_detect_in_closed_range(
|
|
tensor: Optional[torch.Tensor], low: float, high: float, msg: str = ""
|
|
):
|
|
if not envs.SGLANG_ENABLE_ASYNC_ASSERT.get():
|
|
return
|
|
if tensor is None or tensor.numel() == 0:
|
|
return
|
|
torch._assert_async(
|
|
((tensor >= low) & (tensor <= high)).all(),
|
|
f"value outside [{low}, {high}]: {msg}",
|
|
)
|
|
|
|
|
|
def maybe_detect_oob(indices: Optional[torch.Tensor], low: int, high: int, msg: str):
|
|
"""Async OOB check — no GPU-CPU sync, error surfaces at next sync point.
|
|
|
|
Low/high asserted separately so the message names which failed (low =
|
|
negative/sentinel, high = out of range).
|
|
"""
|
|
if not envs.SGLANG_ENABLE_ASYNC_ASSERT.get():
|
|
return
|
|
if indices is None or indices.numel() == 0:
|
|
return
|
|
torch._assert_async(
|
|
indices.min() >= low,
|
|
f"index < {low} (negative / unmasked sentinel?): {msg}",
|
|
)
|
|
torch._assert_async(
|
|
indices.max() < high,
|
|
f"index >= {high} (out of range): {msg}",
|
|
)
|
|
|
|
|
|
def maybe_detect_page_aligned(
|
|
indices: Optional[torch.Tensor], page_size: int, msg: str
|
|
):
|
|
"""Async page-alignment check on slot ids."""
|
|
if not envs.SGLANG_ENABLE_ASYNC_ASSERT.get():
|
|
return
|
|
if indices is None or indices.numel() == 0 or page_size <= 1:
|
|
return
|
|
torch._assert_async(
|
|
(indices % page_size == 0).all(),
|
|
f"page-misaligned indices (page_size={page_size}): {msg}",
|
|
)
|