[New model] Kimi K3 (#50000)
Signed-off-by: zjy0516 <riverclouds.zhu@qq.com> Signed-off-by: Isotr0py <Isotr0py@outlook.com> Signed-off-by: Bugen Zhao <i@bugenzhao.com> Signed-off-by: Jee Jee Li <jeejeelee@inferact.ai> Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai> Signed-off-by: Yongye Zhu <zyy1102000@gmail.com> Signed-off-by: wzhao18 <wzhao18.sz@gmail.com> Co-authored-by: Isotr0py <Isotr0py@outlook.com> Co-authored-by: Thien Tran <gau.nernst@yahoo.com.sg> Co-authored-by: Bugen Zhao <i@bugenzhao.com> Co-authored-by: Yongye Zhu <zyy1102000@gmail.com> Co-authored-by: Ziming Huang <zelda.huanghuang@gmail.com> Co-authored-by: Roger Wang <hey@rogerw.io> Co-authored-by: Isotr0py <mozf@inferact.ai> Co-authored-by: aoshen02 <aoshen02@users.noreply.github.com> Co-authored-by: Woosuk Kwon <woosuk@inferact.ai> Co-authored-by: Jee Jee Li <jeejeelee@inferact.ai> Co-authored-by: aoshen02 <aoshen@inferact.ai> Co-authored-by: Summer Yang <girasoleyang@gmail.com> Co-authored-by: Kevin H. Luu <khluu000@gmail.com> Co-authored-by: Bowen Wang <abmfy@icloud.com> Co-authored-by: gnovack <novackgm@gmail.com> Co-authored-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai> Co-authored-by: xiaozhoupy <peiyuanzhou1994@gmail.com> Co-authored-by: Roy Wang <yasong.wang@inferact.ai> Co-authored-by: Jeff (Junze) Ma <93145857+majunze2001@users.noreply.github.com> Co-authored-by: Codex <codex@openai.com> Co-authored-by: Wei Zhao <51183510+wzhao18@users.noreply.github.com>
This commit is contained in:
co-authored by
Isotr0py
Thien Tran
Bugen Zhao
Yongye Zhu
Ziming Huang
Roger Wang
Isotr0py
aoshen02
Woosuk Kwon
Jee Jee Li
aoshen02
Summer Yang
Kevin H. Luu
Bowen Wang
gnovack
Nick Hill
Yifan Qiao
xiaozhoupy
Roy Wang
Jeff Ma
Codex
Wei Zhao
parent
0c64be8873
commit
aeeb36b1f1
@@ -87,6 +87,7 @@ _CONFIG_REGISTRY: dict[str, type[PretrainedConfig]] = LazyConfigDict(
|
||||
deepseek_vl_v2="DeepseekVLV2Config",
|
||||
deepseek_v32="DeepseekV3Config",
|
||||
deepseek_v4="DeepseekV4Config",
|
||||
k3_dspark="K3DSparkConfig",
|
||||
flex_olmo="FlexOlmoConfig",
|
||||
fireredlid="FireRedLIDConfig",
|
||||
funaudiochat="FunAudioChatConfig",
|
||||
@@ -100,6 +101,7 @@ _CONFIG_REGISTRY: dict[str, type[PretrainedConfig]] = LazyConfigDict(
|
||||
kimi_linear="KimiLinearConfig",
|
||||
kimi_vl="KimiVLConfig",
|
||||
kimi_k25="KimiK25Config",
|
||||
kimi_k3="KimiK3Config",
|
||||
RefinedWeb="RWConfig", # For tiiuae/falcon-40b(-instruct)
|
||||
RefinedWebModel="RWConfig", # For tiiuae/falcon-7b(-instruct)
|
||||
mlp_speculator="MLPSpeculatorConfig",
|
||||
|
||||
@@ -35,6 +35,7 @@ _CLASS_TO_MODULE: dict[str, str] = {
|
||||
"DiffusionGemmaTextConfig": "vllm.transformers_utils.configs.diffusion_gemma",
|
||||
"DeepseekVLV2Config": "vllm.transformers_utils.configs.deepseek_vl2",
|
||||
"DeepseekV4Config": "vllm.transformers_utils.configs.deepseek_v4",
|
||||
"K3DSparkConfig": "vllm.transformers_utils.configs.k3_dspark",
|
||||
"DotsOCRConfig": "vllm.transformers_utils.configs.dotsocr",
|
||||
"EAGLEConfig": "vllm.transformers_utils.configs.eagle",
|
||||
"FireRedLIDConfig": "vllm.transformers_utils.configs.fireredlid",
|
||||
@@ -72,6 +73,8 @@ _CLASS_TO_MODULE: dict[str, str] = {
|
||||
"KimiLinearConfig": "vllm.transformers_utils.configs.kimi_linear",
|
||||
"KimiVLConfig": "vllm.transformers_utils.configs.kimi_vl",
|
||||
"KimiK25Config": "vllm.transformers_utils.configs.kimi_k25",
|
||||
"KimiK3Config": "vllm.transformers_utils.configs.kimi_k3",
|
||||
"KimiK3VisionConfig": "vllm.transformers_utils.configs.kimi_k3",
|
||||
"NemotronConfig": "vllm.transformers_utils.configs.nemotron",
|
||||
"NemotronHConfig": "vllm.transformers_utils.configs.nemotron_h",
|
||||
"OlmoHybridConfig": "vllm.transformers_utils.configs.olmo_hybrid",
|
||||
@@ -124,6 +127,7 @@ __all__ = [
|
||||
"DeepseekVLV2Config",
|
||||
"DeepseekV3Config",
|
||||
"DeepseekV4Config",
|
||||
"K3DSparkConfig",
|
||||
"DotsOCRConfig",
|
||||
"EAGLEConfig",
|
||||
"FlexOlmoConfig",
|
||||
@@ -156,6 +160,8 @@ __all__ = [
|
||||
"KimiLinearConfig",
|
||||
"KimiVLConfig",
|
||||
"KimiK25Config",
|
||||
"KimiK3Config",
|
||||
"KimiK3VisionConfig",
|
||||
"NemotronConfig",
|
||||
"NemotronHConfig",
|
||||
"OlmoHybridConfig",
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from transformers import DeepseekV2Config
|
||||
|
||||
|
||||
class K3DSparkConfig(DeepseekV2Config):
|
||||
"""Configuration for a dense MLA DSpark draft model."""
|
||||
|
||||
model_type = "k3_dspark"
|
||||
has_no_defaults_at_init = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
mla_use_nope: bool = False,
|
||||
mla_use_output_gate: bool = False,
|
||||
mla_use_qk_norm: bool = False,
|
||||
rope_theta: float = 50000.0,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
# DeepseekV2Config defaults to a MoE topology. Zero these fields so
|
||||
# generic vLLM config logic also recognizes this draft as dense.
|
||||
kwargs.setdefault("n_routed_experts", 0)
|
||||
kwargs.setdefault("n_shared_experts", 0)
|
||||
kwargs.setdefault("num_experts_per_tok", 0)
|
||||
|
||||
rope_parameters = kwargs.get("rope_parameters")
|
||||
if rope_parameters is None:
|
||||
kwargs["rope_parameters"] = {
|
||||
"rope_type": "default",
|
||||
"rope_theta": rope_theta,
|
||||
}
|
||||
else:
|
||||
rope_parameters = dict(rope_parameters)
|
||||
rope_parameters.setdefault("rope_type", "default")
|
||||
rope_parameters.setdefault("rope_theta", rope_theta)
|
||||
kwargs["rope_parameters"] = rope_parameters
|
||||
|
||||
super().__init__(**kwargs)
|
||||
self.mla_use_nope = mla_use_nope
|
||||
self.mla_use_output_gate = mla_use_output_gate
|
||||
self.mla_use_qk_norm = mla_use_qk_norm
|
||||
|
||||
unsupported = [
|
||||
name
|
||||
for name in (
|
||||
"mla_use_nope",
|
||||
"mla_use_output_gate",
|
||||
"mla_use_qk_norm",
|
||||
"dspark_bonus_anchor",
|
||||
)
|
||||
if getattr(self, name, False)
|
||||
]
|
||||
if self.q_lora_rank is None:
|
||||
unsupported.append("q_lora_rank=None")
|
||||
if unsupported:
|
||||
raise ValueError(
|
||||
"MLA DSpark does not support " + ", ".join(unsupported) + "."
|
||||
)
|
||||
|
||||
self.draft_vocab_size = (
|
||||
getattr(self, "draft_vocab_size", None) or self.vocab_size
|
||||
)
|
||||
if self.draft_vocab_size != self.vocab_size:
|
||||
raise ValueError(
|
||||
"MLA DSpark requires draft_vocab_size to equal vocab_size when "
|
||||
"sharing the target embedding and LM head."
|
||||
)
|
||||
|
||||
target_layer_ids = getattr(self, "target_layer_ids", None)
|
||||
if not target_layer_ids or getattr(self, "num_target_layers", None) != len(
|
||||
target_layer_ids
|
||||
):
|
||||
raise ValueError(
|
||||
"MLA DSpark requires non-empty target_layer_ids and a matching "
|
||||
"num_target_layers."
|
||||
)
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
|
||||
from vllm.logger import init_logger
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
class KimiLinearConfig(PretrainedConfig):
|
||||
model_type = "kimi_linear"
|
||||
@@ -49,8 +45,16 @@ class KimiLinearConfig(PretrainedConfig):
|
||||
qk_rope_head_dim: int | None = None,
|
||||
v_head_dim: int | None = None,
|
||||
mla_use_nope: bool | None = False,
|
||||
mla_use_output_gate: bool | None = False,
|
||||
num_nextn_predict_layers: int = 0,
|
||||
linear_attn_config: dict | None = None,
|
||||
attn_res_block_size: int | None = None,
|
||||
latent_moe_use_norm: bool = False,
|
||||
activation_situ_beta: float | None = None,
|
||||
activation_situ_linear_beta: float | None = None,
|
||||
max_position_embeddings: int = 4096,
|
||||
routed_expert_hidden_size: int | None = None,
|
||||
topk_method: str = "noaux_tc",
|
||||
**kwargs,
|
||||
):
|
||||
self.model_type = model_type
|
||||
@@ -86,6 +90,7 @@ class KimiLinearConfig(PretrainedConfig):
|
||||
self.qk_rope_head_dim = qk_rope_head_dim
|
||||
self.v_head_dim = v_head_dim
|
||||
self.mla_use_nope = mla_use_nope
|
||||
self.mla_use_output_gate = mla_use_output_gate
|
||||
# moe config
|
||||
self.num_experts = num_experts
|
||||
self.num_experts_per_token = num_experts_per_token
|
||||
@@ -102,6 +107,14 @@ class KimiLinearConfig(PretrainedConfig):
|
||||
self.topk_group = topk_group
|
||||
self.num_nextn_predict_layers = num_nextn_predict_layers
|
||||
|
||||
self.attn_res_block_size = attn_res_block_size
|
||||
self.latent_moe_use_norm = latent_moe_use_norm
|
||||
self.activation_situ_beta = activation_situ_beta
|
||||
self.activation_situ_linear_beta = activation_situ_linear_beta
|
||||
self.max_position_embeddings = max_position_embeddings
|
||||
self.routed_expert_hidden_size = routed_expert_hidden_size
|
||||
self.topk_method = topk_method
|
||||
|
||||
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
|
||||
|
||||
@@ -267,6 +267,7 @@ class ModelArchConfigConvertorBase:
|
||||
"deepseek_v32",
|
||||
"deepseek_v4",
|
||||
"deepseek_mtp",
|
||||
"k3_dspark",
|
||||
"glm_moe_dsa",
|
||||
"glm4_moe_lite",
|
||||
"glm4_moe_lite_mtp",
|
||||
|
||||
@@ -27,6 +27,7 @@ __all__ = [
|
||||
"IsaacProcessor",
|
||||
"KimiAudioProcessor",
|
||||
"KimiK25Processor",
|
||||
"KimiK3Processor",
|
||||
"MiMoOmniProcessor",
|
||||
"MiniCPMOProcessor",
|
||||
"MiniCPMVProcessor",
|
||||
@@ -65,6 +66,7 @@ _CLASS_TO_MODULE: dict[str, str] = {
|
||||
"IsaacProcessor": "vllm.transformers_utils.processors.isaac",
|
||||
"KimiAudioProcessor": "vllm.transformers_utils.processors.kimi_audio",
|
||||
"KimiK25Processor": "vllm.transformers_utils.processors.kimi_k25",
|
||||
"KimiK3Processor": "vllm.transformers_utils.processors.kimi_k3",
|
||||
"MiMoOmniProcessor": "vllm.transformers_utils.processors.mimo_v2_omni",
|
||||
"MiniCPMOProcessor": "vllm.transformers_utils.processors.minicpmo",
|
||||
"MiniCPMVProcessor": "vllm.transformers_utils.processors.minicpmv",
|
||||
|
||||
Reference in New Issue
Block a user