forked from huawei-noah/HEBO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robust_opt_topology.sh
177 lines (149 loc) · 6.71 KB
/
robust_opt_topology.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#-- Common parameters for topology task -#
property_key='scores'
weight_type="rank"
data_seed=0
n_data=100000
use_full_data_for_gp="" # "--use_full_data_for_gp" # ""
samples_per_model=1000
n_retrain_epochs=1
test_dir=""
use_test_set="" # "--use_test_set"
#-- Fit variational GP on a subset of the visible dataset --#
n_inducing_points=500
n_best_points=2500
n_rand_points=500
#################################### SETUP ####################################
batch_size=256
# if several trainings have been launched with similar setups, pytorch_lightning have saved models in directories
# `version_0`, `version_1`,... so the model version shall be specified here (0 by default)
version=0
r=50 # retrain VAE every $r steps
k="1e-3" # factor for weighted retraining
#-- Choose covariance function for the GP --#
covar_name_ind=1
covar_names=('matern-5/2' 'rbf')
covar_name=${covar_names[$covar_name_ind]}
#-- Choose dimension of the latent space --#
latent_dim=20
#-- Choose acquisition function --#
acq_ind=1
acq_func_ids=(
'ExpectedImprovement'
'ErrorAwareEI'
'ErrorAwareUCB'
)
gamma=1
eps=10
beta=2
config="ratio"
acq_func_kwargs_s=(
"{}"
"{'gamma':$gamma,'eps':$eps,'configuration':'$config'}"
"{'gamma':$gamma,'eps':$eps,'beta':$beta,'configuration':'$config'}"
)
acq_func_id=${acq_func_ids[$acq_ind]}
acq_func_kwargs=${acq_func_kwargs_s[$acq_ind]}
acq_func_opt_kwargs_s=("{'batch_limit':100}" "{'batch_limit':50,'maxiter':500}")
acq_func_opt_kwargs=${acq_func_opt_kwargs_s[$acq_ind]}
cost_aware_gamma_sched_ind=0
cost_aware_gamma_scheds=(
''
'--cost_aware_gamma_sched fixed'
'--cost_aware_gamma_sched linear'
'--cost_aware_gamma_sched exponential'
'--cost_aware_gamma_sched reverse_exponential'
'--cost_aware_gamma_sched post_obj_var'
'--cost_aware_gamma_sched post_obj_inv_var'
'--cost_aware_gamma_sched post_err_var'
'--cost_aware_gamma_sched post_min_var'
'--cost_aware_gamma_sched post_var_tradeoff'
'--cost_aware_gamma_sched post_var_inv_tradeoff')
cost_aware_gamma_sched=${cost_aware_gamma_scheds[$cost_aware_gamma_sched_ind]}
test_gp_error_fit='' #'--test_gp_error_fit'
estimate_rec_error=0
if ((estimate_rec_error == 0)); then estimate_rec_error=''; else estimate_rec_error='--estimate_rec_error'; fi
#-- Choose whether to use input warping --#
input_wp=0
if ((input_wp == 1)); then acq_func_opt_kwargs="{'batch_limit':50,'maxiter':500,'clip_gradient':1,'clip_value':10.,'jitter':1e-3}"; else acq_func_opt_kwargs=${acq_func_opt_kwargs_s[$acq_ind]}; fi
if ((input_wp == 0)); then input_wp=''; else input_wp='--input_wp'; fi
#-- Choose whether to use target prediction --#
predict_target=0
beta_target_pred_loss=10
target_predictor_hdims='[128,128]'
if ((predict_target == 0)); then predict_target=''; else predict_target='--predict_target'; fi
#-- Choose the metric loss you want to use -- (default contrastive: 1, default triplet: 2) --#
metric_loss_ind=1
metric_losses=('' 'contrastive' 'triplet' 'triplet')
metric_loss_kws=("" "{'threshold':.1}" "{'threshold':.1,'soft':True}" "{'threshold':.1,'soft':True,'eta':0.05}")
beta_metric_loss_s=(1 1 1 1)
if ((metric_loss_ind == 0)); then metric_loss=''; else metric_loss="--metric_loss ${metric_losses[$metric_loss_ind]}"; fi
if ((metric_loss_ind == 0)); then metric_loss_kw=''; else metric_loss_kw="--metric_loss_kw ${metric_loss_kws[$metric_loss_ind]}"; fi
beta_metric_loss="${beta_metric_loss_s[$metric_loss_ind]}"
n_init_retrain_epochs=1
# KL coef in ELBO
beta_final=0.0001 # same as in train-topology.sh
#-- Choose semi-supervised or fully-supervised setup --#
semi_supervised=0
n_init_bo_points=105
if ((semi_supervised_ind == 0)); then semi_supervised=''; else semi_supervised='--semi_supervised'; fi
if ((semi_supervised_ind == 0)); then query_budget=500; else query_budget=1000; fi
if ((semi_supervised_ind == 0)); then n_init_bo_points=''; else n_init_bo_points="--n_init_bo_points ${n_init_bo_points}"; fi
use_binary_data=1
if ((use_binary_data == 1)); then use_binary_data='--use_binary_data'; else use_binary_data=''; fi
#-- Choose whether to use BO or random search --#
lso_strategy_ind=0
lso_strategies=("opt" "random_search")
lso_strategy="${lso_strategies[$lso_strategy_ind]}"
#-- If random search is chosen for optimisation, choose standard (0) or qMC (1)
random_search_type_ind=1
random_search_types=("" "--random_search_type sobol")
random_search_type="${random_search_types[$random_search_type_ind]}"
#-- How many epochs have been used for VAE training --#
training_max_epochs=300
#-- Run on the following seeds (repeat so that it restarts - not from scratch - after a potential crash)
seed_array=(0 1 2 3 4 0 1 2 3 4)
#-- Choose on which GPU to run --#
cuda=0
##############################################################################
expt_index=0 # Track experiments
for seed in "${seed_array[@]}"; do
# Increment experiment index
expt_index=$((expt_index + 1))
# Break loop if using slurm and it's not the right task
if [[ -n "${SLURM_ARRAY_TASK_ID}" ]] && [[ "${SLURM_ARRAY_TASK_ID}" != "$expt_index" ]]; then
continue
fi
echo "r=${r} k=${k} seed=${seed}"
# Run command
cmd="python weighted_retraining/weighted_retraining/robust_opt_scripts/robust_opt_topology.py \
--seed=$seed \
--query_budget=$query_budget \
--retraining_frequency=$r \
--version $version \
--property_key $property_key \
--lso_strategy=$lso_strategy \
$random_search_type --n_retrain_epochs=$n_retrain_epochs \
--n_init_retrain_epochs=$n_init_retrain_epochs \
--n_best_points=$n_best_points --n_rand_points=$n_rand_points $use_full_data_for_gp --n_inducing_points=$n_inducing_points \
--weight_type=$weight_type --rank_weight_k=$k \
--samples_per_model=$samples_per_model \
--batch_size $batch_size \
--covar-name $covar_name \
--acq-func-id $acq_func_id \
--acq-func-kwargs $acq_func_kwargs \
--acq-func-opt-kwargs $acq_func_opt_kwargs \
--beta_metric_loss $beta_metric_loss --beta_final $beta_final \
--beta_target_pred_loss $beta_target_pred_loss \
--data_seed $data_seed $estimate_rec_error \
--training_max_epochs $training_max_epochs \
--cuda $cuda $use_test_set \
$input_wp $raw_initial_samples \
$predict_target $use_binary_data \
--target_predictor_hdims $target_predictor_hdims $metric_loss \
$metric_loss_kw \
$test_gp_error_fit $cost_aware_gamma_sched \
--latent_dim $latent_dim $semi_supervised $n_init_bo_points"
$cmd
echo $cmd
done