Skip to content

Commit

Permalink
Push changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vwxyzjn committed Oct 10, 2024
1 parent f0b3def commit 80dfb30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
33 changes: 23 additions & 10 deletions open_instruct/dpo_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class FlatArguments:

exp_name: str = os.path.basename(__file__)[: -len(".py")]
"""The name of this experiment"""
run_name: Optional[str] = None
"""A unique name of this run"""
model_name_or_path: Optional[str] = field(
default=None,
metadata={
Expand Down Expand Up @@ -470,6 +472,7 @@ def main(args: FlatArguments):
# Initialize the accelerator. We will let the accelerator handle device placement for us in this example.
# If we're using tracking, we also need to initialize it here and it will by default pick up all supported trackers
# in the environment
args.run_name = f"{args.exp_name}__{args.model_name_or_path.replace('/', '_')}__{args.seed}__{int(time.time())}"
if args.push_to_hub:
if args.hf_repo_id is None: # auto-generate one
args.hf_repo_id = "open_instruct_dev"
Expand All @@ -478,12 +481,16 @@ def main(args: FlatArguments):
if args.hf_entity is None: # then try to use the user's entity
args.hf_entity = HfApi().whoami()["name"]
args.hf_repo_id = f"{args.hf_entity}/{args.hf_repo_id}"
if args.hf_repo_revision is None: # auto-generate one
args.hf_repo_revision = (
f"{args.exp_name}__{args.model_name_or_path.replace('/', '_')}__{args.seed}__{int(time.time())}"
)
if args.hf_repo_revision is None:
args.hf_repo_revision = args.run_name
args.hf_repo_url = f"https://huggingface.co/{args.hf_repo_id}/tree/{args.hf_repo_revision}"

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 = {}

if args.with_tracking:
Expand Down Expand Up @@ -873,8 +880,6 @@ def load_model():

# We need to initialize the trackers we use, and also store our configuration.
# The trackers initializes automatically on the main process.
if is_beaker_job():
beaker_config = maybe_get_beaker_config()
if args.with_tracking:
experiment_config = vars(args)
# TensorBoard cannot log Enums, need the raw value
Expand All @@ -883,11 +888,18 @@ def load_model():
# (Optional) Ai2 internal tracking
if args.wandb_entity is None:
args.wandb_entity = maybe_use_ai2_wandb_entity()
if is_beaker_job():
experiment_config.update(vars(beaker_config))
accelerator.init_trackers(
"open_instruct_internal",
experiment_config,
init_kwargs={"wandb": {"entity": args.wandb_entity, "tags": [args.exp_name] + get_wandb_tags()}},
init_kwargs={
"wandb": {
"name": args.run_name,
"entity": args.wandb_entity,
"tags": [args.exp_name] + get_wandb_tags(),
}
},
)
wandb_tracker = accelerator.get_tracker("wandb")

Expand Down Expand Up @@ -1128,16 +1140,17 @@ def load_model():
"beaker_experiment": beaker_config.beaker_experiment_url,
"beaker_datasets": beaker_config.beaker_dataset_id_urls,
}
# save in the output directory
# save metadata to the output directory. then it should also get pushed to HF.
with open(os.path.join(args.output_dir, "metadata.json"), "w") as f:
json.dump(metadata_blob, f)

# upload metadata to the dataset if set
if args.hf_metadata_dataset:
upload_metadata_to_hf(
metadata_blob,
"metadata.json",
args.hf_metadata_dataset,
"results/" + args.hf_repo_revision, # to match what the auto-evals name as.
"results/" + args.run_name, # to match what the auto-evals name as.
)

if args.try_launch_beaker_eval_jobs:
Expand All @@ -1152,7 +1165,7 @@ def load_model():
--pure_docker_mode \
--gpus 0 -- python scripts/wait_beaker_dataset_model_upload_then_evaluate_model.py \
--beaker_workload_id {beaker_config.beaker_workload_id} \
--model_name {args.hf_repo_revision}
--model_name {args.run_name}
"""
process = subprocess.Popen(["bash", "-c", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
Expand Down
30 changes: 21 additions & 9 deletions open_instruct/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class FlatArguments:

exp_name: str = os.path.basename(__file__)[: -len(".py")]
"""The name of this experiment"""
run_name: Optional[str] = None
"""A unique name of this run"""
model_name_or_path: Optional[str] = field(
default=None,
metadata={
Expand Down Expand Up @@ -454,6 +456,7 @@ def main(args: FlatArguments):
# Initialize the accelerator. We will let the accelerator handle device placement for us in this example.
# If we're using tracking, we also need to initialize it here and it will by default pick up all supported trackers
# in the environment
args.run_name = f"{args.exp_name}__{args.model_name_or_path.replace('/', '_')}__{args.seed}__{int(time.time())}"
if args.push_to_hub:
if args.hf_repo_id is None: # auto-generate one
args.hf_repo_id = "open_instruct_dev"
Expand All @@ -462,12 +465,16 @@ def main(args: FlatArguments):
if args.hf_entity is None: # then try to use the user's entity
args.hf_entity = HfApi().whoami()["name"]
args.hf_repo_id = f"{args.hf_entity}/{args.hf_repo_id}"
if args.hf_repo_revision is None: # auto-generate one
args.hf_repo_revision = (
f"{args.exp_name}__{args.model_name_or_path.replace('/', '_')}__{args.seed}__{int(time.time())}"
)
if args.hf_repo_revision is None:
args.hf_repo_revision = args.run_name
args.hf_repo_url = f"https://huggingface.co/{args.hf_repo_id}/tree/{args.hf_repo_revision}"

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 = {}

if args.with_tracking:
Expand Down Expand Up @@ -819,8 +826,6 @@ def main(args: FlatArguments):

# We need to initialize the trackers we use, and also store our configuration.
# The trackers initializes automatically on the main process.
if is_beaker_job():
beaker_config = maybe_get_beaker_config()
if args.with_tracking:
experiment_config = vars(args)
# TensorBoard cannot log Enums, need the raw value
Expand All @@ -829,11 +834,18 @@ def main(args: FlatArguments):
# (Optional) Ai2 internal tracking
if args.wandb_entity is None:
args.wandb_entity = maybe_use_ai2_wandb_entity()
if is_beaker_job():
experiment_config.update(vars(beaker_config))
accelerator.init_trackers(
"open_instruct_internal",
experiment_config,
init_kwargs={"wandb": {"entity": args.wandb_entity, "tags": [args.exp_name] + get_wandb_tags()}},
init_kwargs={
"wandb": {
"name": args.run_name,
"entity": args.wandb_entity,
"tags": [args.exp_name] + get_wandb_tags(),
}
},
)
wandb_tracker = accelerator.get_tracker("wandb")

Expand Down Expand Up @@ -1052,7 +1064,7 @@ def main(args: FlatArguments):
metadata_blob,
"metadata.json",
args.hf_metadata_dataset,
"results/" + args.hf_repo_revision, # to match what the auto-evals name as.
"results/" + args.run_name, # to match what the auto-evals name as.
)

if args.try_launch_beaker_eval_jobs:
Expand All @@ -1067,7 +1079,7 @@ def main(args: FlatArguments):
--pure_docker_mode \
--gpus 0 -- python scripts/wait_beaker_dataset_model_upload_then_evaluate_model.py \
--beaker_workload_id {beaker_config.beaker_workload_id} \
--model_name {args.hf_repo_revision}
--model_name {args.run_name}
"""
process = subprocess.Popen(["bash", "-c", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
Expand Down

0 comments on commit 80dfb30

Please sign in to comment.