From 8506d6be95a074b1e48dc6b7494cc374e71b7753 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Wed, 5 Feb 2025 06:56:12 -0800 Subject: [PATCH] Update rl.py --- unsloth/models/rl.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 72b911acbb..72b568790d 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -39,13 +39,15 @@ def PatchRL(FastLanguageModel): @contextmanager def unsloth_unwrap_model_for_generation(model, accelerator): # Must use for_inference to allow inference in Unsloth - with unwrap_model_for_generation(model, accelerator) as unwrapped_model: - FastLanguageModel.for_inference(unwrapped_model) - try: - yield unwrapped_model - finally: - # Finally return back training - FastLanguageModel.for_training(model) + with torch.inference_mode(): + with unwrap_model_for_generation(model, accelerator) as unwrapped_model: + FastLanguageModel.for_inference(unwrapped_model) + try: + yield unwrapped_model + finally: + # Finally return back training + FastLanguageModel.for_training(model) + pass pass pass pass