repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_mxfp4_w4a8.py
.py
"""ModelSlim W4A8_MXFP scheme for pre-quantized weight inference on Ascend NPU (SRT). The msmodelslim ``W4A8_MXFP`` checkpoint stores weights as **packed FP4**: weight: uint8 (pack_fp4_to_uint8), shape [out, in//2], group_size=32 weight_scale: uint8 (UE8M0, +127 biased), shape [out, in//32] (verified...
108
4,499
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_scheme.py
.py
# Adapted from https://github.com/vllm-project/vllm/tree/main/vllm/model_executor/layers/quantization/compressed_tensors # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project from abc import abstractmethod from typing import Optional import torch from sglang.srt.l...
75
2,272
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w8a8_int8.py
.py
# Adapted from https://github.com/vllm-project/vllm/tree/main/vllm/model_executor/layers/quantization/compressed_tensors # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project from typing import Dict, List, Optional import torch from sglang.srt.hardware_backend.npu...
119
4,171
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w4a4_int4_moe.py
.py
from __future__ import annotations import logging from typing import Any, Dict import torch from sglang.srt.environ import envs from sglang.srt.hardware_backend.npu.quantization.moe_methods import ( NPUW4A4Int4MoEMethod, ) from sglang.srt.layers.quantization.modelslim.schemes import ModelSlimMoEScheme from sglan...
138
4,584
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_mxfp8.py
.py
"""ModelSlim MXFP8 scheme for pre-quantized weight inference on Ascend NPU (SRT). Loads weights pre-quantized by msmodelslim (float8_e4m3fn weights, uint8 scales) and runs MXFP8 matmul at inference. Following the modelslim-scheme convention (see ModelSlimW8A8Int8), this scheme owns only the hardware-agnostic weight c...
90
3,283
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_mxfp4.py
.py
"""ModelSlim W4A4_MXFP4 scheme for pre-quantized weight inference on Ascend NPU (SRT). The msmodelslim ``W4A4_MXFP4`` checkpoint stores weights as **packed FP4**: weight: uint8 shape [out, in//2] (two FP4 values per byte) weight_scale: uint8 (UE8M0) shape [out, in//32] (block scales, group_s...
99
3,697
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w4a4_int4.py
.py
# Adapted from https://github.com/vllm-project/vllm/tree/main/vllm/model_executor/layers/quantization/compressed_tensors # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project from typing import Any, Dict, List, Optional import torch from sglang.srt.environ import ...
114
4,306
sglang
python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_mxfp8_moe.py
.py
"""ModelSlim MXFP8 offline scheme for MoE layers on Ascend NPU (SRT). Loads weights pre-quantised by msmodelslim: float8_e4m3fn weights + uint8 block scales (block_size=32). The layout transform and the forward pass are delegated to ``NPUMXFP8MoEMethod`` -- the same kernel the online MXFP8 MoE path uses. """ from __f...
115
4,261
sglang
python/sglang/srt/layers/cp/utils.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
343
12,012
sglang
python/sglang/srt/layers/cp/__init__.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
56
1,678
sglang
python/sglang/srt/layers/cp/bcg.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
310
12,103
sglang
python/sglang/srt/layers/cp/padding.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
64
2,409
sglang
python/sglang/srt/layers/cp/cp_decode_attn_tp.py
.py
"""CP Decode Attention TP context. When CP (Context Parallel) mode sets tp_size=1 (repeat weights), decode can partition attention weights across CP ranks matching normal TP behavior. """ from __future__ import annotations import logging from contextlib import contextmanager from typing import TYPE_CHECKING, Dict, L...
214
8,551
sglang
python/sglang/srt/layers/cp/zigzag.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
479
18,496
sglang
python/sglang/srt/layers/cp/base.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
308
9,683
sglang
python/sglang/srt/layers/cp/interleave.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
273
10,207
sglang
python/sglang/srt/layers/rotary_embedding/utils.py
.py
"""Primitive rotary embedding ops: _rotate_neox, _rotate_gptj, _apply_rotary_emb, apply_rotary_pos_emb variants.""" from __future__ import annotations from typing import Tuple import torch from sglang.srt.utils import cpu_has_amx_support, get_compiler_backend, is_cpu, is_npu _is_npu = is_npu() _is_cpu = is_cpu() _...
147
4,113
sglang
python/sglang/srt/layers/rotary_embedding/rope_variant.py
.py
"""RoPE scaling variants: Phi3LongRoPE, FourierRoPE, DeepseekScaling, Llama3, Llama4Vision, DynamicNTK, DynamicNTKAlpha, DualChunkRotaryEmbedding.""" from __future__ import annotations import math from typing import List, Optional, Tuple, Union import torch import torch.nn as nn import torch.nn.functional as F from...
938
34,340
sglang
python/sglang/srt/layers/rotary_embedding/yarn.py
.py
"""YaRNScalingRotaryEmbedding + YaRN helper functions.""" from __future__ import annotations import math from typing import Tuple import torch from sglang.srt.layers.rotary_embedding.base import RotaryEmbedding # Inverse dim formula to find dim based on number of rotations def yarn_find_correction_dim( num_ro...
147
4,678
sglang
python/sglang/srt/layers/rotary_embedding/__init__.py
.py
# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project # Adapted from https://raw.githubusercontent.com/vllm-project/vllm/refs/tags/v0.6.6.post1/vllm/model_executor/layers/rotary_embedding.py """Rotary Positional Embeddings - public API (drop-in replacement for rotary...
34
1,218
sglang
python/sglang/srt/layers/rotary_embedding/factory.py
.py
"""Factory functions: get_rope, get_rope_cpu, get_rope_wrapper.""" from __future__ import annotations import logging from typing import Any, Dict, Optional, Tuple import torch from sglang.srt.layers.rotary_embedding.base import ( LinearScalingRotaryEmbedding, RotaryEmbedding, ) from sglang.srt.layers.rotary...
493
16,095
sglang
python/sglang/srt/layers/rotary_embedding/mrope_rope_index.py
.py
"""get_rope_index implementations for Qwen2-VL/Qwen3-VL, Qwen3-Omni, GLM4V, Ernie4.5.""" from __future__ import annotations import itertools from typing import Any, List, Optional, Tuple, Union import torch def _get_feat_extract_output_lengths(input_lengths): """ Computes the output length of the convoluti...
830
34,309
sglang
python/sglang/srt/layers/rotary_embedding/mrope.py
.py
"""MRotaryEmbedding, YaRNScalingMRotaryEmbedding, Ernie4_5_VLRotaryEmbedding, apply_interleaved_rope for multimodal RoPE.""" from __future__ import annotations from typing import List, Optional, Tuple import torch from sglang.kernels.ops.attention.rotary_triton import ( triton_ernie45_rope_fused_inplace, tr...
615
21,836
sglang
python/sglang/srt/layers/rotary_embedding/base.py
.py
"""RotaryEmbedding base class + LinearScalingRotaryEmbedding.""" from __future__ import annotations import logging from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union import torch from sglang.kernels.fused_op import BaseFusedOp from sglang.srt.environ import envs from sglang.srt.layers.rotary_embed...
571
21,501
sglang
python/sglang/srt/layers/moe/cutlass_moe.py
.py
"""CUTLASS based Fused MoE kernels.""" from typing import Optional, Tuple import torch from sglang.srt.utils import is_cuda, is_sm90_supported, is_sm100_supported _is_cuda = is_cuda() if _is_cuda: from sgl_kernel import ( apply_shuffle_mul_sum, es_fp8_blockwise_scaled_grouped_mm, es_sm10...
337
13,482
sglang
python/sglang/srt/layers/moe/utils.py
.py
from __future__ import annotations import logging import os from contextlib import contextmanager from enum import Enum, IntEnum from typing import TYPE_CHECKING import torch from sglang.srt.environ import envs from sglang.srt.layers.dp_attention import ( is_dp_attention_enabled, ) from sglang.srt.runtime_contex...
766
27,838
sglang
python/sglang/srt/layers/moe/flashinfer_trtllm_moe.py
.py
from typing import Optional import torch from sglang.srt.utils.custom_op import register_custom_op def _fake_fp8_block_scale_moe_out( routing_logits: torch.Tensor, routing_bias: Optional[torch.Tensor], hidden_states: torch.Tensor, hidden_states_scale: torch.Tensor, gemm1_weights: torch.Tensor, ...
324
11,001
sglang
python/sglang/srt/layers/moe/flashinfer_cutedsl_moe.py
.py
from typing import Optional import torch from flashinfer import ( scaled_fp4_grouped_quantize, silu_and_mul_scaled_nvfp4_experts_quantize, ) from flashinfer.cute_dsl.blockscaled_gemm import grouped_gemm_nt_masked def get_cute_dtype(input: torch.Tensor) -> str: if input.dtype == torch.bfloat16: re...
210
7,387
sglang
python/sglang/srt/layers/moe/mega_moe.py
.py
# Copyright 2023-2024 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
384
12,768
sglang
python/sglang/srt/layers/moe/__init__.py
.py
from sglang.srt.layers.moe.moe_runner import MoeRunner, MoeRunnerConfig from sglang.srt.layers.moe.utils import ( DeepEPMode, MoeA2ABackend, MoeRunnerBackend, get_deepep_config, get_deepep_mode, get_moe_a2a_backend, get_moe_runner_backend, get_tbo_token_distribution_threshold, initia...
37
1,007
sglang
python/sglang/srt/layers/moe/topk.py
.py
# Copyright 2024 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, so...
2,375
93,411
sglang
python/sglang/srt/layers/moe/hash_topk.py
.py
from __future__ import annotations import logging from typing import Optional, Tuple import torch from torch import nn from sglang.srt.environ import envs from sglang.srt.eplb.expert_distribution import ( get_global_expert_distribution_recorder, ) from sglang.srt.eplb.expert_location_dispatch import ( Expert...
276
10,780
sglang
python/sglang/srt/layers/moe/fused_moe_native.py
.py
""" Torch-native implementation for FusedMoE. This is used for torch.compile. It is based on https://github.com/pytorch-labs/gpt-fast/blob/32971d3129541c5bfb4f715abc33d1c5f408d204/mixtral-moe/model.py#L204 """ import torch from torch.nn import functional as F from sglang.srt.layers.activation import GeluAndMul, SiluA...
165
5,738
sglang
python/sglang/srt/layers/moe/cutlass_moe_params.py
.py
from dataclasses import dataclass from enum import Enum, auto from typing import Optional import torch class CutlassMoEType(Enum): """ Enum for the different types of cutlass moe operations that are currently supported in SGLang. """ BlockscaledFP8 = auto() BlockscaledFP4 = auto() @datacla...
188
7,226
sglang
python/sglang/srt/layers/moe/cutlass_w4a8_moe.py
.py
# SPDX-License-Identifier: Apache-2.0 """Cutlass W4A8 MoE kernel.""" from typing import Optional import torch from sglang.srt.runtime_context import get_parallel from sglang.srt.utils import is_cuda, is_cuda_alike _is_cuda = is_cuda() _is_cuda_alike = is_cuda_alike() if _is_cuda_alike: from sgl_kernel import (...
578
20,500
sglang
python/sglang/srt/layers/moe/kt_ep_wrapper.py
.py
# SPDX-License-Identifier: Apache-2.0 """ KT Expert Parallelism Wrapper for MoE layers. This module provides a generic wrapper that enables CPU-GPU expert parallelism for any MoE quantization method. It coordinates parallel execution of GPU experts (using any quantization method) and CPU experts (using AMX/AVX instruc...
394
14,240
sglang
python/sglang/srt/layers/moe/route_quant_handoff.py
.py
"""Attempt-and-verify handoff for the fused K3 MoE-front prep launch. At decode batch sizes the chain between the K3 fused-front GEMM and the trtllm-gen SiTU MoE op is three tiny back-to-back kernels on the critical path β€” route_radix (top-16 of 896), the triton ``(id << 16) | bf16(weight)`` pack, and per_token_group_...
131
4,575
sglang
python/sglang/srt/layers/moe/waterfill.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
293
10,932
sglang
python/sglang/srt/layers/moe/mega_moe_sm90.py
.py
# Copyright 2023-2024 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
180
5,891
sglang
python/sglang/srt/layers/moe/fused_moe_triton/layer.py
.py
# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project # Adapted from https://github.com/vllm-project/vllm/blob/a6221a144af772fd1a68fe7e627935dc53e81738/vllm/model_executor/layers/fused_moe/layer.py import logging from enum import Enum from functools import cached_pr...
1,743
67,984
sglang
python/sglang/srt/layers/moe/fused_moe_triton/__init__.py
.py
from sglang.srt.layers.moe.fused_moe_triton.layer import ( FusedMoE, FusedMoeWeightScaleSupported, ) from sglang.srt.layers.moe.moe_runner.triton_utils import ( fused_experts, get_config, get_config_file_name, moe_align_block_size, override_config, try_get_optimal_moe_config, ) __all__ ...
24
530
sglang
python/sglang/srt/layers/moe/fused_moe_triton/triton_kernels_moe.py
.py
# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project # Adapted from https://github.com/vllm-project/vllm/pull/18595/files#diff-f426a6de78c82ffec568eff6811bfbf0043dab5f87f1a8c0cffdbdcb8a81e035 from __future__ import annotations from typing import TYPE_CHECKING, Opt...
364
11,649
sglang
python/sglang/srt/layers/moe/fused_moe_triton/fused_marlin_moe.py
.py
from typing import Optional import torch import torch.nn.functional as F import triton import triton.language as tl from sglang.srt.layers import zero_copy_context from sglang.srt.utils import is_cuda from sglang.srt.utils.custom_op import register_custom_op _is_cuda = is_cuda() if _is_cuda: from sgl_kernel imp...
429
14,599
sglang
python/sglang/srt/layers/moe/ep_moe/layer.py
.py
from __future__ import annotations import logging from typing import TYPE_CHECKING, Any, Dict, Optional import torch from sglang.kernels.ops.quantization.fp8_kernel import is_fp8_fnuz from sglang.srt.environ import envs from sglang.srt.layers import deep_gemm_wrapper from sglang.srt.layers.dp_attention import ( ...
363
12,080
sglang
python/sglang/srt/layers/moe/dwdp/layout.py
.py
# Adapted from NVIDIA TensorRT-LLM (https://github.com/NVIDIA/TensorRT-LLM) """Expert ownership and page-aligned memory layout computation for DWDP.""" from __future__ import annotations import math from typing import Dict, List, Optional, Tuple import torch from sglang.srt.cuda_vmm_utils import align_down, align_u...
288
8,769
sglang
python/sglang/srt/layers/moe/dwdp/transport.py
.py
# Adapted from NVIDIA TensorRT-LLM (https://github.com/NVIDIA/TensorRT-LLM) """Cross-rank expert weight handle exchange (FABRIC or POSIX fd) and peer view import.""" from __future__ import annotations import logging import os from typing import Dict, List, Optional, Tuple import torch import torch.distributed as dis...
234
8,084
sglang
python/sglang/srt/layers/moe/dwdp/page_pool.py
.py
# Adapted from NVIDIA TensorRT-LLM (https://github.com/NVIDIA/TensorRT-LLM) """Double-buffered pool of local VMM pages backing the remote regions of the composite VA.""" from __future__ import annotations import logging from typing import Dict, List, Optional from cuda.bindings import driver as cuda from sglang.srt...
127
3,935
sglang
python/sglang/srt/layers/moe/dwdp/__init__.py
.py
"""DWDP (Distributed Weight Data Parallelism): MoE prefill with tokens kept on-rank and peer expert weights prefetched via NVLink into a composite VMM address space.""" from sglang.srt.layers.moe.dwdp.dwdp_manager import DwdpManager from sglang.srt.runtime_context import ( get_global_dwdp_manager, set_global_d...
14
431
sglang
python/sglang/srt/layers/moe/dwdp/weight_manager.py
.py
# Adapted from NVIDIA TensorRT-LLM (https://github.com/NVIDIA/TensorRT-LLM) """Double-buffered async prefetch of peer expert weights into the composite VA.""" from __future__ import annotations import bisect import logging from typing import Dict, List, Optional, Tuple import torch from sglang.srt.layers.moe.dwdp.l...
143
5,522
sglang
python/sglang/srt/layers/moe/dwdp/weight_buffer.py
.py
# Adapted from NVIDIA TensorRT-LLM (https://github.com/NVIDIA/TensorRT-LLM) """Composite VA presenting a contiguous full-expert weight tensor per (layer, weight).""" from __future__ import annotations import logging from typing import Dict, List, Optional, Tuple import torch from sglang.srt.cuda_vmm_utils import ( ...
215
7,396
sglang
python/sglang/srt/layers/moe/dwdp/dwdp_manager.py
.py
"""Global singleton orchestrating the DWDP lifecycle from setup(model) to cleanup().""" from __future__ import annotations import logging from typing import TYPE_CHECKING, Dict, List, Optional, Tuple import torch import torch.distributed as dist from torch import nn from sglang.srt.layers.moe.dwdp.layout import ( ...
212
7,983
sglang
python/sglang/srt/layers/moe/moe_runner/flashinfer_cutedsl.py
.py
from __future__ import annotations import logging from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Optional import torch from sglang.srt.environ import envs from sglang.srt.layers.moe.moe_runner.base import ( MoeQuantInfo, MoeRunnerConfig, register_fused_func, ) from sglang.srt.mo...
658
25,709
sglang
python/sglang/srt/layers/moe/moe_runner/marlin.py
.py
from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING, Optional import torch import triton import triton.language as tl from sglang.srt.layers.moe.moe_runner.base import ( MoeQuantInfo, MoeRunnerConfig, RunnerInput, RunnerOutput, register_fused_func...
219
7,703
sglang
python/sglang/srt/layers/moe/moe_runner/deep_gemm.py
.py
from __future__ import annotations import logging from dataclasses import dataclass from typing import TYPE_CHECKING, Any, List, Optional, Tuple import einops import torch import triton import triton.language as tl from sglang.kernels.ops.attention.dsv4 import silu_and_mul_masked_post_quant from sglang.kernels.ops.q...
1,451
52,700
sglang
python/sglang/srt/layers/moe/moe_runner/runner.py
.py
from __future__ import annotations import logging import os from typing import TYPE_CHECKING, Any, Optional from sglang.srt.layers.moe.moe_runner.base import ( FusedOpPool, MoeRunnerConfig, PermuteMethodPool, ) from sglang.srt.layers.moe.moe_runner.deep_gemm import DeepGemmRunnerCore from sglang.srt.layer...
220
9,498
sglang
python/sglang/srt/layers/moe/moe_runner/__init__.py
.py
from sglang.srt.layers.moe.moe_runner.base import MoeRunnerConfig from sglang.srt.layers.moe.moe_runner.runner import MoeRunner __all__ = ["MoeRunnerConfig", "MoeRunner"]
5
172
sglang
python/sglang/srt/layers/moe/moe_runner/ascend.py
.py
"""Ascend MoE runner backend with NPU‑specific ops.""" from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Optional import torch from sglang.srt.hardware_backend.npu.moe.activation import ( AllGatherActivationWrapper, NPUGeluAndMul, NPUSitu, NP...
351
12,006
sglang
python/sglang/srt/layers/moe/moe_runner/triton_kernels.py
.py
"""Triton kernels MoE runner backend skeleton.""" from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Optional import torch from sglang.srt.layers.moe.moe_runner.base import ( MoeQuantInfo, MoeRunnerConfig, MoeRunnerCore, RunnerInput, Runne...
208
6,811
sglang
python/sglang/srt/layers/moe/moe_runner/flashinfer_trtllm.py
.py
from __future__ import annotations import contextvars from contextlib import contextmanager from dataclasses import dataclass from typing import TYPE_CHECKING, Generator, Optional, cast import torch from torch.nn import Module from torch.nn.parameter import Parameter from sglang.kernels.ops.moe.pack_topk_ids import ...
1,386
53,711
sglang
python/sglang/srt/layers/moe/moe_runner/hpc_ops.py
.py
from __future__ import annotations """ MoE runner backend powered by HPC-Ops (https://github.com/Tencent/hpc-ops), a production-grade operator library for LLM inference developed by the Tencent Hunyuan AI Infra team. The backend wraps the monolithic FP8 fused-MoE kernels ``fuse_moe_blockwise`` (128x128 block-quantize...
209
7,936
sglang
python/sglang/srt/layers/moe/moe_runner/flashinfer_cutlass.py
.py
"""FlashInfer CUTLASS MoE fused funcs. This module owns the FlashInfer ``cutlass_fused_moe`` calls used by the unquantized, ModelOpt FP8, ModelOpt NVFP4, and MXFP4 MoE paths. Quantization methods prepare a small quant_info payload and route through ``MoeRunner``. """ from __future__ import annotations from dataclass...
399
14,142
sglang
python/sglang/srt/layers/moe/moe_runner/base.py
.py
from __future__ import annotations from abc import ABC, abstractmethod from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Callable, Optional, Tuple, TypeGuard import torch from sglang.srt.layers.moe.utils import ( MoeA2ABackend, MoeRunnerBackend, RoutingMethodType, ) if TYPE_CHECKI...
305
9,734
sglang
python/sglang/srt/layers/moe/moe_runner/triton.py
.py
from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING, Any, List, Optional import torch from sglang.srt.layers.moe.moe_runner.base import ( MoeQuantInfo, MoeRunnerConfig, MoeRunnerCore, RunnerInput, RunnerOutput, register_fused_func, registe...
336
11,729
sglang
python/sglang/srt/layers/moe/moe_runner/humming.py
.py
from __future__ import annotations import json import logging import math from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Optional from weakref import WeakValueDictionary import torch from sglang.kernels.ops.moe.ep_moe_kernels import moe_permute, moe_unpermute from sglang.kernels.ops.moe.moe...
818
28,473
sglang
python/sglang/srt/layers/moe/moe_runner/aiter.py
.py
from __future__ import annotations import functools import inspect from dataclasses import dataclass from enum import Enum from typing import TYPE_CHECKING, Any, Optional, Union import torch from sglang.srt.layers.moe.moe_runner.base import ( MoeQuantInfo, MoeRunnerConfig, MoeRunnerCore, RunnerInput,...
478
17,594
sglang
python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.py
.py
# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project # Adapted from https://github.com/vllm-project/vllm/blob/a6221a144af772fd1a68fe7e627935dc53e81738/vllm/model_executor/layers/fused_moe/fused_moe.py """Fused MoE kernel.""" from __future__ import annotations imp...
1,158
40,671
sglang
python/sglang/srt/layers/moe/moe_runner/triton_utils/moe_align_block_size.py
.py
from __future__ import annotations from typing import Tuple import torch import triton from sglang.srt.environ import envs from sglang.srt.utils import is_cuda, is_hip, is_musa, is_xpu _SGLANG_EXPERIMENTAL_LORA_OPTI = envs.SGLANG_EXPERIMENTAL_LORA_OPTI.get() _is_cuda = is_cuda() _is_hip = is_hip() _is_xpu = is_xpu...
163
5,943
sglang
python/sglang/srt/layers/moe/moe_runner/triton_utils/__init__.py
.py
from contextlib import contextmanager from typing import Any, Dict, Optional from sglang.srt.layers.moe.moe_runner.triton_utils.fused_moe import fused_experts from sglang.srt.layers.moe.moe_runner.triton_utils.fused_moe_triton_config import ( get_config_file_name, try_get_optimal_moe_config, ) from sglang.srt....
37
837
sglang
python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe_triton_config.py
.py
from __future__ import annotations import functools import json import logging import os from typing import Any, Dict, List, Optional, Tuple import torch import triton from sglang.srt.runtime_context import get_exec from sglang.srt.utils import get_device_name, is_hip logger = logging.getLogger(__name__) _is_hip = ...
363
12,850
sglang
python/sglang/srt/layers/moe/token_dispatcher/deepep.py
.py
from __future__ import annotations import logging from contextlib import nullcontext from dataclasses import dataclass from typing import TYPE_CHECKING, List, NamedTuple, Optional, Tuple, Union from sglang.srt.distributed.parallel_state import get_tp_group from sglang.srt.environ import envs from sglang.srt.eplb.expe...
1,027
35,126
sglang
python/sglang/srt/layers/moe/token_dispatcher/nixl.py
.py
from __future__ import annotations import logging from enum import Enum, auto import torch import torch.distributed as dist from sglang.srt.distributed.utils import get_global_tcp_store from sglang.srt.elastic_ep.elastic_ep import ElasticEPStateManager from sglang.srt.environ import envs from sglang.srt.eplb.expert_...
554
18,356
sglang
python/sglang/srt/layers/moe/token_dispatcher/ascend_tp.py
.py
from __future__ import annotations from typing import NamedTuple, Optional import torch from sglang.srt.hardware_backend.npu.moe.finalize_routing import ( AllGatherFinalizeRoutingWrapper, NPUFinalizeRouting, ) from sglang.srt.hardware_backend.npu.moe.init_routing import ( MXFP8_QUANT_MODE, NPUMoEInit...
144
5,129
sglang
python/sglang/srt/layers/moe/token_dispatcher/__init__.py
.py
from sglang.srt.layers.moe.token_dispatcher.ascend_tp import ( AscendTPCombineInput, AscendTPDispatcher, AscendTPDispatchOutput, ) from sglang.srt.layers.moe.token_dispatcher.base import ( BaseDispatcher, BaseDispatcherConfig, CombineInput, CombineInputChecker, CombineInputFormat, Di...
94
2,470
sglang
python/sglang/srt/layers/moe/token_dispatcher/mooncake.py
.py
from __future__ import annotations import logging from dataclasses import dataclass from enum import Enum, auto from typing import NamedTuple, Optional import torch import torch.distributed as dist from sglang.srt.elastic_ep.elastic_ep import ElasticEPStateManager from sglang.srt.eplb.expert_distribution import get_...
410
12,713
sglang
python/sglang/srt/layers/moe/token_dispatcher/flashinfer_utils.py
.py
import torch.distributed as dist from sglang.srt.utils import is_flashinfer_available if is_flashinfer_available(): from flashinfer.comm.mnnvl import CommBackend else: class CommBackend: """ Placeholder base class when flashinfer is not available """ pass class TorchDistrib...
48
1,265
sglang
python/sglang/srt/layers/moe/token_dispatcher/moriep.py
.py
from __future__ import annotations import logging import os from dataclasses import dataclass from typing import TYPE_CHECKING, List, NamedTuple, Optional, Tuple from sglang.srt.eplb.expert_distribution import ( _ExpertDistributionRecorderNoop, get_global_expert_distribution_recorder, ) from sglang.srt.layers...
1,180
40,512
sglang
python/sglang/srt/layers/moe/token_dispatcher/flashinfer.py
.py
from __future__ import annotations import logging from typing import NamedTuple, Optional import torch from sglang.kernel_api_logging import debug_kernel_api from sglang.srt.environ import envs from sglang.srt.layers.dp_attention import ( get_dp_global_num_tokens, is_dp_attention_enabled, ) from sglang.srt.l...
317
13,565
sglang
python/sglang/srt/layers/moe/token_dispatcher/pplx.py
.py
from __future__ import annotations from enum import Enum, auto from typing import NamedTuple, Optional, Tuple import torch import torch.distributed as dist from sglang.srt.environ import envs from sglang.srt.eplb.expert_distribution import get_global_expert_distribution_recorder from sglang.srt.layers.dp_attention i...
528
17,525
sglang
python/sglang/srt/layers/moe/token_dispatcher/base.py
.py
from __future__ import annotations import weakref from abc import ABC, abstractmethod from enum import Enum from typing import ( TYPE_CHECKING, Any, Callable, Optional, OrderedDict, Protocol, Tuple, TypeGuard, Union, runtime_checkable, ) import torch if TYPE_CHECKING: from...
392
12,449
sglang
python/sglang/srt/layers/moe/token_dispatcher/standard.py
.py
from __future__ import annotations from typing import TYPE_CHECKING, NamedTuple, Optional, Tuple import torch from sglang.srt.distributed import ( get_tp_group, ) from sglang.srt.distributed.device_communicators.pynccl_allocator import ( use_symmetric_memory, ) from sglang.srt.layers.dp_attention import ( ...
261
10,457
sglang
python/sglang/srt/layers/utils/cp_utils.py
.py
from dataclasses import dataclass from itertools import accumulate from typing import Callable, List import torch import torch.nn.functional as F from sglang.srt.distributed.device_communicators.pynccl_allocator import ( use_symmetric_memory, ) from sglang.srt.layers.dp_attention import ( attn_cp_all_gather_i...
676
24,929
sglang
python/sglang/srt/layers/utils/multi_platform.py
.py
"""Deprecated compatibility shim for the former ``MultiPlatformOp``. The multi-platform operator abstraction was unified into :class:`sglang.kernels.fused_op.BaseFusedOp` (RFC #29630): one class now covers kernel-backend selection (``forward_aot`` / ``forward_jit`` / ...), platform dispatch (``forward_cuda`` / ``forwa...
63
2,345
sglang
python/sglang/srt/layers/utils/common.py
.py
# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import logging import re import torch from torch.nn.parameter import Parameter logger = logging.getLogger(__name__) def get_layer_id(weight_name): # example weight name: model.layers.10.self_attn.qkv_proj....
128
4,584
sglang
python/sglang/srt/layers/deep_gemm_wrapper/entrypoint.py
.py
import logging from contextlib import contextmanager from typing import Any, Optional, Tuple import torch from sglang.srt.environ import envs from sglang.srt.layers.deep_gemm_wrapper import compile_utils from sglang.srt.layers.deep_gemm_wrapper.configurer import ( # noqa: F401 DEEPGEMM_BLACKWELL, DEEPGEMM_NE...
285
8,360
sglang
python/sglang/srt/layers/deep_gemm_wrapper/configurer.py
.py
import logging from sglang.srt.environ import envs from sglang.srt.utils import ( get_device_sm, is_cuda, is_musa, is_sm100_supported, ) logger = logging.getLogger(__name__) _is_cuda = is_cuda() _is_musa = is_musa() def _compute_enable_deep_gemm(): sm_version = get_device_sm() if (_is_cuda ...
40
959
sglang
python/sglang/srt/layers/deep_gemm_wrapper/compile_utils.py
.py
import logging import math import os import time from contextlib import contextmanager, nullcontext from enum import IntEnum, auto from typing import Dict, List, Tuple import torch from tqdm import tqdm from sglang.srt.distributed.device_communicators.pynccl_allocator import ( disable_symmetric_memory_context, ...
511
19,700
sglang
python/sglang/srt/layers/attention/aiter_backend.py
.py
from __future__ import annotations from sglang.srt.runtime_context import get_parallel, get_spec """ end to end attention solution with aiter kernels """ import logging from dataclasses import dataclass from enum import Enum, auto from typing import TYPE_CHECKING, Optional import torch import triton from sglang.ke...
2,990
120,413
sglang
python/sglang/srt/layers/attention/torch_flex_backend.py
.py
from __future__ import annotations from typing import TYPE_CHECKING import torch from torch.nn.attention.flex_attention import create_block_mask, flex_attention from sglang.srt.layers.attention.base_attn_backend import AttentionBackend from sglang.srt.layers.radix_attention import AttentionType from sglang.srt.model...
332
11,915
sglang
python/sglang/srt/layers/attention/aiter_utils.py
.py
"""SHUFFLE 5D KV pool helpers for the AITER attention backend. This module hosts the attention pathways that are specific to the ``SGLANG_AITER_KV_CACHE_LAYOUT=vectorized_5d`` (SHUFFLE 5D) physical layout. They live here rather than inline in :mod:`sglang.srt.layers.attention.aiter_backend` so the main backend file ke...
310
11,970
sglang
python/sglang/srt/layers/attention/dsa_backend.py
.py
from __future__ import annotations import logging from dataclasses import dataclass from typing import ( TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, TypeAlias, ) import torch from sglang.srt.configs.model_config import get_dsa_index_topk, is_deepseek_dsa from sglang.srt.runtime_c...
3,640
153,237
sglang
python/sglang/srt/layers/attention/intel_amx_backend.py
.py
from __future__ import annotations from typing import TYPE_CHECKING import torch from sglang.srt.layers.attention.base_attn_backend import AttentionBackend from sglang.srt.mem_cache.memory_pool import KVWriteLoc from sglang.srt.mem_cache.swa_memory_pool import SWAKVPool from sglang.srt.model_executor.forward_batch_i...
362
13,896
sglang
python/sglang/srt/layers/attention/cutlass_mla_backend.py
.py
from __future__ import annotations from sglang.srt.runtime_context import get_parallel """ Support attention backend for Cutlass MLA. """ from dataclasses import dataclass from typing import TYPE_CHECKING, Optional, Union import torch import triton from sglang.kernels.ops.attention.utils import ( create_flash...
251
8,708
sglang
python/sglang/srt/layers/attention/triton_backend.py
.py
from __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING, List, Optional import torch import triton from sglang.kernels.ops.attention.metadata import get_num_kv_splits_triton from sglang.kernels.ops.kvcache.kv_indices import ( create_flashinfer_kv_indices_triton, ) fr...
2,170
88,099
sglang
python/sglang/srt/layers/attention/index_topk_share.py
.py
from __future__ import annotations from contextlib import contextmanager from typing import TYPE_CHECKING, Iterator, Optional if TYPE_CHECKING: import torch from sglang.srt.model_executor.forward_batch_info import ForwardBatch class IndexTopKShareState: def __init__( self, forward_batch...
87
2,810
sglang
python/sglang/srt/layers/attention/deepseek_v4_backend.py
.py
from __future__ import annotations import enum import functools import logging from dataclasses import dataclass, field from typing import ( TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, TypeVar, Union, ) import torch import torch.nn.functional as F from sglang.kernels.ops.atte...
2,212
90,625
sglang
python/sglang/srt/layers/attention/merge_state.py
.py
from typing import Optional, Tuple import torch from sgl_kernel import merge_state_v2 from sglang.kernels.ops.attention.merge_state import merge_state_triton from sglang.srt.utils import is_cuda _is_cuda = is_cuda() # Automatically fallback to the Triton kernel in some cases # (e.g., for AMD GPUs, when the head di...
47
1,413
sglang
python/sglang/srt/layers/attention/xpu_backend.py
.py
from __future__ import annotations from typing import TYPE_CHECKING, Optional import torch from sglang.srt.configs.model_config import AttentionArch from sglang.srt.layers.attention.base_attn_backend import AttentionBackend from sglang.srt.layers.attention.flashattention_backend import ( FlashAttentionMetadata, ...
1,312
60,721
sglang
python/sglang/srt/layers/attention/trtllm_mha_backend.py
.py
from __future__ import annotations """ Support attention backend for TRTLLM MHA kernels from flashinfer. The kernel supports sm100 only, with sliding window and attention sink features. """ import logging from dataclasses import dataclass from typing import TYPE_CHECKING, Optional import torch from sglang.kernels.o...
1,476
62,369
sglang
python/sglang/srt/layers/attention/unified_mem_hooks.py
.py
# Copyright 2023-2026 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
71
2,666
sglang
python/sglang/srt/layers/attention/hybrid_linear_attn_backend.py
.py
from __future__ import annotations import logging from typing import TYPE_CHECKING, Optional, Union import torch from sglang.kernels.ops.mamba.causal_conv1d_triton import PAD_SLOT_ID from sglang.kernels.ops.mamba.mamba_state_indices_triton import ( fused_replay_state_indices, ) from sglang.kernels.ops.mamba.mamb...
1,281
58,018