Skip to content

Commit

Permalink
Add --try_auto_save_to_beaker arg (#505)
Browse files Browse the repository at this point in the history
* Add `--try_auto_save_to_beaker` arg

* push changes
  • Loading branch information
vwxyzjn authored Jan 9, 2025
1 parent c00cf71 commit a3ea937
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
9 changes: 6 additions & 3 deletions open_instruct/dpo_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import math
import os
import random
import shutil
import subprocess
import time
from copy import deepcopy
Expand Down Expand Up @@ -365,6 +366,8 @@ class FlatArguments:
default=0.001,
metadata={"help": "Weight for load balancing loss if applicable."},
)
try_auto_save_to_beaker: bool = True
"""Whether to try to save the model to Beaker dataset `/output` after training"""
push_to_hub: bool = True
"""Whether to upload the saved model to huggingface"""
hf_entity: Optional[str] = None
Expand Down Expand Up @@ -487,9 +490,6 @@ def main(args: FlatArguments):

if is_beaker_job():
beaker_config = maybe_get_beaker_config()
# try saving to the beaker `/output`, which will be uploaded to the beaker dataset
if len(beaker_config.beaker_dataset_id_urls) > 0:
args.output_dir = "/output"

accelerator_log_kwargs = {}

Expand Down Expand Up @@ -1119,6 +1119,9 @@ def load_model():
if accelerator.is_local_main_process:
clean_last_n_checkpoints(args.output_dir, keep_last_n_checkpoints=0)

if args.try_auto_save_to_beaker and accelerator.is_main_process == 0 and len(beaker_config.beaker_dataset_id_urls) > 0 and args.output_dir != "/output":
shutil.copytree(args.output_dir, "/output", dirs_exist_ok=True)

if is_beaker_job() and accelerator.is_main_process:
# dpo script only supports these two options right now for datasets
if args.dataset_mixer:
Expand Down
9 changes: 6 additions & 3 deletions open_instruct/dpo_tune_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import math
import os
import random
import shutil
import subprocess
import time
from dataclasses import dataclass, field
Expand Down Expand Up @@ -375,6 +376,8 @@ class FlatArguments:
)
concatenated_forward: bool = True
"""Whether to concatenate chosen and rejected for DPO training; True is good but you can set to False for saving memory."""
try_auto_save_to_beaker: bool = True
"""Whether to try to save the model to Beaker dataset `/output` after training"""
push_to_hub: bool = True
"""Whether to upload the saved model to huggingface"""
hf_entity: Optional[str] = None
Expand Down Expand Up @@ -501,9 +504,6 @@ def main(args: FlatArguments):

if is_beaker_job():
beaker_config = maybe_get_beaker_config()
# try saving to the beaker `/output`, which will be uploaded to the beaker dataset
if len(beaker_config.beaker_dataset_id_urls) > 0:
args.output_dir = "/output"

accelerator_log_kwargs = {}

Expand Down Expand Up @@ -1139,6 +1139,9 @@ def load_model():
if accelerator.is_local_main_process:
clean_last_n_checkpoints(args.output_dir, keep_last_n_checkpoints=0)

if args.try_auto_save_to_beaker and accelerator.is_main_process == 0 and len(beaker_config.beaker_dataset_id_urls) > 0 and args.output_dir != "/output":
shutil.copytree(args.output_dir, "/output", dirs_exist_ok=True)

if is_beaker_job() and accelerator.is_main_process:
# dpo script only supports these two options right now for datasets
if args.dataset_mixer:
Expand Down
9 changes: 6 additions & 3 deletions open_instruct/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import math
import os
import random
import shutil
import subprocess
import time
from dataclasses import dataclass, field
Expand Down Expand Up @@ -337,6 +338,8 @@ class FlatArguments:
default=0.5,
metadata={"help": "Weight for load balancing loss if applicable."},
)
try_auto_save_to_beaker: bool = True
"""Whether to try to save the model to Beaker dataset `/output` after training"""
push_to_hub: bool = True
"""Whether to upload the saved model to huggingface"""
hf_entity: Optional[str] = None
Expand Down Expand Up @@ -471,9 +474,6 @@ def main(args: FlatArguments):

if is_beaker_job():
beaker_config = maybe_get_beaker_config()
# try saving to the beaker `/output`, which will be uploaded to the beaker dataset
if len(beaker_config.beaker_dataset_id_urls) > 0:
args.output_dir = "/output"

accelerator_log_kwargs = {}

Expand Down Expand Up @@ -1033,6 +1033,9 @@ def main(args: FlatArguments):
if accelerator.is_local_main_process:
clean_last_n_checkpoints(args.output_dir, keep_last_n_checkpoints=0)

if args.try_auto_save_to_beaker and accelerator.is_main_process == 0 and len(beaker_config.beaker_dataset_id_urls) > 0 and args.output_dir != "/output":
shutil.copytree(args.output_dir, "/output", dirs_exist_ok=True)

if is_beaker_job() and accelerator.is_main_process:
# dpo script only supports these two options right now for datasets
if args.dataset_mixer:
Expand Down
4 changes: 3 additions & 1 deletion open_instruct/ppo_vllm_thread_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ class Args:
"""Whether to launch beaker evaluation jobs after training"""
try_launch_beaker_eval_jobs_on_weka: bool = False
"""Whether to launch beaker evaluation jobs after training on weka"""
try_auto_save_to_beaker: bool = True
"""Whether to try to save the model to Beaker dataset `/output` after training"""
oe_eval_tasks: Optional[List[str]] = None
"""The beaker evaluation tasks to launch"""
hf_metadata_dataset: Optional[str] = "allenai/tulu-3-evals"
Expand Down Expand Up @@ -1300,7 +1302,7 @@ def vllm_generate(

# Ai2 logic: we use /output to store the artifacts of the job, so we
# make a copy of the model to `/output` in the end.
if self.rank == 0 and len(self.beaker_config.beaker_dataset_id_urls) > 0:
if args.try_auto_save_to_beaker and self.rank == 0 and len(self.beaker_config.beaker_dataset_id_urls) > 0 and args.output_dir != "/output":
shutil.copytree(args.output_dir, "/output", dirs_exist_ok=True)
print("finished training")

Expand Down
4 changes: 3 additions & 1 deletion open_instruct/ppo_vllm_thread_ray_gtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class Args:
"""Whether to launch beaker evaluation jobs after training"""
try_launch_beaker_eval_jobs_on_weka: bool = False
"""Whether to launch beaker evaluation jobs after training on weka"""
try_auto_save_to_beaker: bool = True
"""Whether to try to save the model to Beaker dataset `/output` after training"""
oe_eval_tasks: Optional[List[str]] = None
"""The beaker evaluation tasks to launch"""
hf_metadata_dataset: Optional[str] = "allenai/tulu-3-evals"
Expand Down Expand Up @@ -1375,7 +1377,7 @@ def vllm_generate(

# Ai2 logic: we use /output to store the artifacts of the job, so we
# make a copy of the model to `/output` in the end.
if self.rank == 0 and len(self.beaker_config.beaker_dataset_id_urls) > 0:
if args.try_auto_save_to_beaker and self.rank == 0 and len(self.beaker_config.beaker_dataset_id_urls) > 0 and args.output_dir != "/output":
shutil.copytree(args.output_dir, "/output", dirs_exist_ok=True)
print("finished training")

Expand Down

0 comments on commit a3ea937

Please sign in to comment.