Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Fix/patch tokenizer (#1171)

Eddda8e5476785c
diff --git a/unsloth/tokenizer_utils.py b/unsloth/tokenizer_utils.py
index 1cad00d44dd..4b9fd5e133d 100644
--- a/unsloth/tokenizer_utils.py
+++ b/unsloth/tokenizer_utils.py
@@ -915,7 +915,7 @@ def patch_sft_trainer_tokenizer():
check_text = \
"\n"\
"if 'tokenizer' not in locals(): tokenizer = processing_class\n"\
- "test_text = dataset[0][dataset_text_field] if (formatting_func is not None and dataset_text_field is None) else formatting_func(dataset[0])[0]\n"\
+ "test_text = dataset[0][dataset_text_field] if (formatting_func is None and dataset_text_field is not None) else formatting_func(dataset[0])[0]\n"\
"chat_template = getattr(tokenizer, 'chat_template', None)\n"\
"chat_template = '' if chat_template is None else chat_template\n"\
"has_bos_token_already = (test_text.startswith(tokenizer.bos_token) or tokenizer.bos_token in chat_template) "\