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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
check_tokenizer
Daniel Han-Chen6efffb46e425
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex e2361d389c0..f310d102f45 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -619,6 +619,7 @@ class FastLlamaModel:token = None,device_map = "sequential",rope_scaling = None,+ check_tokenizer = True,):SUPPORTS_BFLOAT16 = torch.cuda.is_bf16_supported()gpu_stats = torch.cuda.get_device_properties(0)@@ -703,14 +704,16 @@ class FastLlamaModel:internal_model.max_seq_length = max_position_embeddings# We check the tokenizer first for errors- tokenizer = check_tokenizer(- model = model,- tokenizer = tokenizer,- model_name = model_name,- model_max_length = max_seq_length,- padding_side = "right",- token = token,- )+ if check_tokenizer:+ tokenizer = check_tokenizer(+ model = model,+ tokenizer = tokenizer,+ model_name = model_name,+ model_max_length = max_seq_length,+ padding_side = "right",+ token = token,+ )+ passreturn model, tokenizerpassdiff --git a/unsloth/models/loader.py b/unsloth/models/loader.pyindex 61585d77a55..eadf026cc90 100644--- a/unsloth/models/loader.py+++ b/unsloth/models/loader.py@@ -44,6 +44,7 @@ class FastLanguageModel(FastLlamaModel):token = None,device_map = "sequential",rope_scaling = None,+ check_tokenizer = True,*args, **kwargs,):if not SUPPORTS_FOURBIT and model_name in FOURBIT_MAPPER:@@ -83,6 +84,7 @@ class FastLanguageModel(FastLlamaModel):token = token,device_map = device_map,rope_scaling = rope_scaling,+ check_tokenizer = check_tokenizer,*args, **kwargs,)passdiff --git a/unsloth/models/mistral.py b/unsloth/models/mistral.pyindex 3e3d5956cc1..e15a3ae9fff 100644--- a/unsloth/models/mistral.py+++ b/unsloth/models/mistral.py@@ -263,6 +263,7 @@ class FastMistralModel(FastLlamaModel):token = None,device_map = "sequential",rope_scaling = None, # Mistral does not support RoPE scaling+ check_tokenizer = True,):if rope_scaling is not None:logger.warning_once("Unsloth: Mistral models do not support RoPE scaling.")@@ -332,14 +333,16 @@ class FastMistralModel(FastLlamaModel):internal_model.max_seq_length = max_position_embeddings# We check the tokenizer first for errors- tokenizer = check_tokenizer(- model = model,- tokenizer = tokenizer,- model_name = model_name,- model_max_length = max_seq_length,- padding_side = "right",- token = token,- )+ if check_tokenizer:+ tokenizer = check_tokenizer(+ model = model,+ tokenizer = tokenizer,+ model_name = model_name,+ model_max_length = max_seq_length,+ padding_side = "right",+ token = token,+ )+ passreturn model, tokenizerpasspass