forked from trxcc/Offline-RaM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
65 lines (58 loc) · 1.58 KB
/
run.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
tasks="AntMorphology-Exact-v0 DKittyMorphology-Exact-v0 Superconductor-RandomForest-v0 TFBind8-Exact-v0 TFBind10-Exact-v0"
losses="listnet"
MAX_JOBS=8
AVAILABLE_GPUS="0 1 2 3"
MAX_RETRIES=0
get_gpu_allocation() {
local job_number=$1
local gpus=($AVAILABLE_GPUS)
local num_gpus=${#gpus[@]}
local gpu_id=$((job_number % num_gpus))
echo ${gpus[gpu_id]}
}
check_jobs() {
while true; do
jobs_count=$(jobs -p | wc -l)
if [ "$jobs_count" -lt "$MAX_JOBS" ]; then
break
fi
sleep 1
done
}
run_with_retry() {
local script=$1
local gpu_allocation=$2
local attempt=0
echo $gpu_allocation
while [ $attempt -le $MAX_RETRIES ]; do
# Run the Python script
CUDA_VISIBLE_DEVICES=$gpu_allocation python $script
status=$?
if [ $status -eq 0 ]; then
echo "Script $script succeeded."
break
else
echo "Script $script failed on attempt $attempt. Retrying..."
((attempt++))
fi
done
if [ $attempt -gt $MAX_RETRIES ]; then
echo "Script $script failed after $MAX_RETRIES attempts."
fi
}
for task in $tasks; do
for loss in $losses; do
for seed in {1..8}; do
check_jobs
gpu_allocation=$(get_gpu_allocation $job_number)
((job_number++))
run_with_retry "main.py \
--task=${task} \
--loss=${loss} \
--expt-name=RaM \
--seed=${seed}" \
"$gpu_allocation" &
done
done
done
wait