From ca826bc3d8f712eaf24a0fe698285746ad167e62 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 31 May 2026 12:59:12 +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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 8374920e75..82ef7b48d2 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -728,16 +728,20 @@ def _install_grpo_lm_head_passthrough(model): if lm_head is None: get_output_embeddings = getattr(head, "get_output_embeddings", None) if callable(get_output_embeddings): - try: lm_head = get_output_embeddings() - except Exception: lm_head = None + try: + lm_head = get_output_embeddings() + except Exception: + lm_head = None if lm_head is None or getattr(lm_head, "_unsloth_grpo_passthrough", False): return False original_lm_head_forward = lm_head.forward + def passthrough_forward(*args, **kwargs): if os.environ.get("UNSLOTH_RETURN_HIDDEN_STATES", "0") == "1": return args[0] if args else next(iter(kwargs.values())) return original_lm_head_forward(*args, **kwargs) + lm_head.forward = passthrough_forward lm_head._unsloth_grpo_passthrough = True setattr(model, _UNSLOTH_RETURN_HIDDEN_STATES_SUPPORT_MARKER, True)