chore: import upstream snapshot with attribution
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

This commit is contained in:
wehub-resource-sync
2026-07-13 12:38:16 +08:00
commit 94057c3d3e
7152 changed files with 2120455 additions and 0 deletions
@@ -0,0 +1,7 @@
from sgl_kernel.infllm_v2.attention import infllmv2_attn_stage1
from sgl_kernel.infllm_v2.max_pooling import max_pooling_1d_varlen
__all__ = [
"infllmv2_attn_stage1",
"max_pooling_1d_varlen",
]
@@ -0,0 +1,98 @@
"""Robust loader for the standalone ``infllm_ops`` pybind extension.
The InfLLM-V2 FlashAttention backend is built as its own module ``infllm_ops``
(installed into the ``sgl_kernel`` package directory). Under editable installs
the compiled ``.so`` may live in ``site-packages/sgl_kernel`` while the imported
``sgl_kernel`` package resolves to the source tree, so a plain ``from sgl_kernel
import infllm_ops`` is not always sufficient. This loader searches the known
candidate locations and loads the extension by file path.
"""
import glob
import importlib.util
import site
import sys
from pathlib import Path
from typing import List, Optional
_infllm_ops = None
def _candidate_dirs() -> List[Path]:
dirs: List[Path] = []
# 1) The directory of the sgl_kernel package as currently imported.
try:
import sgl_kernel
dirs.append(Path(sgl_kernel.__file__).parent)
except Exception:
pass
# 2) This module's parent package directory (source tree).
dirs.append(Path(__file__).resolve().parent.parent)
# 3) Every ``sgl_kernel`` directory found on the install paths.
search_roots: List[str] = []
try:
search_roots.extend(site.getsitepackages())
except Exception:
pass
try:
search_roots.append(site.getusersitepackages())
except Exception:
pass
search_roots.extend(p for p in sys.path if p)
for root in search_roots:
dirs.append(Path(root) / "sgl_kernel")
# De-duplicate while preserving order.
seen = set()
unique: List[Path] = []
for d in dirs:
key = str(d)
if key not in seen:
seen.add(key)
unique.append(d)
return unique
def _find_so() -> Optional[Path]:
for d in _candidate_dirs():
if not d.is_dir():
continue
matches = sorted(glob.glob(str(d / "infllm_ops*.so")))
if matches:
return Path(matches[0])
return None
def load_infllm_ops():
"""Import and return the ``infllm_ops`` extension module (cached)."""
global _infllm_ops
if _infllm_ops is not None:
return _infllm_ops
# Fast path: a normal import may already work.
try:
from sgl_kernel import infllm_ops as _mod # type: ignore
_infllm_ops = _mod
return _infllm_ops
except Exception:
pass
so_path = _find_so()
if so_path is None:
raise ImportError(
"[sgl_kernel] Could not locate the 'infllm_ops' extension (infllm_ops*.so). "
"Ensure sgl-kernel was built with the InfLLM-V2 FlashAttention backend."
)
spec = importlib.util.spec_from_file_location("infllm_ops", str(so_path))
if spec is None or spec.loader is None:
raise ImportError(f"[sgl_kernel] Could not create module spec for {so_path}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
_infllm_ops = module
return _infllm_ops
@@ -0,0 +1,82 @@
"""InfLLM-V2 sparse FlashAttention public API.
Ported (drop-in) from ``3rdparty/infllmv2_cuda_impl/infllm_v2/infllmv2_sparse_attention.py``.
The CUDA backend now lives in the standalone ``infllm_ops`` extension.
"""
import torch
from sgl_kernel.infllm_v2._loader import load_infllm_ops
def maybe_contiguous(x):
return x.contiguous() if x is not None and x.stride(-1) != 1 else x
def infllmv2_attn_stage1(
q,
k,
v,
cu_seqlens_q,
cu_seqlens_k,
cu_seqlens_v,
max_seqlen_q,
max_seqlen_k,
dropout_p=0.0,
softmax_scale=None,
causal=False,
window_size=(-1, -1),
softcap=0.0,
alibi_slopes=None,
deterministic=False,
return_attn_probs=True,
block_table=None,
):
"""Neighborhood Sparse Attention (NSA) Stage 1 with varlen support.
Drop-in replacement for ``infllm_v2.infllmv2_attn_stage1``. Returns the
attention-score matrix with the NSA sparsity pattern, shape
``(num_heads_k, total_q, max_seqlen_k)``.
"""
infllm_ops = load_infllm_ops()
if softmax_scale is None:
softmax_scale = q.shape[-1] ** (-0.5)
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
total_q, nheads, head_dim = q.shape
nheads_k = k.shape[1]
nheads_per_group = nheads // nheads_k
q = q.reshape(total_q, nheads_k, nheads_per_group, head_dim)
q = (
q.transpose(1, 2)
.reshape(total_q * nheads_per_group, nheads_k, head_dim)
.contiguous()
)
result = infllm_ops.varlen_fwd_stage1(
q,
k,
v,
None,
cu_seqlens_q,
cu_seqlens_k,
cu_seqlens_v,
None,
None,
block_table,
alibi_slopes,
max_seqlen_q,
max_seqlen_k,
dropout_p,
softmax_scale,
True,
causal,
window_size[0],
window_size[1],
softcap,
True,
None,
)
return result[0]
@@ -0,0 +1,61 @@
import torch
def max_pooling_1d_varlen(
input: torch.Tensor, # num_heads x total_q x max_k
cu_seqlens_q: torch.Tensor, # batch_size + 1
cu_seqlens_k: torch.Tensor, # batch_size + 1
cache_lens: torch.Tensor, # batch_size
max_seqlen_q: int,
max_context_len: int,
local_blocks: int,
init_blocks: int,
block_size: int = 64,
stride: int = 16,
total_q: int = -1,
) -> torch.Tensor:
"""Variable-length 1D max pooling over packed sequences.
Drop-in replacement for ``infllm_v2.max_pooling_1d_varlen``.
"""
assert input.dtype in (torch.float16, torch.bfloat16)
assert cu_seqlens_q.dtype == torch.int32
assert cu_seqlens_k.dtype == torch.int32
assert cache_lens.dtype == torch.int32
assert input.dim() == 3, f"Expected 3D input, got {input.dim()}D"
input = input.contiguous()
cu_seqlens_q = cu_seqlens_q.contiguous()
cu_seqlens_k = cu_seqlens_k.contiguous()
cache_lens = cache_lens.contiguous()
max_seqlen_k = max_context_len // stride
out_len = (max_context_len + block_size - 1) // block_size
stride = block_size // stride
kernel_size = stride + 1
padding = 1
num_heads = input.shape[0]
total_q = input.shape[1]
output = torch.zeros(
num_heads, total_q, out_len, device=input.device, dtype=input.dtype
)
torch.ops.sgl_kernel.infllm_v2_max_pooling_1d_varlen.default(
input,
output,
cu_seqlens_q,
cu_seqlens_k,
cache_lens,
max_seqlen_q,
max_seqlen_k,
kernel_size,
stride,
padding,
block_size,
local_blocks,
init_blocks,
total_q,
)
return output