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.

GRPO truncated-support gate test: lift the block that binds _support_kwargs (#15267)

Daniel Hanb9ae4e70c1d7
diff --git a/tests/test_grpo_truncated_support_policy_gate.py b/tests/test_grpo_truncated_support_policy_gate.py
index 717915385cd..c0dba35cdc1 100644
--- a/tests/test_grpo_truncated_support_policy_gate.py
+++ b/tests/test_grpo_truncated_support_policy_gate.py
@@ -29,6 +29,19 @@ _SOURCE_PATH = Path(__file__).resolve().parents[1] / "unsloth" / "models" / "rl_
_SUPPORT = {"support_top_k": 2, "support_top_p": 1.0, "support_min_p": 0.0}
+def _binds(node, name):
+ return any(
+ isinstance(target, ast.Name) and target.id == name
+ for n in ast.walk(node)
+ if isinstance(n, ast.Assign)
+ for target in n.targets
+ )
+
+
+def _reads_or_binds(node, name):
+ return any(isinstance(n, ast.Name) and n.id == name for n in ast.walk(node))
+
+
def _sources():
text = _SOURCE_PATH.read_text(encoding = "utf-8")
tree = ast.parse(text)
@@ -46,16 +59,18 @@ def _sources():
stmts = getattr(node, field, None)
if not isinstance(stmts, list):
continue
+ # Anchored on the try that binds _support_kwargs: an earlier try in the same body also
+ # imports grpo_truncated_support_kwargs (the UNSLOTH_GRPO_LOGPROB_RECOMPUTE scorer pick).
starts = [
i
for i, s in enumerate(stmts)
- if isinstance(s, ast.Try) and "grpo_truncated_support_kwargs" in ast.unparse(s)
+ if isinstance(s, ast.Try) and _binds(s, "_support_kwargs")
]
if not starts:
continue
block = []
for s in stmts[starts[0] :]:
- if "_support_kwargs" not in ast.unparse(s):
+ if not _reads_or_binds(s, "_support_kwargs"):
break
block.append(textwrap.dedent(ast.get_source_segment(text, s, padded = True)))
return "\n".join(helpers), "\n".join(block)