-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsngp_search.py
65 lines (52 loc) · 1.74 KB
/
sngp_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import submitit
import hydra
import optuna
import os
from omegaconf import DictConfig
def objective(trial: optuna.Trial, args: DictConfig):
args = args.copy()
from projects.IJCARS_2023.sngp import SNGP
args.exp_dir = os.path.join(args.exp_dir, f"trial_{trial.number}")
args.lr = trial.suggest_loguniform("lr", 1e-5, 1e-1)
args.weight_decay = trial.suggest_loguniform("weight_decay", 1e-7, 1e-2)
args.feature_scale = trial.suggest_loguniform("feature_scale", 1e-2, 10)
args.ridge_penalty = trial.suggest_loguniform("ridge_penalty", 1e-2, 10)
args.batch_size = trial.suggest_int("batch_size", 32, 128)
executor = submitit.AutoExecutor(args.exp_dir)
executor.update_parameters(
mem_gb=24,
cpus_per_task=16,
timeout_min=90,
slurm_gres="gpu:1",
slurm_partition="a40,t4v2,rtx6000",
)
f = SNGP(args)
job = executor.submit(f)
print(f"Submitted job: {job.job_id}")
print(f"Job stdout at: {job.paths.stdout}")
return job.result()
@hydra.main(config_path="config", config_name="sngp_sweep")
def main(args):
if not "optuna.db" in os.listdir():
print("Creating new study")
study = optuna.create_study(
direction="maximize",
sampler=optuna.samplers.TPESampler(),
storage="sqlite:///optuna.db",
study_name="sngp_sweep",
)
else:
print("Loading study from optuna.db")
study = optuna.load_study(
storage="sqlite:///optuna.db",
study_name="sngp_sweep",
)
from functools import partial
_objective = partial(objective, args=args)
study.optimize(
_objective,
n_trials=20,
n_jobs=4,
)
if __name__ == "__main__":
main()