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
205 lines
6.1 KiB
Python
205 lines
6.1 KiB
Python
from typing import Literal, Tuple
|
|
|
|
import torch
|
|
import triton
|
|
import triton.language as tl
|
|
|
|
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_metadata_module():
|
|
return load_jit(
|
|
make_name("metadata"),
|
|
cuda_files=["deepseek_v4/paged_mqa_metadata.cuh"],
|
|
cuda_wrappers=[("run", "IndexerMetadataKernel::run")],
|
|
)
|
|
|
|
|
|
@cache_once
|
|
def _jit_fused_store_module(
|
|
name: Literal["flashmla", "indexer"],
|
|
input_dtype: torch.dtype,
|
|
index_dtype: torch.dtype,
|
|
page_size: int,
|
|
):
|
|
args = make_cpp_args(input_dtype, index_dtype, page_size, is_arch_support_pdl())
|
|
cname = "FlashMLA" if name == "flashmla" else "Indexer"
|
|
kernel_class = f"FusedStoreCache{cname}Kernel<{args}>"
|
|
return load_jit(
|
|
make_name("store_" + name),
|
|
*args,
|
|
cuda_files=["deepseek_v4/store.cuh"],
|
|
cuda_wrappers=[("run", f"{kernel_class}::run")],
|
|
)
|
|
|
|
|
|
def get_paged_mqa_logits_metadata(seq_lens: torch.Tensor, page_size: int, num_sm: int):
|
|
assert page_size == 64
|
|
seq_lens = seq_lens.view(-1).to(torch.int32)
|
|
metadata = seq_lens.new_empty(num_sm + 1, 2)
|
|
module = _jit_metadata_module()
|
|
module.run(seq_lens, metadata)
|
|
return metadata
|
|
|
|
|
|
def fused_store_cache(
|
|
input: torch.Tensor,
|
|
cache: torch.Tensor,
|
|
indices: torch.Tensor,
|
|
*,
|
|
page_size: int,
|
|
type: Literal["flashmla", "indexer"],
|
|
) -> None:
|
|
if is_hip_runtime():
|
|
from sglang.jit_kernel.triton_store_cache import triton_fused_store_cache
|
|
|
|
triton_fused_store_cache(input, cache, indices, page_size=page_size, type=type)
|
|
else:
|
|
module = _jit_fused_store_module(
|
|
name=type,
|
|
input_dtype=input.dtype,
|
|
index_dtype=indices.dtype,
|
|
page_size=page_size,
|
|
)
|
|
module.run(input, cache, indices)
|
|
|
|
|
|
@triton.jit
|
|
def create_paged_compress_data_kernel(
|
|
req_pool_indices_ptr,
|
|
seq_lens_ptr,
|
|
extend_seq_lens_ptr,
|
|
req_to_token_ptr,
|
|
full_to_swa_index_mapping_ptr,
|
|
out_0_ptr,
|
|
out_1_ptr,
|
|
batch_size,
|
|
stride_req_to_token_0,
|
|
stride_req_to_token_1: tl.constexpr,
|
|
stride_out_1_0,
|
|
stride_out_1_1: tl.constexpr,
|
|
compress_ratio: tl.constexpr,
|
|
is_overlap: tl.constexpr,
|
|
swa_page_size: tl.constexpr,
|
|
ring_size: tl.constexpr,
|
|
BLOCK: tl.constexpr,
|
|
) -> None:
|
|
pid = tl.program_id(0)
|
|
offs = pid * BLOCK + tl.arange(0, BLOCK)
|
|
mask = offs < batch_size
|
|
|
|
rid = tl.load(req_pool_indices_ptr + offs, mask=mask, other=0).to(tl.int32)
|
|
seq_len = tl.load(seq_lens_ptr + offs, mask=mask, other=0).to(tl.int32)
|
|
extend_len = tl.load(extend_seq_lens_ptr + offs, mask=mask, other=0).to(tl.int32)
|
|
prefix_len = seq_len - extend_len
|
|
|
|
cr = compress_ratio
|
|
write_pos = ((seq_len - 1) // cr) * cr
|
|
load_pos = ((prefix_len - 1) // cr) * cr
|
|
write_overlap_pos = write_pos - cr
|
|
load_overlap_pos = load_pos - cr
|
|
v0 = tl.zeros([BLOCK], tl.int32)
|
|
v1 = tl.zeros([BLOCK], tl.int32)
|
|
v2 = tl.zeros([BLOCK], tl.int32)
|
|
v3 = tl.zeros([BLOCK], tl.int32)
|
|
|
|
for i in tl.static_range(4):
|
|
if i == 0:
|
|
pos = load_pos
|
|
elif i == 1:
|
|
pos = write_pos
|
|
elif i == 2:
|
|
pos = load_overlap_pos
|
|
else:
|
|
pos = write_overlap_pos
|
|
pos = tl.maximum(pos, 0)
|
|
if compress_ratio == 128:
|
|
state_loc = rid * ring_size + (pos % ring_size)
|
|
else:
|
|
loc = tl.load(
|
|
req_to_token_ptr
|
|
+ rid.to(tl.int64) * stride_req_to_token_0
|
|
+ pos.to(tl.int64) * stride_req_to_token_1,
|
|
mask=mask,
|
|
other=0,
|
|
).to(tl.int32)
|
|
swa_loc = tl.load(
|
|
full_to_swa_index_mapping_ptr + loc, mask=mask, other=0
|
|
).to(tl.int32)
|
|
swa_page = swa_loc // swa_page_size
|
|
state_loc = swa_page * ring_size + (swa_loc % ring_size)
|
|
state_loc = state_loc // cr
|
|
if i == 0:
|
|
v0 = state_loc
|
|
elif i == 1:
|
|
v1 = state_loc
|
|
elif i == 2:
|
|
v2 = state_loc
|
|
else:
|
|
v3 = state_loc
|
|
|
|
tl.store(out_0_ptr + offs, v1, mask=mask)
|
|
|
|
if is_overlap:
|
|
base = out_1_ptr + offs * stride_out_1_0
|
|
tl.store(base + 0 * stride_out_1_1, v2, mask=mask)
|
|
tl.store(base + 1 * stride_out_1_1, v0, mask=mask)
|
|
tl.store(base + 2 * stride_out_1_1, v3, mask=mask)
|
|
tl.store(base + 3 * stride_out_1_1, write_pos.to(tl.int32), mask=mask)
|
|
else:
|
|
base = out_1_ptr + offs * stride_out_1_0
|
|
tl.store(base + 0 * stride_out_1_1, v0, mask=mask)
|
|
|
|
|
|
def triton_create_paged_compress_data(
|
|
*,
|
|
compress_ratio: int,
|
|
is_overlap: bool,
|
|
swa_page_size: int,
|
|
ring_size: int,
|
|
req_pool_indices: torch.Tensor,
|
|
seq_lens: torch.Tensor,
|
|
extend_seq_lens: torch.Tensor,
|
|
req_to_token: torch.Tensor,
|
|
full_to_swa_index_mapping: torch.Tensor,
|
|
block: int = 128,
|
|
) -> Tuple[torch.Tensor, torch.Tensor]:
|
|
batch_size = req_pool_indices.shape[0]
|
|
out_dim = 4 if is_overlap else 1
|
|
device_args: dict = dict(device=req_pool_indices.device, dtype=torch.int32)
|
|
out_0 = torch.empty((batch_size,), **device_args)
|
|
out_1 = torch.empty((batch_size, out_dim), **device_args)
|
|
grid = (triton.cdiv(batch_size, block),)
|
|
create_paged_compress_data_kernel[grid](
|
|
req_pool_indices,
|
|
seq_lens,
|
|
extend_seq_lens,
|
|
req_to_token,
|
|
full_to_swa_index_mapping,
|
|
out_0,
|
|
out_1,
|
|
batch_size=batch_size,
|
|
stride_req_to_token_0=req_to_token.stride(0),
|
|
stride_req_to_token_1=req_to_token.stride(1), # type: ignore
|
|
stride_out_1_0=out_1.stride(0),
|
|
stride_out_1_1=out_1.stride(1), # type: ignore
|
|
compress_ratio=compress_ratio, # type: ignore
|
|
is_overlap=1 if is_overlap else 0, # type: ignore
|
|
swa_page_size=swa_page_size, # type: ignore
|
|
ring_size=ring_size, # type: ignore
|
|
BLOCK=block, # type: ignore
|
|
)
|
|
|
|
if not is_overlap:
|
|
out_1.squeeze_(1)
|
|
return out_0, out_1
|