Update rl.py

This commit is contained in:
Daniel Han 2025-02-05 05:45:05 -08:00
commit d34f2ff23f

View file

@ -39,10 +39,9 @@ def PatchRL(FastLanguageModel):
@contextmanager
def unsloth_unwrap_model_for_generation(model, *args, **kwargs):
# Must use for_inference to allow inference in Unsloth
FastLanguageModel.for_inference(model)
with torch.inference_mode():
with unwrap_model_for_generation(model, *args, **kwargs) as unwrapped_model:
yield unwrapped_model
with unwrap_model_for_generation(model, *args, **kwargs) as unwrapped_model:
FastLanguageModel.for_inference(unwrapped_model)
yield unwrapped_model
# Return back to training mode
FastLanguageModel.for_training (model)
pass