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.

RL class source: parse the code above a class with ast.parse, not a dynamic compile() (#16896)

Daniel Han7e4586c62c67
diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py
index ff7053da262..2c07c25aaa2 100644
--- a/unsloth/models/rl_replacements.py
+++ b/unsloth/models/rl_replacements.py
@@ -92,9 +92,7 @@ def _class_source(cls):
if lines[prev].startswith("@"):
return inspect.getsource(cls)
try:
- compile(
- "".join(lines[prev:start]), "<unsloth_class_source>", "exec", ast.PyCF_ONLY_AST
- )
+ ast.parse("".join(lines[prev:start]), "<unsloth_class_source>", "exec")
break
except SyntaxError:
continue