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.

Bug fixes (#2982)

Daniel Han3824a6ad789f
diff --git a/pyproject.toml b/pyproject.toml
index ae46d7aaf51..d17859cfa8b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -37,7 +37,7 @@ triton = [
]
huggingface = [
- "unsloth_zoo>=2025.7.4",
+ "unsloth_zoo>=2025.7.5",
"packaging",
"tyro",
"transformers>=4.51.3,!=4.47.0,!=4.52.0,!=4.52.1,!=4.52.2,!=4.52.3,!=4.53.0",
@@ -48,7 +48,7 @@ huggingface = [
"wheel>=0.42.0",
"numpy",
"accelerate>=0.34.1",
- "trl>=0.7.9,!=0.9.0,!=0.9.1,!=0.9.2,!=0.9.3,!=0.15.0",
+ "trl>=0.7.9,!=0.9.0,!=0.9.1,!=0.9.2,!=0.9.3,!=0.15.0,!=0.19.0",
"peft>=0.7.1,!=0.11.0",
"protobuf",
"huggingface_hub",
@@ -381,7 +381,7 @@ colab-ampere-torch220 = [
"flash-attn>=2.6.3",
]
colab-new = [
- "unsloth_zoo>=2025.7.4",
+ "unsloth_zoo>=2025.7.5",
"packaging",
"tyro",
"transformers>=4.51.3,!=4.47.0,!=4.52.0,!=4.52.1,!=4.52.2,!=4.52.3,!=4.53.0",
@@ -399,7 +399,7 @@ colab-new = [
]
colab-no-deps = [
"accelerate>=0.34.1",
- "trl>=0.7.9,!=0.9.0,!=0.9.1,!=0.9.2,!=0.9.3,!=0.15.0",
+ "trl>=0.7.9,!=0.9.0,!=0.9.1,!=0.9.2,!=0.9.3,!=0.15.0,!=0.19.0",
"peft>=0.7.1",
"xformers",
"bitsandbytes>=0.45.5",
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py
index 5b3879ce68b..bfd7c8c5a59 100644
--- a/unsloth/models/_utils.py
+++ b/unsloth/models/_utils.py
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-__version__ = "2025.7.3"
+__version__ = "2025.7.4"
__all__ = [
"SUPPORTS_BFLOAT16",
@@ -190,6 +190,14 @@ try:
except:
pass
+# The following generation flags are not valid and may be ignored:
+try:
+ from transformers.generation.configuration_utils import logger as configuration_logger
+ configuration_logger.addFilter(HideLoggingMessage("following generation flags"))
+ del configuration_logger
+except:
+ pass
+
# Gemma3 It is strongly recommended to train Gemma3 models with the `eager`
try:
from transformers.models.gemma3.modeling_gemma3 import logger as gemma3_logger
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index 3551c6ca5e6..8d985aa9d24 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -2224,7 +2224,7 @@ class FastLlamaModel:
bias = "none",
layers_to_transform = None,
layers_pattern = None,
- use_gradient_checkpointing = True,
+ use_gradient_checkpointing = "unsloth",
random_state = 3407,
max_seq_length = 2048, # not used anymore
use_rslora = False,
@@ -2678,7 +2678,7 @@ class FastLlamaModel:
@staticmethod
def patch_peft_model(
model,
- use_gradient_checkpointing = True,
+ use_gradient_checkpointing = "unsloth",
):
if os.environ.get("UNSLOTH_USE_NEW_MODEL", "0") == "1":
return FastBaseModel.patch_peft_model(
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index 45b8ca63347..664fe10c4fc 100644
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -481,10 +481,11 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
"include_tokens_per_second" : False,
"include_num_input_tokens_seen" : False,
"auto_find_batch_size" : True, # Auto /2 batch size
- "dataloader_persistent_workers" : True, # Keeps dataloader in RAM
- "dataloader_prefetch_factor" : 2,
"dataloader_pin_memory" : True,
- "dataloader_num_workers" : 1,
+ # Might fail so disable for now
+ # "dataloader_persistent_workers" : True, # Keeps dataloader in RAM
+ # "dataloader_prefetch_factor" : 2,
+ # "dataloader_num_workers" : 2, # Default is 0 means 1
}
for k, v in replacements.items():
x = f"{k}( = [^,\n]{{1,}})?,\n"
@@ -671,7 +672,7 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
RLTrainer_source,
f"trl.trainer.{trainer_file}",
imports,
- overwrite = False,
+ overwrite = True,
)
# Patch Trainer
diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py
index 4d5b4d7a4dd..a88385bf03c 100644
--- a/unsloth/models/rl_replacements.py
+++ b/unsloth/models/rl_replacements.py
@@ -235,6 +235,59 @@ pass
RL_FUNCTIONS["grpo_trainer"].append(grpo_trainer__prepare_inputs)
+# Fix incorrect special tokens handling and truncation in older TRL versions
+def grpo_trainer__generate_and_score_completions(function_name, function):
+ if function_name != "_generate_and_score_completions": return function
+
+ # TRL 0.19.0 did skip_special_tokens = True which should be False
+ function = function.replace(
+ "prompt_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False",
+ "prompt_ids, skip_special_tokens=False, clean_up_tokenization_spaces=False",
+ )
+
+ # Always between max_prompt_length and use_vllm
+ found = re.findall(
+ r"\n(([ ]{8,})if self\.max_prompt_length is not None:.*?"\
+ r"\2if self\.use_vllm:)",
+ function,
+ flags = re.DOTALL | re.MULTILINE,
+ )
+ if len(found) != 0:
+ replace_part, spacing = found[0]
+ removed_comments = re.sub(r"\#[^\n]{1,}", "", replace_part)
+ splits = removed_comments.split("\n")
+ if sum(re.match(rf"{spacing}[^\s]", x) is not None for x in splits) == 2 and len(spacing) >= 8:
+
+ new_replacement = \
+ f"""\n{spacing}if self.max_prompt_length is not None:
+ # If max_prompt_length is set, we trim the prompt to keep only the last `max_prompt_length` tokens.
+ # Then we decode those tokens back into text. We manually remove leading pad tokens from the decoded text,
+ # because we can't use `skip_special_tokens=True` (some special tokens are still needed for generation).
+ prompt_ids = prompt_ids[:, -self.max_prompt_length :]
+ prompt_mask = prompt_mask[:, -self.max_prompt_length :]
+ prompts_text = self.processing_class.batch_decode(
+ prompt_ids, skip_special_tokens=False, clean_up_tokenization_spaces=False
+ )
+ pad_token = self.processing_class.pad_token
+ def strip_leading_tokens(text):
+ while text.startswith(pad_token):
+ text = text.removeprefix(pad_token)
+ return text
+
+ if pad_token is not None:
+ prompts_text = [
+ strip_leading_tokens(text) for text in prompts_text
+ ]
+
+ # Generate completions using either vLLM or regular generation
+ if self.use_vllm:"""
+ function = function.replace(replace_part, new_replacement)
+ pass
+ return function
+pass
+RL_FUNCTIONS["grpo_trainer"].append(grpo_trainer__generate_and_score_completions)
+
+
# Remove _move_model_to_vllm
def grpo_trainer__move_model_to_vllm(function_name, function):
if function_name != "_move_model_to_vllm": return function
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py
index 7442f07e738..5bbf4c76a68 100644
--- a/unsloth/models/vision.py
+++ b/unsloth/models/vision.py
@@ -755,6 +755,8 @@ class FastBaseModel:
os.environ["UNSLOTH_RETURN_HIDDEN_STATES"] = "0"
# Must enable returning logits
os.environ["UNSLOTH_RETURN_LOGITS"] = "1"
+ # Turn off skip guards and set stance to default
+ torch.compiler.set_stance(stance = "default", skip_guard_eval_unsafe = False)
return model
pass
@@ -801,6 +803,8 @@ class FastBaseModel:
pass
# Can re-enable not returning logits
os.environ["UNSLOTH_RETURN_LOGITS"] = "0"
+ # Turn off skip guards and set stance to default
+ torch.compiler.set_stance(stance = "default", skip_guard_eval_unsafe = False)
return model
pass
pass