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.

Fix DPO stats (#906)

Daniel Han120410772485
diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.py
index 6074a515383..b8473e60c7f 100644
--- a/unsloth/kernels/cross_entropy_loss.py
+++ b/unsloth/kernels/cross_entropy_loss.py
@@ -303,6 +303,7 @@ class Fast_CrossEntropyLoss(torch.autograd.Function):
pass
+@torch._disable_dynamo
def fast_cross_entropy_loss(logits, labels, logit_softcapping = 0):
"""
Arguments:
diff --git a/unsloth/models/dpo.py b/unsloth/models/dpo.py
index b7c7305bb3f..e7074350c3c 100644
--- a/unsloth/models/dpo.py
+++ b/unsloth/models/dpo.py
@@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+__all__ = [
+ "PatchDPOTrainer",
+]
+
try:
from transformers.utils.notebook import (
IntervalStrategy,
@@ -22,6 +26,12 @@ try:
except:
HAS_NOTEBOOK = False
pass
+import torch
+from ._utils import torch_compile_options
+import inspect
+import torch.nn as nn
+from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union
+
DPOTrainer_metrics = [
"rewards/chosen",
@@ -37,11 +47,11 @@ set_DPOTrainer_metrics = frozenset(DPOTrainer_metrics)
def NotebookProgressCallback_on_train_begin(self, args, state, control, **kwargs):
- self.first_column = "Epoch" if args.evaluation_strategy == IntervalStrategy.EPOCH else "Step"
+ self.first_column = "Epoch" if args.eval_strategy == IntervalStrategy.EPOCH else "Step"
self.training_loss = 0
self.last_log = 0
column_names = [self.first_column] + ["Training Loss"]
- if args.evaluation_strategy != IntervalStrategy.NO:
+ if args.eval_strategy != IntervalStrategy.NO:
column_names.append("Validation Loss")
column_names += [x.replace("/", " / ") for x in DPOTrainer_metrics]
self.training_tracker = NotebookTrainingTracker(state.max_steps, column_names)
@@ -50,7 +60,7 @@ pass
def NotebookProgressCallback_on_log(self, args, state, control, logs=None, **kwargs):
# Only for when there is no evaluation
- if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
+ if args.eval_strategy == IntervalStrategy.NO and "loss" in logs:
values = {"Training Loss": logs["loss"]}
for metric in DPOTrainer_metrics:
values[metric.replace("/", " / ")] = logs[metric]
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index 2a07da6ce58..6f1bb62c189 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -961,6 +961,7 @@ def CausalLM_fast_forward(fast_forward_inference):
pass
+@torch._disable_dynamo
def PeftModelForCausalLM_fast_forward(
self,
input_ids=None,