Skip to content

Instantly share code, notes, and snippets.

@piercelamb
Created December 19, 2022 23:06
Show Gist options
  • Save piercelamb/eeaa8dc02d967852f8cf1f81b6cbce1d to your computer and use it in GitHub Desktop.
Save piercelamb/eeaa8dc02d967852f8cf1f81b6cbce1d to your computer and use it in GitHub Desktop.
write_train_files
if not is_tuning_job:
# this is a training job, just upload
write_experiment_results(files_to_be_uploaded, s3_run_dir)
else:
# this is a tuning job, the run dir should only have the best result
if folder_exists(bucket, s3_run_dir):
temp_file = os.path.join(os.getcwd(), 'remote_best_model_stats.json')
s3_path = os.path.join(s3_run_dir, 'best_model_stats.json')
bucket.download_file(s3_path, temp_file)
with open(temp_file) as f:
remote_model_stats = json.load(f)
with open(local_best_model_stats) as f:
local_model_stats = json.load(f)
remote_f1 = remote_model_stats["best_valid_f1"]
local_f1 = local_model_stats["best_valid_f1"]
if local_f1 > remote_f1:
write_experiment_results(files_to_be_uploaded, s3_run_dir)
else:
# no tuning job has written yet
write_experiment_results(files_to_be_uploaded, s3_run_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment