Upgrade transformers==5.3.0 (#17784)
Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com> Co-authored-by: Kangyan-Zhou <zky314343421@gmail.com> Co-authored-by: Alison Shao <alisonshao@mac.lan> Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
@@ -593,7 +593,6 @@ class InternLM2Tokenizer(PreTrainedTokenizer):
|
||||
current_sub_tokens.append(token)
|
||||
prev_is_special = False
|
||||
out_string += self.sp_model.decode(current_sub_tokens)
|
||||
out_string = self.clean_up_tokenization(out_string)
|
||||
out_string = self._maybe_add_prefix_space(tokens=tokens, decoded=out_string)
|
||||
return out_string[1:]
|
||||
|
||||
|
||||
@@ -51,10 +51,20 @@ class ModelImpl(str, Enum):
|
||||
MINDSPORE = "mindspore"
|
||||
|
||||
|
||||
def is_deepseek_nsa(config: PretrainedConfig) -> bool:
|
||||
def is_deepseek_nsa(config) -> bool:
|
||||
architectures = (
|
||||
config.get("architectures")
|
||||
if isinstance(config, dict)
|
||||
else getattr(config, "architectures", None)
|
||||
)
|
||||
index_topk = (
|
||||
config.get("index_topk")
|
||||
if isinstance(config, dict)
|
||||
else getattr(config, "index_topk", None)
|
||||
)
|
||||
return (
|
||||
config.architectures is not None
|
||||
and config.architectures[0]
|
||||
architectures is not None
|
||||
and architectures[0]
|
||||
in [
|
||||
"DeepseekV3ForCausalLM",
|
||||
"DeepseekV32ForCausalLM",
|
||||
@@ -63,7 +73,7 @@ def is_deepseek_nsa(config: PretrainedConfig) -> bool:
|
||||
"PixtralForConditionalGeneration",
|
||||
"GlmMoeDsaForCausalLM",
|
||||
]
|
||||
and getattr(config, "index_topk", None) is not None
|
||||
and index_topk is not None
|
||||
)
|
||||
|
||||
|
||||
@@ -457,10 +467,9 @@ class ModelConfig:
|
||||
or "default"
|
||||
)
|
||||
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
|
||||
self.scaling = compute_mla_mscale_scaling(
|
||||
rope_scaling, self.scaling
|
||||
)
|
||||
elif "MiniCPM3ForCausalLM" in self.hf_config.architectures:
|
||||
self.head_dim = 128
|
||||
self.attention_arch = AttentionArch.MLA
|
||||
@@ -501,12 +510,9 @@ class ModelConfig:
|
||||
# Handle rope scaling with yarn
|
||||
self.scaling = 1 / math.sqrt(self.qk_nope_head_dim + self.qk_rope_head_dim)
|
||||
if self.hf_config.rope_scaling:
|
||||
mscale_all_dim = self.hf_config.rope_scaling.get(
|
||||
"mscale_all_dim", False
|
||||
self.scaling = compute_mla_mscale_scaling(
|
||||
self.hf_config.rope_scaling, self.scaling
|
||||
)
|
||||
scaling_factor = self.hf_config.rope_scaling["factor"]
|
||||
mscale = yarn_get_mscale(scaling_factor, float(mscale_all_dim))
|
||||
self.scaling = self.scaling * mscale * mscale
|
||||
elif "SarvamMLAForCausalLM" in self.hf_config.architectures:
|
||||
self.head_dim = (
|
||||
self.hf_config.qk_nope_head_dim + self.hf_config.qk_rope_head_dim
|
||||
@@ -518,12 +524,9 @@ class ModelConfig:
|
||||
self.v_head_dim = self.hf_config.v_head_dim
|
||||
self.scaling = 1 / math.sqrt(self.qk_nope_head_dim + self.qk_rope_head_dim)
|
||||
if self.hf_config.rope_scaling:
|
||||
mscale_all_dim = self.hf_config.rope_scaling.get(
|
||||
"mscale_all_dim", False
|
||||
self.scaling = compute_mla_mscale_scaling(
|
||||
self.hf_config.rope_scaling, self.scaling
|
||||
)
|
||||
scaling_factor = self.hf_config.rope_scaling["factor"]
|
||||
mscale = yarn_get_mscale(scaling_factor, float(mscale_all_dim))
|
||||
self.scaling = self.scaling * mscale * mscale
|
||||
else:
|
||||
if (
|
||||
"MistralModel" in self.hf_config.architectures
|
||||
@@ -1410,6 +1413,23 @@ def yarn_get_mscale(scale: float = 1, mscale: float = 1) -> float:
|
||||
return 0.1 * mscale * math.log(scale) + 1.0
|
||||
|
||||
|
||||
def compute_mla_mscale_scaling(rope_scaling: dict, base_scaling: float) -> float:
|
||||
"""Compute MLA attention scaling factor from rope_scaling with mscale.
|
||||
|
||||
Used by DeepSeek, BailingMoe, SarvamMLA and similar MLA models.
|
||||
Warns if 'factor' is missing from rope_scaling (common in v5 configs).
|
||||
"""
|
||||
mscale_all_dim = rope_scaling.get("mscale_all_dim", False)
|
||||
if "factor" not in rope_scaling:
|
||||
logger.warning(
|
||||
"rope_scaling missing 'factor', defaulting to 1.0. "
|
||||
"Check model accuracy.",
|
||||
)
|
||||
scaling_factor = rope_scaling.get("factor", 1.0)
|
||||
mscale = yarn_get_mscale(scaling_factor, float(mscale_all_dim))
|
||||
return base_scaling * mscale * mscale
|
||||
|
||||
|
||||
def is_hybrid_swa_model(model_architectures: List[str]):
|
||||
|
||||
hybrid_swa_archs = {
|
||||
|
||||
Reference in New Issue
Block a user