From e539965740d96a2ac6aa112d869c1ffe0cf42a47 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Fri, 13 Mar 2026 15:18:04 +0000 Subject: [PATCH] fix error for chat template --- studio/backend/core/inference/inference.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/studio/backend/core/inference/inference.py b/studio/backend/core/inference/inference.py index ff02816953..c4788b6cbb 100644 --- a/studio/backend/core/inference/inference.py +++ b/studio/backend/core/inference/inference.py @@ -744,13 +744,21 @@ class InferenceBackend: ) else: logger.info( - f"No registered template for {self.active_model_name}, using tokenizer default" + f"No registered Unsloth template for {self.active_model_name}, using tokenizer default" ) except Exception as e: logger.warning(f"Could not apply get_chat_template: {e}") # Step 2: Format with tokenizer.apply_chat_template() try: + if not (hasattr(tokenizer, 'chat_template') and tokenizer.chat_template): + raise ValueError( + f"Model '{self.active_model_name}' has no chat_template set in its " + f"tokenizer_config.json. This is usually a problem with the model's " + f"HuggingFace repository — it is missing a 'chat_template' key. " + f"Please use a model that includes a chat template, or manually set " + f"one via tokenizer.chat_template before inference." + ) formatted_prompt = tokenizer.apply_chat_template( messages, tokenize = False, add_generation_prompt = True )