This commit is contained in:
shengdinghu 2022-03-25 15:19:45 +08:00
parent bfbf5b1077
commit 5d2dab3284
4 changed files with 12 additions and 5 deletions

View File

@ -0,0 +1 @@
optuna

View File

@ -280,6 +280,7 @@ def main():
load_from_cache_file=not data_args.overwrite_cache,
)
train_dataset = concatenate_datasets(train_datasets)
print(f"Train dataset size {len(train_dataset)}")
if training_args.do_eval:
eval_datasets = {eval_dataset: AutoTask.get(eval_dataset, eval_dataset_config,

View File

@ -18,6 +18,7 @@ if __name__=="__main__":
parser.add_argument("--continue_study", type=bool, default=False)
parser.add_argument("--substudy_prefix", type=str, default="")
parser.add_argument("--num_trials", type=int)
parser.add_argument("--pathbase", type=str, default="")
args = parser.parse_args()
@ -27,7 +28,7 @@ if __name__=="__main__":
else:
args.study_name += pardir
setattr(args, "output_dir", f"outputs_search/{args.study_name}")
setattr(args, "output_dir", f"{args.pathbase}/outputs_search/{args.study_name}")
@ -68,7 +69,7 @@ if __name__=="__main__":
else:
sub_n_trials = args.num_trials//tot_chunk_num + args.num_trials%tot_chunk_num
command = "nohup python search_single.py "
command = "python search_single.py "
command += f"--cuda_id {cudas} "
command += f"--model_name {args.model_name} "
command += f"--dataset {args.dataset} "
@ -76,7 +77,7 @@ if __name__=="__main__":
command += f"--study_name {args.study_name} "
command += f"--optuna_seed 10{id} "
command += f"--num_trials {sub_n_trials} "
command += f">{args.output_dir}/{args.substudy_prefix}{id}.log 2>&1 &"
command += f"> {args.output_dir}/{args.substudy_prefix}{id}.log 2>&1 &"
p = subprocess.Popen(command, cwd="./", shell=True)
print("id {} on cuda:{}, pid {}\n {}\n".format(id, cudas, p.pid, command))

View File

@ -20,11 +20,14 @@ def objective_singleseed(args, unicode, search_space_sample ):
with open(f"{args.output_dir}/{unicode}/this_configs.json", 'w') as fout:
json.dump(search_space_sample, fout, indent=4,sort_keys=True)
command = "CUDA_VISIBLE_DEVICES={} ".format(args.cuda_id)
command += "python run.py "
command += f"{args.output_dir}/{unicode}/this_configs.json"
command += f" >> {args.output_dir}/{unicode}/output.log 2>&1"
print("======"*5+"\n"+command)
status_code = os.system(command)
print("status_code",status_code)
# if status_code != 0:
@ -61,7 +64,7 @@ def objective(trial, args=None):
search_space_sample.update(DatasetSearchSpace(args.dataset).get_config(trial, args))
search_space_sample.update(AllDeltaSearchSpace[args.delta_type]().get_config(trial, args))
results = []
for seed in [100]:
for seed in [42,43,44]:
search_space_sample.update({"seed": seed})
unicode = random.randint(0, 100000000)
while os.path.exists(f"{args.output_dir}/{unicode}"):
@ -84,10 +87,11 @@ if __name__=="__main__":
parser.add_argument("--study_name")
parser.add_argument("--num_trials", type=int)
parser.add_argument("--optuna_seed", type=int, default="the seed to sample suggest point")
parser.add_argument("--pathbase", type=str, default="")
args = parser.parse_args()
setattr(args, "output_dir", f"outputs_search/{args.study_name}")
setattr(args, "output_dir", f"{args.pathbase}/outputs_search/{args.study_name}")
study = optuna.load_study(study_name=args.study_name, storage=f'sqlite:///{args.study_name}.db', sampler=TPESampler(seed=args.optuna_seed))
study.optimize(partial(objective, args=args), n_trials=args.num_trials)