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.

Patch PEFT

Daniel Hanfcf92c54caed
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index ba4362b3cdb..96eb5035e83 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -2063,9 +2063,9 @@ class FastLlamaModel:
(getattr(gate_proj, "base_layer", gate_proj).bias is None) and \
(getattr( up_proj, "base_layer", up_proj).bias is None) and \
(getattr(down_proj, "base_layer", down_proj).bias is None) and \
- (getattr(gate_proj, "lora_magnitude_vector", None) is None) and \
- (getattr( up_proj, "lora_magnitude_vector", None) is None) and \
- (getattr(down_proj, "lora_magnitude_vector", None) is None):
+ (len(getattr(gate_proj, "lora_magnitude_vector", [])) == 0) and \
+ (len(getattr( up_proj, "lora_magnitude_vector", [])) == 0) and \
+ (len(getattr(down_proj, "lora_magnitude_vector", [])) == 0):
# https://stackoverflow.com/questions/50599045/python-replacing-a-function-within-a-class-of-a-module
layer.mlp.forward = types.MethodType(apply_lora_mlp, layer.mlp)
@@ -2085,11 +2085,11 @@ class FastLlamaModel:
hasattr(k_proj, "lora_A") and \
hasattr(v_proj, "lora_A") and \
(getattr(q_proj, "base_layer", q_proj).bias is None) and \
- (getattr(q_proj, "base_layer", k_proj).bias is None) and \
- (getattr(q_proj, "base_layer", v_proj).bias is None) and \
- (getattr(q_proj, "lora_magnitude_vector", None) is None) and \
- (getattr(k_proj, "lora_magnitude_vector", None) is None) and \
- (getattr(v_proj, "lora_magnitude_vector", None) is None):
+ (getattr(k_proj, "base_layer", k_proj).bias is None) and \
+ (getattr(v_proj, "base_layer", v_proj).bias is None) and \
+ (len(getattr(q_proj, "lora_magnitude_vector", [])) == 0) and \
+ (len(getattr(k_proj, "lora_magnitude_vector", [])) == 0) and \
+ (len(getattr(v_proj, "lora_magnitude_vector", [])) == 0):
layer.self_attn.apply_qkv = apply_lora_qkv
n_qkv += 1
@@ -2106,7 +2106,7 @@ class FastLlamaModel:
o_proj = layer.self_attn.o_proj
if hasattr(o_proj, "lora_A") and \
(getattr(o_proj, "base_layer", o_proj).bias is None) and \
- (getattr(o_proj, "lora_magnitude_vector", None) is None):
+ (len(getattr(o_proj, "lora_magnitude_vector", [])) == 0):
layer.self_attn.apply_o = apply_lora_o
n_o += 1