[model] support GLM4.6v (#9586)

This commit is contained in:
Hertz
2025-12-09 11:06:42 +08:00
committed by GitHub
parent 5744f1ea94
commit c1f5f8fff6
3 changed files with 19 additions and 5 deletions

View File

@@ -199,9 +199,12 @@ class Template:
logger.info_rank0(f"Add pad token: {tokenizer.pad_token}")
if stop_words:
num_added_tokens = tokenizer.add_special_tokens(
dict(additional_special_tokens=stop_words), replace_additional_special_tokens=False
)
try:
num_added_tokens = tokenizer.add_special_tokens(
dict(additional_special_tokens=stop_words), replace_additional_special_tokens=False
)
except TypeError:
num_added_tokens = tokenizer.add_special_tokens(dict(additional_special_tokens=stop_words))
logger.info_rank0("Add {} to stop words.".format(",".join(stop_words)))
if num_added_tokens > 0:
logger.warning_rank0("New tokens have been added, make sure `resize_vocab` is True.")

View File

@@ -969,6 +969,14 @@ register_model_group(
DownloadSource.DEFAULT: "zai-org/GLM-4.1V-9B-Thinking",
DownloadSource.MODELSCOPE: "ZhipuAI/GLM-4.1V-9B-Thinking",
},
"GLM-4.6V": {
DownloadSource.DEFAULT: "zai-org/GLM-4.6V",
DownloadSource.MODELSCOPE: "ZhipuAI/GLM-4.6V",
},
"GLM-4.6V-Flash": {
DownloadSource.DEFAULT: "zai-org/GLM-4.6V-Flash",
DownloadSource.MODELSCOPE: "ZhipuAI/GLM-4.6V-Flash",
},
},
template="glm4v",
multimodal=True,

View File

@@ -78,8 +78,11 @@ def run_sft(
# Compatible with Transformers v4 and Transformers v5
if is_transformers_version_greater_than("5.0.0RC0"):
extra_special_tokens = getattr(tokenizer, "_extra_special_tokens", [])
extra_ids = tokenizer.convert_tokens_to_ids(extra_special_tokens)
extra_ids = getattr(tokenizer, "additional_special_tokens_ids", None)
if not isinstance(extra_ids, list):
extra_special_tokens = getattr(tokenizer, "_extra_special_tokens", [])
string_tokens = [str(t) for t in extra_special_tokens]
extra_ids = tokenizer.convert_tokens_to_ids(string_tokens)
all_eos_ids = [tokenizer.eos_token_id] + [i for i in extra_ids if i != -1]
unique_eos_ids = list(dict.fromkeys(all_eos_ids))
gen_kwargs["eos_token_id"] = unique_eos_ids