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.

Quick fixes (#106)

Daniel Han12e75c93d040
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py
index ee9647c7c60..a773b138907 100644
--- a/unsloth/models/_utils.py
+++ b/unsloth/models/_utils.py
@@ -242,7 +242,17 @@ def LoraLayer_update_layer(self, adapter_name, r, lora_alpha, lora_dropout, init
self.scaling[adapter_name] = lora_alpha / r
if init_lora_weights == "loftq":
+ # We manually check for PEFT
+ if not hasattr(self, "loftq_init"):
+ import peft
+ raise RuntimeError(
+ f"Unsloth: Your PEFT version of {peft.__version__} does not support LoftQ init.\n"\
+ "Please install PEFT 0.7.2 or higher.\n"\
+ "You can also install from source: `pip install git+https://github.com/huggingface/peft.git"
+ )
+ pass
self.loftq_init(adapter_name)
+
elif init_lora_weights:
self.reset_lora_parameters(adapter_name, init_lora_weights)
diff --git a/unsloth/models/dpo.py b/unsloth/models/dpo.py
index 519914d9046..92fde81fd03 100644
--- a/unsloth/models/dpo.py
+++ b/unsloth/models/dpo.py
@@ -28,6 +28,7 @@ DPOTrainer_metrics = [
"logits/rejected",
"logits/chosen",
]
+set_DPOTrainer_metrics = frozenset(DPOTrainer_metrics)
def NotebookProgressCallback_on_train_begin(self, args, state, control, **kwargs):
@@ -47,16 +48,7 @@ def NotebookProgressCallback_on_log(self, args, state, control, logs=None, **kwa
if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
values = {"Training Loss": logs["loss"]}
for metric in DPOTrainer_metrics:
- if metric in logs:
- values[metric.replace("/", " / ")] = logs[metric]
- else:
- # Maybe not a DPO Trainer anymore? Redo the tracker
- column_names = [self.first_column] + ["Training Loss"]
- if args.evaluation_strategy != IntervalStrategy.NO:
- column_names.append("Validation Loss")
- self.training_tracker = NotebookTrainingTracker(state.max_steps, column_names)
- break
- pass
+ values[metric.replace("/", " / ")] = logs[metric]
pass
# First column is necessarily Step since we're not in epoch eval strategy
values["Step"] = state.global_step
@@ -76,10 +68,16 @@ def NotebookTrainingTracker_write_line(self, values):
self.inner_table = [list(values.keys()), list(values.values())]
else:
columns = self.inner_table[0]
- print(columns)
- for key in values.keys():
- if key not in columns:
- columns.append(key)
+ new_values = {}
+ for key, value in values.items():
+ lowered = key.lower()
+ if lowered in set_DPOTrainer_metrics:
+ new_values[lowered.replace("/", " / ")] = value
+ else:
+ new_values[key] = value
+ pass
+ values = new_values
+
self.inner_table[0] = columns
if len(self.inner_table) > 1:
last_values = self.inner_table[-1]
@@ -104,7 +102,7 @@ pass
def PatchDPOTrainer():
# Patch DPO notebook printing
- # NotebookTrainingTracker.write_line = NotebookTrainingTracker_write_line
+ NotebookTrainingTracker.write_line = NotebookTrainingTracker_write_line
from transformers.trainer import DEFAULT_PROGRESS_CALLBACK
DEFAULT_PROGRESS_CALLBACK.on_train_begin = NotebookProgressCallback_on_train_begin
DEFAULT_PROGRESS_CALLBACK.on_log = NotebookProgressCallback_on_log
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index 06b78d77c5f..1df1a3e1205 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -912,14 +912,13 @@ class FastLlamaModel:
assert(type(use_rslora) is bool)
if use_rslora:
if not SUPPORTS_RSLORA:
- # We do it ourselves!
- new_alpha = lora_alpha / (r**0.5)
+ # We manually check for PEFT
import peft
- logger.warning_once(
- f"Unsloth: Your PEFT version of {peft.__version__} (0.7.2 needed) does not support `use_rslora` natively.\n"\
- f"But, we do it ourselves by setting `alpha = {new_alpha}.`"
+ raise RuntimeError(
+ f"Unsloth: Your PEFT version of {peft.__version__} does not support `use_rslora`.\n"\
+ "Please install PEFT 0.7.2 or higher.\n"\
+ "You can also install from source: `pip install git+https://github.com/huggingface/peft.git"
)
- lora_alpha = new_alpha
pass
pass
diff --git a/unsloth/save.py b/unsloth/save.py
index 3f279df37af..543ffd80d0d 100644
--- a/unsloth/save.py
+++ b/unsloth/save.py
@@ -555,7 +555,7 @@ def unsloth_push_to_hub_merged(
self,
repo_id : str,
tokenizer = None,
- save_method : str = "merged_16bit", # ["lora", "merged_16bit", "merged_4bit"]
+ save_method : str = "merged_16bit", # ["lora", "merged_16bit", "merged_4bit"]
use_temp_dir : Optional[bool] = None,
commit_message : Optional[str] = None,
private : Optional[bool] = None,
@@ -601,7 +601,7 @@ def unsloth_save_pretrained_gguf(
self,
save_directory : Union[str, os.PathLike],
tokenizer = None,
- quantization_method : str = "fast_quantized",
+ quantization_method : str = "fast_quantized",
push_to_hub : bool = False,
token : Optional[Union[str, bool]] = None,
is_main_process : bool = True,
@@ -649,7 +649,7 @@ def unsloth_save_pretrained_gguf(
arguments["push_to_hub"] = False # We save ourselves
arguments["save_method"] = "merged_16bit" # Must be 16bit
del arguments["self"]
- del arguments["quantization"]
+ del arguments["quantization_method"]
# Non blocking install GGUF first
git_clone = install_llama_cpp_clone_non_blocking()
@@ -699,7 +699,7 @@ def unsloth_push_to_hub_gguf(
self,
repo_id : str,
tokenizer = None,
- quantization_method : str = "fast_quantized",
+ quantization_method : str = "fast_quantized",
use_temp_dir : Optional[bool] = None,
commit_message : Optional[str] = None,
private : Optional[bool] = None,
@@ -749,7 +749,7 @@ def unsloth_push_to_hub_gguf(
arguments["save_method"] = "merged_16bit" # Must be 16bit
del arguments["self"]
del arguments["repo_id"]
- del arguments["quantization"]
+ del arguments["quantization_method"]
# Non blocking install GGUF first
git_clone = install_llama_cpp_clone_non_blocking()