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
DPO
Daniel Han-Chen473554810a03
diff --git a/unsloth/models/__init__.py b/unsloth/models/__init__.pyindex 9322049dc83..b174a2cec18 100644--- a/unsloth/models/__init__.py+++ b/unsloth/models/__init__.py@@ -12,6 +12,6 @@# See the License for the specific language governing permissions and# limitations under the License.-from .loader import FastLanguageModel+from .loader import FastLanguageModel, FastDPOTrainerfrom .llama import FastLlamaModelfrom .mistral import FastMistralModeldiff --git a/unsloth/models/dpo.py b/unsloth/models/dpo.pyindex 59e614983f0..55ee247bf6a 100644--- a/unsloth/models/dpo.py+++ b/unsloth/models/dpo.py@@ -17,6 +17,9 @@ from transformers.utils.notebook import (NotebookTrainingTracker,NotebookProgressCallback,)+from transformers.trainer import DEFAULT_PROGRESS_CALLBACK+from trl import DPOTrainer+import typesDPOTrainer_metrics = ["rewards/chosen",@@ -46,23 +49,35 @@ def NotebookProgressCallback_on_log(self, args, state, control, logs=None, **kwaif args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:values = {"Training Loss": logs["loss"]}for metric in DPOTrainer_metrics:- values[metric.replace("/", " / ")] = logs[metric]+ 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+ pass# First column is necessarily Step since we're not in epoch eval strategyvalues["Step"] = state.global_stepself.training_tracker.write_line(values)+ passpass-def patch_dpo_trainer():- # We patch Jupyter Notebook's printing to include all columns for DPO.- NotebookProgressCallback.on_train_begin = NotebookProgressCallback_on_train_begin- NotebookProgressCallback.on_log = NotebookProgressCallback_on_log-pass-# Patch DPO notebook printing-patch_dpo_trainer()---from trl import DPOTrainerclass FastDPOTrainer(DPOTrainer):+ # Patch DPO notebook printing+ if (DEFAULT_PROGRESS_CALLBACK is NotebookProgressCallback):++ DEFAULT_PROGRESS_CALLBACK.on_train_begin = types.MethodType(+ NotebookProgressCallback_on_train_begin,+ DEFAULT_PROGRESS_CALLBACK,+ )+ DEFAULT_PROGRESS_CALLBACK.on_log = types.MethodType(+ NotebookProgressCallback_on_log,+ DEFAULT_PROGRESS_CALLBACK,+ )passpass