forked from McGill-NLP/length-generalization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual_sweep_agent.sh
96 lines (78 loc) · 2.93 KB
/
manual_sweep_agent.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
#!/bin/bash
# Assert $SWEEP_CONFIGS is set
if [ -z "$SWEEP_CONFIGS" ]; then
echo "SWEEP_CONFIGS is not set"
exit 1
fi
# Assert $SWEEP_NAME is set
if [ -z "$SWEEP_NAME" ]; then
echo "SWEEP_NAME is not set"
exit 1
fi
# Exit when any command fails
set -e
export APP_LAUNCHED_BY_MANUAL_SWEEPER=1
export APP_MANUAL_SWEEP=1
python scripts/manual_sweep.py \
--sweep_name $SWEEP_NAME \
--sweep_root_dir $SWEEP_ROOT_DIR \
--sweep_configs $SWEEP_CONFIGS \
dump_sweep_config_obj
# Create sweep config files
# This script dumps the config files into $SWEEP_ROOT_DIR/hyperparameters dir
python scripts/manual_sweep.py \
--sweep_name $SWEEP_NAME \
--sweep_root_dir $SWEEP_ROOT_DIR \
--sweep_configs $SWEEP_CONFIGS \
create_exp_configs --sweep-configs $SWEEP_CONFIGS
SWEEP_PROGRAM=$(python scripts/read_json_field.py "sweep_cfg.json" "program")
chmod +x $SWEEP_PROGRAM
mkdir -p $SWEEP_ROOT_DIR/exps
mkdir -p $SWEEP_ROOT_DIR/console_logs
shopt -s nullglob
# Iterate over $SWEEP_ROOT_DIR/hyperparameters and run the experiments
for CONFIG_FILE in $SWEEP_ROOT_DIR/hyperparameters/*.json; do
RUN_NAME=$(basename $CONFIG_FILE .json)
HP_EXP_DIR=$SWEEP_ROOT_DIR/exps/$RUN_NAME
mkdir -p $HP_EXP_DIR
is_complete=$(python scripts/manual_sweep.py \
--sweep_name $SWEEP_NAME \
--sweep_root_dir $SWEEP_ROOT_DIR \
--sweep_configs $SWEEP_CONFIGS \
is_hp_run_complete --run_name $RUN_NAME)
if [ "$is_complete" == "True" ]; then
echo "=========> [Manual Sweeper] Skipping $RUN_NAME as it is already complete"
continue
fi
echo "=========> [Manual Sweeper] Running $RUN_NAME"
RUN_ID=$(python scripts/manual_sweep.py \
--sweep_name $SWEEP_NAME \
--sweep_root_dir $SWEEP_ROOT_DIR \
--sweep_configs $SWEEP_CONFIGS \
generate_deterministic_run_id --run_name $RUN_NAME)
if [ -z "$CAPTURE_LOG" ]; then
APP_MANUAL_SWEEP_HYPERPARAMETER_FILE=$CONFIG_FILE APP_SWEEP_ROOT_DIR=$SWEEP_ROOT_DIR RUN_ID=$RUN_ID ./$SWEEP_PROGRAM
else
stderr_file=$SWEEP_ROOT_DIR/console_logs/"${RUN_NAME}_stderr.log"
stdout_file=$SWEEP_ROOT_DIR/console_logs/"${RUN_NAME}_stdout.log"
touch $stderr_file
touch $stdout_file
echo "=========> [Manual Sweeper] Capturing console logs to $stderr_file and $stdout_file"
APP_MANUAL_SWEEP_HYPERPARAMETER_FILE=$CONFIG_FILE APP_SWEEP_ROOT_DIR=$SWEEP_ROOT_DIR RUN_ID=$RUN_ID ./$SWEEP_PROGRAM 2>$stderr_file 1>$stdout_file
fi
done
shopt -u nullglob
# Check if the SWEEP_CONFIGS was not equal to 'configs/sweeps/no_sweep.jsonnet
# If it was, then we don't need to run the sweep completion script
if [ "$SWEEP_CONFIGS" != "configs/sweeps/no_sweep.jsonnet" ]; then
python scripts/manual_sweep.py \
--sweep_name $SWEEP_NAME \
--sweep_root_dir $SWEEP_ROOT_DIR \
--sweep_configs $SWEEP_CONFIGS \
fail_if_sweep_not_complete
python scripts/manual_sweep.py \
--sweep_name $SWEEP_NAME \
--sweep_root_dir $SWEEP_ROOT_DIR \
--sweep_configs $SWEEP_CONFIGS \
save_best_config
fi