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 exec, eval (#743)
Daniel Han775fb647d5b7
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex e0df218a930..725e9b3ff3a 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -618,7 +618,11 @@ def patch_linear_scaling(f"from {model_filepath} import logger, "\f"{model_name.title()}Attention, {model_name.title()}Config"- function = inspect.getsource(attention_module.__init__)+ try:+ function = inspect.getsource(attention_module.__init__)+ except:+ # Most likely already patched!+ return None, Nonewhere = function.find("def")function = function.split("\n")function = "\n".join(x[where:] for x in function)diff --git a/unsloth/models/gemma.py b/unsloth/models/gemma.pyindex 4d3db8d3931..c47e65e87b2 100644--- a/unsloth/models/gemma.py+++ b/unsloth/models/gemma.py@@ -281,8 +281,10 @@ class FastGemmaModel(FastLlamaModel):scaled_rope_module = GemmaFixedLinearScalingRotaryEmbedding,attention_module = GemmaAttention,)- exec(function, globals())- GemmaAttention.__init__ = eval(init_name)+ if init_name is not None:+ exec(function, globals())+ GemmaAttention.__init__ = eval(init_name)+ passGemmaAttention .forward = LlamaAttention_fast_forwardGemmaSdpaAttention .forward = LlamaAttention_fast_forwardGemmaFlashAttention2.forward = LlamaAttention_fast_forwarddiff --git a/unsloth/models/gemma2.py b/unsloth/models/gemma2.pyindex 4a1420fb42d..fda78534d89 100644--- a/unsloth/models/gemma2.py+++ b/unsloth/models/gemma2.py@@ -436,8 +436,10 @@ class FastGemma2Model(FastLlamaModel):scaled_rope_module = GemmaFixedLinearScalingRotaryEmbedding,attention_module = Gemma2Attention,)- exec(function, globals())- Gemma2Attention.__init__ = eval(init_name)+ if init_name is not None:+ exec(function, globals())+ Gemma2Attention.__init__ = eval(init_name)+ passGemma2Attention .forward = Gemma2Attention_fast_forwardGemma2SdpaAttention .forward = Gemma2Attention_fast_forwardGemma2FlashAttention2.forward = Gemma2Attention_fast_forwarddiff --git a/unsloth/models/mistral.py b/unsloth/models/mistral.pyindex 28f664ca2d9..6eb3fccfabc 100644--- a/unsloth/models/mistral.py+++ b/unsloth/models/mistral.py@@ -277,8 +277,10 @@ class FastMistralModel(FastLlamaModel):scaled_rope_module = LlamaLinearScalingRotaryEmbedding,attention_module = MistralAttention,)- exec(function, globals())- MistralAttention.__init__ = eval(init_name)+ if init_name is not None:+ exec(function, globals())+ MistralAttention.__init__ = eval(init_name)+ passMistralAttention .forward = MistralAttention_fast_forwardMistralSdpaAttention .forward = MistralAttention_fast_forwardMistralFlashAttention2.forward = MistralAttention_fast_forwarddiff --git a/unsloth/models/qwen2.py b/unsloth/models/qwen2.pyindex dcd05af60e7..82de1951b89 100644--- a/unsloth/models/qwen2.py+++ b/unsloth/models/qwen2.py@@ -45,8 +45,10 @@ class FastQwen2Model(FastLlamaModel):scaled_rope_module = LlamaLinearScalingRotaryEmbedding,attention_module = Qwen2Attention,)- exec(function, globals())- Qwen2Attention.__init__ = eval(init_name)+ if init_name is not None:+ exec(function, globals())+ Qwen2Attention.__init__ = eval(init_name)+ passQwen2Attention .forward = LlamaAttention_fast_forwardQwen2SdpaAttention .forward = LlamaAttention_fast_forwardQwen2FlashAttention2.forward = LlamaAttention_fast_forward