From 0028e2f6d7bef631be8b1a868e3481d45c0107ee Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Tue, 24 Feb 2026 08:08:03 +0000 Subject: [PATCH] Fix tokenizer reload from LoRA path on transformers 5.x Transformers 5.x no longer saves special_tokens_map.json when calling tokenizer.save_pretrained(). The three-file check in loader.py (tokenizer_config.json + tokenizer.json + special_tokens_map.json) fails, causing Unsloth to fall back to the base model's tokenizer which may not have a chat_template set. Accept chat_template.jinja as an alternative signal that the LoRA path contains valid tokenizer data. This file is always saved by Unsloth's save_pretrained and contains the chat template. --- unsloth/models/loader.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index ef7e67b468..06c9603988 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -568,7 +568,10 @@ class FastLanguageModel(FastLlamaModel): if ( os.path.exists(os.path.join(old_model_name, "tokenizer_config.json")) and os.path.exists(os.path.join(old_model_name, "tokenizer.json")) - and os.path.exists(os.path.join(old_model_name, "special_tokens_map.json")) + and ( + os.path.exists(os.path.join(old_model_name, "special_tokens_map.json")) + or os.path.exists(os.path.join(old_model_name, "chat_template.jinja")) + ) ): tokenizer_name = old_model_name else: @@ -1237,7 +1240,10 @@ class FastModel(FastBaseModel): if ( os.path.exists(os.path.join(old_model_name, "tokenizer_config.json")) and os.path.exists(os.path.join(old_model_name, "tokenizer.json")) - and os.path.exists(os.path.join(old_model_name, "special_tokens_map.json")) + and ( + os.path.exists(os.path.join(old_model_name, "special_tokens_map.json")) + or os.path.exists(os.path.join(old_model_name, "chat_template.jinja")) + ) ): tokenizer_name = old_model_name else: