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.

Update rl.py

Daniel Han7dfd171c553f
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index 2aa8f026597..2bd602e0995 100644
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -21,11 +21,12 @@ def PatchRL(FastLanguageModel):
from trl.models.utils import unwrap_model_for_generation
from contextlib import contextmanager
-
+
@contextmanager
def unsloth_unwrap_model_for_generation(model, *args, **kwargs):
FastLanguageModel.for_inference(model)
- yield unwrap_model_for_generation(model, *args, **kwargs)
+ with unwrap_model_for_generation(model, *args, **kwargs) as unwrapped_model:
+ yield unwrapped_model
FastLanguageModel.for_training (model)
pass