From de6c777442bb0a35ebe0a27cbd992bd782ab3929 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:33:26 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/models/_utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 1fcab917ba..2365975cdd 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -239,6 +239,7 @@ def _unsloth_reset_stray_compile_cache(self): # Module-level (not just inside the RL trainer template) so the SFT auto-packing wrapper and # the plain-Trainer loop can import and run it too. import os + model = getattr(self, "model", None) if model is None: return @@ -270,7 +271,9 @@ def _unsloth_reset_stray_compile_cache(self): except Exception: pass try: - from unsloth_zoo.gradient_checkpointing import reset_unsloth_gradient_checkpointing_buffers + from unsloth_zoo.gradient_checkpointing import ( + reset_unsloth_gradient_checkpointing_buffers, + ) reset_unsloth_gradient_checkpointing_buffers() except Exception: pass @@ -279,6 +282,7 @@ def _unsloth_reset_stray_compile_cache(self): except Exception: pass import warnings + warnings.warn( "Unsloth: detected a manual forward/backward run before trainer.train(); " "reset the torch.compile graph cache it poisoned so training starts clean. " @@ -288,8 +292,10 @@ def _unsloth_reset_stray_compile_cache(self): for _m in markers: hook = _m.pop("hook", None) if hook is not None: - try: hook.remove() - except Exception: pass + try: + hook.remove() + except Exception: + pass _m["seen"] = False