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.

max_seq_length

Daniel Hanc6f73dd5214b
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index aa5a1c57464..7ae6e92d11f 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -1913,12 +1913,12 @@ class FastLlamaModel:
# Save max_seq_length
model.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.model
pass
- internal_model.max_seq_length = max_seq_length
+ m.max_seq_length = max_seq_length
# We check the tokenizer first for errors
if fix_tokenizer:
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py
index 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 inference
m = model
while hasattr(m, "model"):
+ m.max_seq_length = max_seq_length
m._saved_temp_tokenizer = tokenizer
# Also set is_loaded_in_8bit to disable incorrect DDP
m.is_loaded_in_8bit = True if not full_finetuning else False
m = m.model
pass
+ m.max_seq_length = max_seq_length
m._saved_temp_tokenizer = tokenizer
# Also set is_loaded_in_8bit to disable incorrect DDP
m.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_length
lora_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 items
for _ in range(3):