From cf68eade4f773440f23b85b84fd7dc1104ea42bc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Feb 2026 13:32:32 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/dataprep/synthetic.py | 9 +++++++-- unsloth/models/rl.py | 29 +++++++++++++++++++++++------ unsloth/trainer.py | 8 ++++---- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/unsloth/dataprep/synthetic.py b/unsloth/dataprep/synthetic.py index e59ce50c3f..783b1d3968 100644 --- a/unsloth/dataprep/synthetic.py +++ b/unsloth/dataprep/synthetic.py @@ -282,9 +282,14 @@ class SyntheticDataKit: # Fall back to the metrics endpoint if available. try: import urllib.request - with urllib.request.urlopen("http://localhost:8000/metrics", timeout = 2) as resp: + + with urllib.request.urlopen( + "http://localhost:8000/metrics", timeout = 2 + ) as resp: if getattr(resp, "status", None) == 200: - print("vLLM metrics endpoint detected; proceeding without ready log.") + print( + "vLLM metrics endpoint detected; proceeding without ready log." + ) ready = True except Exception: pass diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 2aee701ded..88abafdcef 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -18,6 +18,7 @@ __all__ = [ ] import torch + UNSLOTH_SFT_VLM_FIX = True from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union import inspect @@ -229,7 +230,9 @@ def PatchRL(FastLanguageModel): continue if hasattr(current_trainer, unwrap): try: - setattr(current_trainer, unwrap, unsloth_unwrap_model_for_generation) + setattr( + current_trainer, unwrap, unsloth_unwrap_model_for_generation + ) except Exception: continue @@ -1229,16 +1232,24 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer", module_prefix = "trl.t # Patch Trainer try: - setattr(trl, RLTrainer_name, getattr(created_module, f"Unsloth{RLTrainer_name}")) + setattr( + trl, RLTrainer_name, getattr(created_module, f"Unsloth{RLTrainer_name}") + ) except Exception: pass try: root_module = importlib.import_module(module_prefix) - setattr(root_module, RLTrainer_name, getattr(created_module, f"Unsloth{RLTrainer_name}")) + setattr( + root_module, + RLTrainer_name, + getattr(created_module, f"Unsloth{RLTrainer_name}"), + ) except Exception: pass try: - setattr(trainer, RLTrainer_name, getattr(created_module, f"Unsloth{RLTrainer_name}")) + setattr( + trainer, RLTrainer_name, getattr(created_module, f"Unsloth{RLTrainer_name}") + ) except Exception: pass @@ -1249,11 +1260,17 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer", module_prefix = "trl.t pass try: root_module = importlib.import_module(module_prefix) - setattr(root_module, RLConfig_name, getattr(created_module, f"Unsloth{RLConfig_name}")) + setattr( + root_module, + RLConfig_name, + getattr(created_module, f"Unsloth{RLConfig_name}"), + ) except Exception: pass try: - setattr(trainer, RLConfig_name, getattr(created_module, f"Unsloth{RLConfig_name}")) + setattr( + trainer, RLConfig_name, getattr(created_module, f"Unsloth{RLConfig_name}") + ) except Exception: pass diff --git a/unsloth/trainer.py b/unsloth/trainer.py index 3faa25b39e..d887078afc 100644 --- a/unsloth/trainer.py +++ b/unsloth/trainer.py @@ -420,7 +420,9 @@ def _patch_trl_trainer(): trl_trainers = set( x[: -len("Trainer")] for x in trl_classes if x.endswith("Trainer") ) - trl_configs = set(x[: -len("Config")] for x in trl_classes if x.endswith("Config")) + trl_configs = set( + x[: -len("Config")] for x in trl_classes if x.endswith("Config") + ) trl_bases = list(trl_trainers & trl_configs) for base in trl_bases: @@ -458,9 +460,7 @@ def _patch_trl_trainer(): for mod in pkgutil.iter_modules(trl_experimental.__path__): if mod.name.endswith("_trainer"): try: - submod = importlib.import_module( - f"trl.experimental.{mod.name}" - ) + submod = importlib.import_module(f"trl.experimental.{mod.name}") _patch_trl_module(submod) except Exception: continue