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
max_seq_length
Daniel Hanc6f73dd5214b
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex aa5a1c57464..7ae6e92d11f 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -1913,12 +1913,12 @@ class FastLlamaModel:# Save max_seq_lengthmodel.max_seq_length = max_seq_length- internal_model = model- while hasattr(internal_model, "model"):- internal_model.max_seq_length = max_seq_length- internal_model = internal_model.model+ m = model+ while hasattr(m, "model"):+ m.max_seq_length = max_seq_length+ m = m.modelpass- internal_model.max_seq_length = max_seq_length+ m.max_seq_length = max_seq_length# We check the tokenizer first for errorsif fix_tokenizer:diff --git a/unsloth/models/vision.py b/unsloth/models/vision.pyindex 371b4795ee2..19aeabb35bc 100644--- a/unsloth/models/vision.py+++ b/unsloth/models/vision.py@@ -238,11 +238,13 @@ class FastBaseModel:tokenizer.tokenizer.padding_side = "left" # Force inferencem = modelwhile hasattr(m, "model"):+ m.max_seq_length = max_seq_lengthm._saved_temp_tokenizer = tokenizer# Also set is_loaded_in_8bit to disable incorrect DDPm.is_loaded_in_8bit = True if not full_finetuning else Falsem = m.modelpass+ m.max_seq_length = max_seq_lengthm._saved_temp_tokenizer = tokenizer# Also set is_loaded_in_8bit to disable incorrect DDPm.is_loaded_in_8bit = True if not full_finetuning else False@@ -328,7 +330,7 @@ class FastBaseModel:gc.collect()torch.cuda.empty_cache()pass-+ max_seq_length = model.max_seq_lengthlora_config = LoraConfig(r = r,lora_alpha = lora_alpha,@@ -346,6 +348,7 @@ class FastBaseModel:requires_grad_for_gradient_checkpointing(model)model = FastBaseModel.post_patch_model(model, use_gradient_checkpointing)+ model.max_seq_length = max_seq_length# Clear deleted GPU itemsfor _ in range(3):