Support GlmMoeDsaForCausalLM (#18521)
Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com> Signed-off-by: BBuf <1182563586@qq.com> Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com> Co-authored-by: BBuf <1182563586@qq.com>
This commit is contained in:
co-authored by
Xiaoyu Zhang
BBuf
parent
e8a2c13380
commit
398b81f78c
@@ -61,6 +61,7 @@ def is_deepseek_nsa(config: PretrainedConfig) -> bool:
|
|||||||
"DeepseekV3ForCausalLMNextN",
|
"DeepseekV3ForCausalLMNextN",
|
||||||
"MistralLarge3ForCausalLM",
|
"MistralLarge3ForCausalLM",
|
||||||
"PixtralForConditionalGeneration",
|
"PixtralForConditionalGeneration",
|
||||||
|
"GlmMoeDsaForCausalLM",
|
||||||
]
|
]
|
||||||
and getattr(config, "index_topk", None) is not None
|
and getattr(config, "index_topk", None) is not None
|
||||||
)
|
)
|
||||||
@@ -271,10 +272,10 @@ class ModelConfig:
|
|||||||
def _config_draft_model(self):
|
def _config_draft_model(self):
|
||||||
is_draft_model = self.is_draft_model
|
is_draft_model = self.is_draft_model
|
||||||
|
|
||||||
if (
|
if is_draft_model and self.hf_config.architectures[0] in [
|
||||||
is_draft_model
|
"DeepseekV3ForCausalLM",
|
||||||
and self.hf_config.architectures[0] == "DeepseekV3ForCausalLM"
|
"GlmMoeDsaForCausalLM",
|
||||||
):
|
]:
|
||||||
self.hf_config.architectures[0] = "DeepseekV3ForCausalLMNextN"
|
self.hf_config.architectures[0] = "DeepseekV3ForCausalLMNextN"
|
||||||
|
|
||||||
if is_draft_model and self.hf_config.architectures[0] in [
|
if is_draft_model and self.hf_config.architectures[0] in [
|
||||||
@@ -411,7 +412,6 @@ class ModelConfig:
|
|||||||
"swa_v_head_dim",
|
"swa_v_head_dim",
|
||||||
self.v_head_dim,
|
self.v_head_dim,
|
||||||
)
|
)
|
||||||
|
|
||||||
# FIXME: temporary special judge for MLA architecture
|
# FIXME: temporary special judge for MLA architecture
|
||||||
if (
|
if (
|
||||||
"DeepseekV2ForCausalLM" in self.hf_config.architectures
|
"DeepseekV2ForCausalLM" in self.hf_config.architectures
|
||||||
@@ -419,6 +419,7 @@ class ModelConfig:
|
|||||||
or "DeepseekV3ForCausalLM" in self.hf_config.architectures
|
or "DeepseekV3ForCausalLM" in self.hf_config.architectures
|
||||||
or "DeepseekV3ForCausalLMNextN" in self.hf_config.architectures
|
or "DeepseekV3ForCausalLMNextN" in self.hf_config.architectures
|
||||||
or "Glm4MoeLiteForCausalLM" in self.hf_config.architectures
|
or "Glm4MoeLiteForCausalLM" in self.hf_config.architectures
|
||||||
|
or "GlmMoeDsaForCausalLM" in self.hf_config.architectures
|
||||||
or "LongcatFlashForCausalLM" in self.hf_config.architectures
|
or "LongcatFlashForCausalLM" in self.hf_config.architectures
|
||||||
or "LongcatFlashForCausalLMNextN" in self.hf_config.architectures
|
or "LongcatFlashForCausalLMNextN" in self.hf_config.architectures
|
||||||
or "DotsVLMForCausalLM" in self.hf_config.architectures
|
or "DotsVLMForCausalLM" in self.hf_config.architectures
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ from sglang.srt.layers.vocab_parallel_embedding import (
|
|||||||
from sglang.srt.model_executor.cuda_graph_runner import get_is_capture_mode
|
from sglang.srt.model_executor.cuda_graph_runner import get_is_capture_mode
|
||||||
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, PPProxyTensors
|
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, PPProxyTensors
|
||||||
from sglang.srt.model_loader.weight_utils import default_weight_loader
|
from sglang.srt.model_loader.weight_utils import default_weight_loader
|
||||||
|
from sglang.srt.models.deepseek_v2 import DeepseekV2ForCausalLM
|
||||||
from sglang.srt.models.utils import apply_qk_norm
|
from sglang.srt.models.utils import apply_qk_norm
|
||||||
from sglang.srt.server_args import get_global_server_args
|
from sglang.srt.server_args import get_global_server_args
|
||||||
from sglang.srt.utils import (
|
from sglang.srt.utils import (
|
||||||
@@ -1279,4 +1280,8 @@ class Glm4MoeForCausalLM(nn.Module):
|
|||||||
self.model.layers_to_capture = [val + 1 for val in layer_ids]
|
self.model.layers_to_capture = [val + 1 for val in layer_ids]
|
||||||
|
|
||||||
|
|
||||||
EntryClass = [Glm4MoeForCausalLM]
|
class GlmMoeDsaForCausalLM(DeepseekV2ForCausalLM):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
EntryClass = [Glm4MoeForCausalLM, GlmMoeDsaForCausalLM]
|
||||||
|
|||||||
@@ -1194,9 +1194,15 @@ class ServerArgs:
|
|||||||
"KimiK25ForConditionalGeneration",
|
"KimiK25ForConditionalGeneration",
|
||||||
"MistralLarge3ForCausalLM",
|
"MistralLarge3ForCausalLM",
|
||||||
"PixtralForConditionalGeneration",
|
"PixtralForConditionalGeneration",
|
||||||
|
"GlmMoeDsaForCausalLM",
|
||||||
]:
|
]:
|
||||||
# Set attention backend for DeepSeek
|
# Set attention backend for DeepSeek
|
||||||
if is_deepseek_nsa(hf_config): # DeepSeek 3.2
|
if is_deepseek_nsa(hf_config): # DeepSeek 3.2, GlmMoeDsaForCausalLM
|
||||||
|
if model_arch == "GlmMoeDsaForCausalLM" and is_blackwell_supported():
|
||||||
|
envs.SGLANG_NSA_FORCE_MLA.set(True)
|
||||||
|
logger.warning(
|
||||||
|
"Force NSA prefill to use MLA (i.e. disable MHA_ONE_SHOT) for GlmMoeDsaForCausalLM on SM100."
|
||||||
|
)
|
||||||
if self.is_attention_backend_not_set():
|
if self.is_attention_backend_not_set():
|
||||||
self.attention_backend = "nsa"
|
self.attention_backend = "nsa"
|
||||||
logger.info("Use nsa attention backend for DeepSeek with DSA.")
|
logger.info("Use nsa attention backend for DeepSeek with DSA.")
|
||||||
@@ -2323,6 +2329,7 @@ class ServerArgs:
|
|||||||
"DeepseekV3ForCausalLM",
|
"DeepseekV3ForCausalLM",
|
||||||
"Glm4MoeForCausalLM",
|
"Glm4MoeForCausalLM",
|
||||||
"Glm4MoeLiteForCausalLM",
|
"Glm4MoeLiteForCausalLM",
|
||||||
|
"GlmMoeDsaForCausalLM",
|
||||||
"BailingMoeForCausalLM",
|
"BailingMoeForCausalLM",
|
||||||
"BailingMoeV2ForCausalLM",
|
"BailingMoeV2ForCausalLM",
|
||||||
"MistralLarge3ForCausalLM",
|
"MistralLarge3ForCausalLM",
|
||||||
@@ -2652,6 +2659,7 @@ class ServerArgs:
|
|||||||
"DeepseekV32ForCausalLM",
|
"DeepseekV32ForCausalLM",
|
||||||
"MistralLarge3ForCausalLM",
|
"MistralLarge3ForCausalLM",
|
||||||
"PixtralForConditionalGeneration",
|
"PixtralForConditionalGeneration",
|
||||||
|
"GlmMoeDsaForCausalLM",
|
||||||
]
|
]
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
@@ -5648,6 +5656,7 @@ def auto_choose_speculative_params(self: ServerArgs):
|
|||||||
"GptOssForCausalLM",
|
"GptOssForCausalLM",
|
||||||
"Glm4MoeForCausalLM",
|
"Glm4MoeForCausalLM",
|
||||||
"Glm4MoeLiteForCausalLM",
|
"Glm4MoeLiteForCausalLM",
|
||||||
|
"GlmMoeDsaForCausalLM",
|
||||||
"BailingMoeForCausalLM",
|
"BailingMoeForCausalLM",
|
||||||
"BailingMoeV2ForCausalLM",
|
"BailingMoeV2ForCausalLM",
|
||||||
"MistralLarge3ForCausalLM",
|
"MistralLarge3ForCausalLM",
|
||||||
|
|||||||
Reference in New Issue
Block a user