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
164 lines
5.9 KiB
Python
164 lines
5.9 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
# Adapted from: https://github.com/vllm-project/vllm/blob/0384aa7150c4c9778efca041ffd1beb3ad2bd694/vllm/transformers_utils/configs/kimi_linear.py
|
|
from transformers.configuration_utils import PretrainedConfig
|
|
|
|
from sglang.srt.configs.mamba_utils import KimiLinearCacheParams, KimiLinearStateShape
|
|
from sglang.srt.runtime_context import get_parallel
|
|
|
|
|
|
class KimiLinearConfig(PretrainedConfig):
|
|
model_type = "kimi_linear"
|
|
keys_to_ignore_at_inference = ["past_key_values"]
|
|
|
|
def __init__(
|
|
self,
|
|
model_type="kimi_linear",
|
|
vocab_size=163840,
|
|
hidden_size=4096,
|
|
head_dim=None,
|
|
intermediate_size=11008,
|
|
num_hidden_layers=32,
|
|
num_attention_heads=32,
|
|
num_key_value_heads=None,
|
|
hidden_act="silu",
|
|
initializer_range=0.02,
|
|
rms_norm_eps=1e-6,
|
|
use_cache=True,
|
|
pad_token_id=0,
|
|
bos_token_id=1,
|
|
eos_token_id=2,
|
|
rope_theta=10000.0,
|
|
rope_scaling=None,
|
|
tie_word_embeddings=False,
|
|
moe_intermediate_size: int | None = None,
|
|
moe_renormalize: bool = True,
|
|
moe_router_activation_func: str = "sigmoid",
|
|
num_experts: int | None = None,
|
|
num_experts_per_token: int | None = None,
|
|
num_shared_experts: int = 0,
|
|
routed_scaling_factor: float = 1.0,
|
|
first_k_dense_replace: int = 0,
|
|
moe_layer_freq: int = 1,
|
|
use_grouped_topk: bool = True,
|
|
num_expert_group: int = 1,
|
|
topk_group: int = 1,
|
|
q_lora_rank: int | None = None,
|
|
kv_lora_rank: int | None = None,
|
|
qk_nope_head_dim: int | None = None,
|
|
qk_rope_head_dim: int | None = None,
|
|
v_head_dim: int | None = None,
|
|
mla_use_nope: bool | None = False,
|
|
num_nextn_predict_layers: int = 0,
|
|
linear_attn_config: dict | None = None,
|
|
**kwargs,
|
|
):
|
|
self.model_type = model_type
|
|
self.vocab_size = vocab_size
|
|
self.hidden_size = hidden_size
|
|
self.head_dim = (
|
|
head_dim if head_dim is not None else hidden_size // num_attention_heads
|
|
)
|
|
self.intermediate_size = intermediate_size
|
|
self.num_hidden_layers = num_hidden_layers
|
|
self.num_attention_heads = num_attention_heads
|
|
|
|
# for backward compatibility
|
|
if num_key_value_heads is None:
|
|
num_key_value_heads = num_attention_heads
|
|
|
|
self.num_key_value_heads = num_key_value_heads
|
|
self.hidden_act = hidden_act
|
|
self.initializer_range = initializer_range
|
|
self.rms_norm_eps = rms_norm_eps
|
|
self.use_cache = use_cache
|
|
self.rope_theta = rope_theta
|
|
self.rope_scaling = rope_scaling
|
|
|
|
self.q_lora_rank = q_lora_rank
|
|
self.kv_lora_rank = kv_lora_rank
|
|
self.qk_nope_head_dim = qk_nope_head_dim
|
|
self.qk_rope_head_dim = qk_rope_head_dim
|
|
self.v_head_dim = v_head_dim
|
|
self.mla_use_nope = mla_use_nope
|
|
# moe config
|
|
self.n_routed_experts = self.num_experts = num_experts
|
|
self.num_experts_per_token = num_experts_per_token
|
|
self.moe_renormalize = moe_renormalize
|
|
self.num_shared_experts = num_shared_experts
|
|
self.routed_scaling_factor = routed_scaling_factor
|
|
self.moe_router_activation_func = moe_router_activation_func
|
|
assert self.moe_router_activation_func in ("softmax", "sigmoid")
|
|
self.moe_intermediate_size = moe_intermediate_size
|
|
self.first_k_dense_replace = first_k_dense_replace
|
|
self.moe_layer_freq = moe_layer_freq
|
|
self.use_grouped_topk = use_grouped_topk
|
|
self.num_expert_group = num_expert_group
|
|
self.topk_group = topk_group
|
|
self.num_nextn_predict_layers = num_nextn_predict_layers
|
|
|
|
if linear_attn_config is not None:
|
|
assert linear_attn_config["kda_layers"] is not None
|
|
assert linear_attn_config["full_attn_layers"] is not None
|
|
self.linear_attn_config = linear_attn_config
|
|
|
|
super().__init__(
|
|
pad_token_id=pad_token_id,
|
|
bos_token_id=bos_token_id,
|
|
eos_token_id=eos_token_id,
|
|
tie_word_embeddings=tie_word_embeddings,
|
|
**kwargs,
|
|
)
|
|
|
|
@property
|
|
def is_mla(self):
|
|
return (
|
|
self.q_lora_rank is not None
|
|
or self.kv_lora_rank is not None
|
|
or self.qk_nope_head_dim is not None
|
|
or self.qk_rope_head_dim is not None
|
|
or self.v_head_dim is not None
|
|
or self.mla_use_nope is True
|
|
)
|
|
|
|
@property
|
|
def is_moe(self):
|
|
return self.num_experts is not None
|
|
|
|
@property
|
|
def is_linear_attn(self) -> bool:
|
|
return not (
|
|
self.linear_attn_config is None
|
|
or (
|
|
isinstance(self.linear_attn_config, dict)
|
|
and self.linear_attn_config["kda_layers"] is not None
|
|
and len(self.linear_attn_config["kda_layers"]) == 0
|
|
)
|
|
)
|
|
|
|
def is_kda_layer(self, layer_idx: int):
|
|
return (
|
|
self.linear_attn_config is not None
|
|
and (layer_idx + 1) in self.linear_attn_config["kda_layers"]
|
|
)
|
|
|
|
@property
|
|
def linear_layer_ids(self):
|
|
return [i for i in range(self.num_hidden_layers) if self.is_kda_layer(i)]
|
|
|
|
@property
|
|
def full_attention_layer_ids(self):
|
|
return [i for i in range(self.num_hidden_layers) if not self.is_kda_layer(i)]
|
|
|
|
@property
|
|
def mamba2_cache_params(self) -> KimiLinearCacheParams:
|
|
|
|
shape = KimiLinearStateShape.create(
|
|
tp_world_size=get_parallel().attn_tp_size,
|
|
num_heads=self.linear_attn_config["num_heads"],
|
|
head_dim=self.linear_attn_config["head_dim"],
|
|
conv_kernel_size=self.linear_attn_config["short_conv_kernel_size"],
|
|
)
|
|
|
|
return KimiLinearCacheParams(shape=shape, layers=self.linear_layer_ids)
|