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
fix: 3 patch_* helpers — fast_lora import, sft_trainer Union, openenv OSError (#5319)
Daniel Han948ce43584c2
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex 34fec53504b..d3eee033256 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -2483,6 +2483,7 @@ def patch_tokenizer(model, tokenizer):def patch_fast_lora():import peft.tuners.lora.bnb+ from ..kernels.fast_lora import fast_lora_forwardpeft.tuners.lora.bnb.Linear4bit.forward = fast_lora_forwarddiff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.pyindex 0f10847282b..c2be1bf74a6 100755--- a/unsloth/models/rl_replacements.py+++ b/unsloth/models/rl_replacements.py@@ -1780,7 +1780,20 @@ def openenv_vllm_reload_weights():patch_target_name = "generate_rollout_completions"patch_target = getattr(openenv_utils, patch_target_name)- src = inspect.getsource(patch_target)+ # TRL 0.29.1+ ships some openenv helpers as compiled bytecode without+ # accessible source on disk; inspect.getsource raises OSError("could+ # not get source code") in that case. Skip the source-rewrite patch+ # rather than crashing -- the core unsloth weight-reload path stays+ # functional, only the wake_up tag rewrite is skipped.+ try:+ src = inspect.getsource(patch_target)+ except OSError as e:+ logger.warning(+ f"Unsloth: Could not retrieve source for trl openenv "+ f"{patch_target_name} ({e}); skipping rewrite. "+ f"Weight reload still functional."+ )+ returnsrc = textwrap.dedent(src)original_src = srcdiff --git a/unsloth/tokenizer_utils.py b/unsloth/tokenizer_utils.pyindex 130894e3855..67edc41d52e 100644--- a/unsloth/tokenizer_utils.py+++ b/unsloth/tokenizer_utils.py@@ -1580,6 +1580,12 @@ def patch_sft_trainer_tokenizer():except:returnall_imports = dir(trl.trainer.sft_trainer)+ # Make typing names available to the exec'd source bodies. TRL >= 1.x+ # type-hints _prepare_dataset / _prepare_non_packed_dataloader with+ # `Union[...]` and friends; without these imports in the exec namespace+ # those become NameErrors at exec time. Mirrors the pattern used in+ # unsloth/models/_utils.py:patch_linear_scaling.+ from typing import Union, Optional, List, Any, Callable, Tuple, Dict, Iterator # noqa: F401for (function_name,