Deepseekv32 compatibility with transformers v5 (#18297)

Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com>
Co-authored-by: Baizhou Zhang <sobereddiezhang@gmail.com>
This commit is contained in:
Xinyuan Tong
2026-02-10 14:50:40 +08:00
committed by GitHub
co-authored by Xiaoyu Zhang Baizhou Zhang
parent 0b15f19927
commit e8a2c13380
5 changed files with 33 additions and 19 deletions
+13 -14
View File
@@ -438,23 +438,22 @@ class ModelConfig:
if is_deepseek_nsa(self.hf_text_config)
else None
)
if "Glm4MoeLiteForCausalLM" in self.hf_config.architectures:
self.scaling = 1
self.hf_config.rope_scaling = None
else:
# Handle rope scaling with yarn
self.scaling = 1 / math.sqrt(
self.qk_nope_head_dim + self.qk_rope_head_dim
# Handle rope scaling
self.scaling = 1 / math.sqrt(self.qk_nope_head_dim + self.qk_rope_head_dim)
# in transformers v5, rope_scaling is just rope_parameters for backward compatibility
rope_scaling = self.hf_text_config.rope_scaling
if rope_scaling:
# v5 uses "rope_type", v4 uses "type"
rope_type = (
rope_scaling.get("rope_type")
or rope_scaling.get("type")
or "default"
)
if self.hf_text_config.rope_scaling:
mscale_all_dim = self.hf_text_config.rope_scaling.get(
"mscale_all_dim", False
)
scaling_factor = self.hf_text_config.rope_scaling["factor"]
if rope_type != "default":
mscale_all_dim = rope_scaling.get("mscale_all_dim", False)
scaling_factor = rope_scaling["factor"]
mscale = yarn_get_mscale(scaling_factor, float(mscale_all_dim))
self.scaling = self.scaling * mscale * mscale
elif "MiniCPM3ForCausalLM" in self.hf_config.architectures:
self.head_dim = 128
self.attention_arch = AttentionArch.MLA