From 46fc68f38c50f67b7d25ee8715bc77851045ec69 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Feb 2026 14:54:13 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/models/rl.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index f30b7012cc..783efb56b6 100755 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -475,11 +475,16 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): if _parent is object: continue _parent_mod = inspect.getmodule(_parent) - if _parent_mod is None or _parent_mod.__name__ == f"trl.trainer.{trainer_file}": + if ( + _parent_mod is None + or _parent_mod.__name__ == f"trl.trainer.{trainer_file}" + ): continue config = [ - x for x in dir(_parent_mod) - if x.endswith("Config") and x != "Config" + x + for x in dir(_parent_mod) + if x.endswith("Config") + and x != "Config" and not x.startswith("_") and trainer_file.split("_")[0] in x.lower() ] @@ -520,7 +525,10 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): if _parent is object: continue _parent_mod = inspect.getmodule(_parent) - if _parent_mod is None or _parent_mod.__name__ == f"trl.trainer.{trainer_file}": + if ( + _parent_mod is None + or _parent_mod.__name__ == f"trl.trainer.{trainer_file}" + ): continue if hasattr(_parent_mod, RLConfig_name): RLConfig = getattr(_parent_mod, RLConfig_name) @@ -549,8 +557,13 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): try: _trainer_src = inspect.getsource(RLTrainer) _trainer_module = inspect.getmodule(RLTrainer) - _trainer_module_src = inspect.getsource(_trainer_module) if _trainer_module else "" - if "trl.experimental" in _trainer_src or "trl.experimental" in _trainer_module_src: + _trainer_module_src = ( + inspect.getsource(_trainer_module) if _trainer_module else "" + ) + if ( + "trl.experimental" in _trainer_src + or "trl.experimental" in _trainer_module_src + ): for _parent in RLTrainer.__mro__[1:]: if _parent is object: continue @@ -569,7 +582,10 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): _config_src = inspect.getsource(RLConfig) _config_module = inspect.getmodule(RLConfig) _config_module_src = inspect.getsource(_config_module) if _config_module else "" - if "trl.experimental" in _config_src or "trl.experimental" in _config_module_src: + if ( + "trl.experimental" in _config_src + or "trl.experimental" in _config_module_src + ): for _parent in RLConfig.__mro__[1:]: if _parent is object: continue @@ -1735,9 +1751,7 @@ def patch_trl_rl_trainers(): try: _patch_trl_rl_trainers(trainer) except Exception as e: - logger.warning_once( - f"Unsloth: Could not patch trl.trainer.{trainer}: {e}" - ) + logger.warning_once(f"Unsloth: Could not patch trl.trainer.{trainer}: {e}") return