Update rl.py
This commit is contained in:
parent
e59e196448
commit
8506d6be95
1 changed files with 9 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue