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
116 lines
3.7 KiB
Python
116 lines
3.7 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Optional
|
|
|
|
import torch
|
|
|
|
from sglang.jit_kernel.utils import (
|
|
cache_once,
|
|
is_arch_support_pdl,
|
|
is_hip_runtime,
|
|
load_jit,
|
|
make_cpp_args,
|
|
)
|
|
|
|
from .utils import make_name
|
|
|
|
|
|
@cache_once
|
|
def _jit_topk_v1_module(topk: int):
|
|
args = make_cpp_args(is_arch_support_pdl())
|
|
assert topk in (512, 1024), "Only support topk=512 or 1024"
|
|
return load_jit(
|
|
make_name(f"topk_v1_{topk}"),
|
|
*args,
|
|
cuda_files=["deepseek_v4/topk_v1.cuh"],
|
|
cuda_wrappers=[("topk_transform", f"TopKKernel<{args}>::transform")],
|
|
extra_cuda_cflags=[f"-DSGL_TOPK={topk}"],
|
|
)
|
|
|
|
|
|
@cache_once
|
|
def _jit_topk_v2_module():
|
|
# v2 is universal: topk (<= 2048) is a runtime argument, not a compile-time
|
|
# constant, so a single module serves every k.
|
|
return load_jit(
|
|
make_name("topk_v2"),
|
|
cuda_files=["deepseek_v4/topk_v2.cuh"],
|
|
cuda_wrappers=[
|
|
("topk_transform", "TopKKernel::transform"),
|
|
("topk_plan", "TopKKernel::plan"),
|
|
],
|
|
)
|
|
|
|
|
|
def topk_transform_512(
|
|
scores: torch.Tensor,
|
|
seq_lens: torch.Tensor,
|
|
page_tables: torch.Tensor,
|
|
out_page_indices: torch.Tensor,
|
|
page_size: int,
|
|
out_raw_indices: Optional[torch.Tensor] = None,
|
|
) -> None:
|
|
if is_hip_runtime():
|
|
torch.ops.sgl_kernel.deepseek_v4_topk_transform_512(
|
|
scores, seq_lens, page_tables, out_page_indices, page_size, out_raw_indices
|
|
)
|
|
else:
|
|
module = _jit_topk_v1_module(out_page_indices.shape[1])
|
|
module.topk_transform(
|
|
scores, seq_lens, page_tables, out_page_indices, page_size, out_raw_indices
|
|
)
|
|
|
|
|
|
# metadata is (batch+1, 2) int32: row 0 = {cluster_threshold, num_cluster_items};
|
|
# rows 1..N = {batch_id, seq_len} of items routed to the persistent cluster pool.
|
|
_PLAN_METADATA_INTS_PER_BATCH = 2
|
|
|
|
|
|
def plan_topk_v2(seq_lens: torch.Tensor, static_threshold: int = 0) -> torch.Tensor:
|
|
"""Preprocess the per-batch routing plan for :func:`topk_transform_512_v2`.
|
|
|
|
IMPORTANT: every entry of ``seq_lens`` must be NON-NEGATIVE. The device
|
|
kernel reads the int32 buffer as ``uint32_t``, so a negative length (e.g.
|
|
-4 from a DP-padded / idle-companion row) reinterprets as ~4e9, poisons
|
|
the plan, and drives the transform kernel into an illegal memory access.
|
|
Producers of padded rows must clamp their lengths to 0 (0 selects the
|
|
trivial all-(-1) output path, which is safe).
|
|
"""
|
|
module = _jit_topk_v2_module()
|
|
bs = seq_lens.shape[0]
|
|
metadata = seq_lens.new_empty(bs + 1, _PLAN_METADATA_INTS_PER_BATCH)
|
|
module.topk_plan(seq_lens, metadata, static_threshold)
|
|
return metadata
|
|
|
|
|
|
def topk_transform_512_v2(
|
|
scores: torch.Tensor,
|
|
seq_lens: torch.Tensor,
|
|
page_tables: torch.Tensor,
|
|
out_page_indices: torch.Tensor,
|
|
page_size: int,
|
|
metadata: torch.Tensor,
|
|
out_raw_indices: Optional[torch.Tensor] = None,
|
|
) -> None:
|
|
"""Fused top-k + page-table transform (DeepSeek-V4 top-k v2 kernel).
|
|
|
|
IMPORTANT: every entry of ``seq_lens`` must be NON-NEGATIVE, and
|
|
``metadata`` must come from :func:`plan_topk_v2` over the same ``seq_lens``
|
|
values. The kernel reads lengths as ``uint32_t``: a negative entry
|
|
reinterprets as a ~4e9-token sequence, sending the row down the cluster
|
|
path over garbage scores and crashing with an illegal memory access
|
|
(GLM 5.2 MTP DP-idle companion rows hit exactly this). A length of 0 is
|
|
the valid way to express "no tokens": the row takes the trivial path and
|
|
the output is all -1.
|
|
"""
|
|
module = _jit_topk_v2_module()
|
|
module.topk_transform(
|
|
scores,
|
|
seq_lens,
|
|
page_tables,
|
|
out_page_indices,
|
|
page_size,
|
|
metadata,
|
|
out_raw_indices,
|
|
)
|