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.

Update rl.py

Daniel Hanc0805c415f5f
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index 40d68f6a742..4c6d73ee842 100644
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -201,6 +201,21 @@ def get_trl_metrics():
left_prefix = 'prefix = "eval_" if train_eval == "eval" else ""' in file
if left_prefix: metrics += metrics_f
+ # Remove optional items
+ # if ...: metrics[...] =
+ metrics_optional = re.findall(
+ r"if[^\n]{1,}\n[\s]{4,}"\
+ r"(?:metrics|stats)"\
+ r"\["\
+ r"(?:f[\"\']\{[^\}]{1,}\})?"\
+ r"([^\"\']{1,})[\"\']"\
+ r"\]",
+ file,
+ flags = re.MULTILINE,
+ )
+ metrics_optional = set(metrics_optional)
+ metrics = [x for x in metrics if x not in metrics_optional]
+
# Remove all eval_ things
metrics = [x for x in metrics if not x.startswith("eval_")]