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 Han9680d0f73a07
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index c50f65e4bd9..5583702e7ee 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -1952,13 +1952,13 @@ class FastLlamaModel:
Trainer._inner_training_loop = _fast_inner_training_loop
# Save max_seq_length
- model.max_seq_length = max_position_embeddings
+ model.max_seq_length = max_seq_length
internal_model = model
while hasattr(internal_model, "model"):
- internal_model.max_seq_length = max_position_embeddings
+ internal_model.max_seq_length = max_seq_length
internal_model = internal_model.model
pass
- internal_model.max_seq_length = max_position_embeddings
+ internal_model.max_seq_length = max_seq_length
# We check the tokenizer first for errors
if fix_tokenizer:
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index 5ec418dda86..dad658170ec 100644
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -287,6 +287,25 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
extra_args += saving_check
pass
+ # Edit dataset_num_proc
+ if "dataset_num_proc" in call_args:
+ num_proc_check = \
+ "if dataset_num_proc is None:\n"\
+ " from multiprocessing import cpu_count\n"\
+ " dataset_num_proc = cpu_count()\n"
+ extra_args += num_proc_check
+ pass
+
+ # Check max_seq_length
+ if "max_seq_length" in call_args:
+ length_check = \
+ "if hasattr(model, 'max_seq_length') and model.max_seq_length > max_seq_length:\n"\
+ " print('Unsloth: You set `max_seq_length` as ' + str(max_seq_length) + ' but the\\n'"\
+ " 'model maximum sequence length is ' + str(model.max_seq_length) + '. We will reduce it.')\n"
+ " max_seq_length = model.max_seq_length\n"
+ extra_args += length_check
+ pass
+
# Create RLConfig args
extra_args = extra_args.split("\n")
extra_args = "\n".join(" "*8 + x for x in extra_args)