Preserve standalone model chat templates
This commit is contained in:
@@ -81,7 +81,14 @@ def repair_tokenizer_config(
|
||||
patched["tokenizer_class"] = "PreTrainedTokenizerFast"
|
||||
repairs.append("TokenizersBackend -> PreTrainedTokenizerFast")
|
||||
|
||||
if not patched.get("chat_template"):
|
||||
# Transformers can load a standalone template with higher precedence than
|
||||
# tokenizer_config.json. Do not synthesize one when the repository already
|
||||
# supplies a template in that format.
|
||||
has_standalone_template = any(
|
||||
(model_dir / name).is_file()
|
||||
for name in ("chat_template.jinja", "chat_template.json")
|
||||
)
|
||||
if not patched.get("chat_template") and not has_standalone_template:
|
||||
config_path = model_dir / "config.json"
|
||||
if config_path.is_file():
|
||||
model_config = _json_object(config_path)
|
||||
|
||||
Reference in New Issue
Block a user