-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·352 lines (296 loc) · 9.76 KB
/
Copy pathsetup
File metadata and controls
executable file
·352 lines (296 loc) · 9.76 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/usr/bin/env bash
# ======================
# 0. Machine + Runtime
# ======================
#Machine="LEONARDO" # on LEONARDO
Machine="LEONARDO" # on HAL
current_ntasks=1 # Better to keep zero
current_cpus=16 # On LEONARDO
#current_cpus=4 # On HAL
current_workers=16 # On LEONARDO
#current_workers=4 # On HAL
debug="Flase" # True or False
#DATA_PATH="/leonardo_work/EUHPC_D27_095/Data_LSM_1995-2000_Large" # Path to the dataset on LEONARDO
DATA_PATH="/net/nfs/ssd1/kardaneh/Data_LSM_1995-2000_Large" # Path to the dataset on HAL
CAMS_TRAIN_DATA_PATH="/leonardo_work/EUHPC_D27_095/CAMS/RADSCHEME_data_g224_CAMS_2009-2018_sans_2014-2015.nc" # Path to the dataset on LEONARDO
CAMS_Test_DATA_PATH="/leonardo_work/EUHPC_D27_095/CAMS/RADSCHEME_data_g224_CAMS_2014.nc" # Path to the dataset on LEONARDO
# ======================
# 1. Model Configuration
# ======================
type="encodertorch" # options: "lstm", "gru", "fcn", "transformer", "encodertorch", "pinn", "mlp", "mlp_residual".
hidden_size=256
# NUMBER OF LAYERS
# ----------------
# num_layers = 3
#
# Rule of thumb: num_layers = 2 to 6 for sequence length 10
# More layers = more capacity but slower training and more overfitting risk
#
# Formula: num_layers ≈ log2(seq_length) + 1 = log2(10) + 1 ≈ 3.3 + 1 = 4.3 (rounded to 4)
# but with dropout, 2-3 is often sufficient for this problem size
#
# Recommended range: 2-4
num_layers=3
output_channel=2
seq_length=60
feature_channel=11
# EMBEDDING SIZE
# ---------------
# embed_size = 256
#
# Rule of thumb: embed_size should be between input and output dimensions
# input=121, output=120 → embed_size=256 is a good balance
#
# Formula: embed_size = 2 × max(input, output) = 2 × 121 = 242 (rounded to 256)
#
# For 256: embed_size / 64 = 4 heads (nice round number)
#
# Recommended range: 256-512 (256 is conservative, good starting point)
embed_size=256 #256
# NUMBER OF ATTENTION HEADS
# -------------------------
# nhead = 4
#
# Rule of thumb: heads = embed_size // 64
#
# Formula: heads = embed_size // d_head (where d_head is typically 64)
#
# For embed_size=256: 256 / 64 = 4 heads
#
# Must divide embed_size evenly: 256 % 4 = 0
nhead=4
# FEED-FORWARD EXPANSION FACTOR
# -----------------------------
# forward_expansion = 2
#
# Rule of thumb: forward_expansion = 2 to 4
#
# Formula: ff_dim = embed_size × forward_expansion
#
# For forward_expansion=2: ff_dim = 256 × 2 = 512
# For forward_expansion=4: ff_dim = 256 × 4 = 1024
#
# Larger expansion = more capacity but more parameters
# Recommended range: 2-4 (2 is conservative, 4 is aggressive)
forward_expansion=4
# DROPOUT RATE
# ------------
# dropout = 0.3
#
# Rule of thumb: dropout = 0.1 to 0.5
#
# For output_channel=120 (many outputs), use higher dropout to prevent overfitting
#
# Recommended range: 0.2-0.4
dropout=0.1
sblock_perc=0.1
# ======================
# 2. Training Configuration
# ======================
batch_size=4 # On LEONARDO
#batch_size=4 # On HAL
num_epochs=300
learning_rate=0.0001
loss_type="huber" # options: "mse", "mae", "huber", "smoothl1", etc
beta=0.001
beta_delta=1.0
num_workers=$current_workers
run_type="train" # options: "train", "resume_train", "inference".
seed=42
# ======================
# 3. Data Configuration
# ======================
train_data_files=$CAMS_TRAIN_DATA_PATH
test_data_files=$CAMS_Test_DATA_PATH
train_years="2009-2018"
test_year="2014"
norm="minmax"
dataset_type="CAMS"
# ======================
# 4. Output Configuration
# ======================
save_model="True"
save_checkpoint_name="model"
save_per_samples=10000
load_checkpoint_name="experiment_best_model.pth.tar"
# ======================
# 5. Tags
# ======================
lr_str="${learning_rate//./d}"
beta_str="${beta//./d}"
# ======================
# 5. Tags (Final version)
# ======================
# Format numeric values (avoid dots)
lr_str="${learning_rate//./d}"
beta_str="${beta//./d}"
dropout_str="${dropout//./d}"
# Model-specific naming
if [ "$type" == "encodertorch" ] || [ "$type" == "transformer" ]; then
model_parts=(
"$type"
"e${embed_size}"
"h${nhead}"
"l${num_layers}"
"fe${forward_expansion}"
"d${dropout_str}"
)
else
model_parts=(
"$type"
"h${hidden_size}"
"l${num_layers}"
"d${dropout_str}"
)
fi
model_name=$(IFS=_ ; echo "${model_parts[*]}")
tag="experiment"
main_folder="$([ "$debug" == "True" ] && echo "Debug" || echo "Prod")__${model_name}_sb_${batch_size}_nw_${num_workers}_ne_${num_epochs}_ds_${dataset_type}_tr_${train_years}_te_${test_year}"
sub_folder="nrm_${norm}_lr_${lr_str}_l_${loss_type}"
if [ "$loss_type" == "huber" ] || [ "$loss_type" == "smoothl1" ]; then
beta_delta_str="${beta_delta//./d}"
sub_folder="${sub_folder}_bd_${beta_delta_str}"
fi
sub_folder="${sub_folder}_beta_${beta_str}_seed_${seed}"
prefix="$tag"
# ======================
# Generate SBATCH Script Only (removed run script)
# ======================
PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"
JOB_DIR="$PROJECT_ROOT/slurm/${main_folder}/${sub_folder}"
SLURM_IO_DIR="$PROJECT_ROOT/slurm_io/${main_folder}/${sub_folder}"
mkdir -p "$JOB_DIR"
mkdir -p "$SLURM_IO_DIR"
sbatch_script="$JOB_DIR/sbatch_${current_ntasks}_${current_cpus}_${current_workers}_rtnn_${tag}.sh"
# Create slurm_io directory if it doesn't exist
# ======================
# 6. Create SBATCH file
# ======================
cat > $sbatch_script <<EOF
#!/bin/bash
# SBATCH always at the beginning of the script!
#SBATCH --job-name=rtnn_${main_folder}_${sub_folder}_${tag}
#SBATCH --error=$SLURM_IO_DIR/rtnn_${current_ntasks}_${current_cpus}_${current_workers}_${tag}_%j.err
#SBATCH --output=$SLURM_IO_DIR/rtnn_${current_ntasks}_${current_cpus}_${current_workers}_${tag}_%j.out
#SBATCH --chdir=$(pwd)
EOF
# ======================
# 7. Machine-specific SBATCH config
# ======================
if [ "$Machine" == "LEONARDO" ]; then
cat >> $sbatch_script <<EOF
#SBATCH -A EUHPC_D36_053
#SBATCH -p boost_usr_prod
#SBATCH --time=$([ "$debug" == "True" ] && echo "00:30:00" || echo "3:00:00")
#SBATCH -N 1
#SBATCH --gpus-per-node=1
#SBATCH --mem-per-gpu=64G
EOF
# Only add ntasks-per-node if not empty
if [ -n "$current_ntasks" ]; then
echo "#SBATCH --ntasks-per-node=$current_ntasks" >> $sbatch_script
fi
# Only add cpus-per-task if not empty
if [ -n "$current_cpus" ]; then
echo "#SBATCH --cpus-per-task=$current_cpus" >> $sbatch_script
fi
[ "$debug" == "True" ] && echo "#SBATCH --qos=boost_qos_dbg" >> $sbatch_script
elif [ "$Machine" == "HAL" ]; then
cat >> $sbatch_script <<EOF
#SBATCH --partition=batch
#SBATCH --gpus=1
#SBATCH --mem=48G
#SBATCH --time=24:00:00
EOF
# Only add ntasks-per-node if not empty
if [ -n "$current_ntasks" ]; then
echo "#SBATCH --ntasks-per-node=$current_ntasks" >> $sbatch_script
fi
# Only add cpus-per-task if not empty
if [ -n "$current_cpus" ]; then
echo "#SBATCH --cpus-per-task=$current_cpus" >> $sbatch_script
fi
fi
# ======================
# 8. Environment setup
# ======================
if [ "$Machine" == "LEONARDO" ]; then
cat >> $sbatch_script <<EOF
source "$PROJECT_ROOT/.venv/bin/activate"
EOF
elif [ "$Machine" == "HAL" ]; then
cat >> $sbatch_script <<EOF
source "$PROJECT_ROOT/.venv/bin/activate"
ulimit -s unlimited
EOF
fi
# ======================
# 9. Runtime diagnostics + training
# ======================
cat >> $sbatch_script <<EOF
echo "=========================================="
echo "CONFIGURATION TEST VALUES"
echo "=========================================="
echo "ntasks-per-node: ${current_ntasks:-default (1)}"
echo "cpus-per-task: ${current_cpus:-default}"
echo "num_workers: $num_workers"
echo "=========================================="
echo ""
echo "=== Job Info ==="
echo "Job ID: \$SLURM_JOB_ID"
echo "Node: \$SLURM_NODELIST"
echo "N tasks: \$SLURM_NTASKS"
echo "CPUs per task: \${SLURM_CPUS_PER_TASK:-default}"
echo "GPUs: \$SLURM_GPUS"
echo ""
echo "=== Environment Info ==="
echo "PyTorch version: \$(python -c 'import torch; print(torch.__version__)')"
echo "CUDA available: \$(python -c 'import torch; print(torch.cuda.is_available())')"
echo "CUDA version: \$(python -c 'import torch; print(torch.version.cuda)')"
echo "GPU count: \$(python -c 'import torch; print(torch.cuda.device_count())')"
echo "=== RTnn Training ==="
echo "Version: \$(python -c 'import rtnn; print(rtnn.__version__)')"
echo "Model: $model_name"
echo "Start time: \$(date)"
rtnn \\
--root_dir "./" \\
--main_folder "$main_folder" \\
--sub_folder "$sub_folder" \\
--prefix "$prefix" \\
--dataset_type "$dataset_type" \\
--type "$type" \\
--hidden_size "$hidden_size" \\
--num_layers "$num_layers" \\
--output_channel "$output_channel" \\
--seq_length "$seq_length" \\
--feature_channel "$feature_channel" \\
--embed_size "$embed_size" \\
--nhead "$nhead" \\
--forward_expansion "$forward_expansion" \\
--dropout "$dropout" \\
--model_name "$model_name" \\
--batch_size "$batch_size" \\
--num_epochs "$num_epochs" \\
--learning_rate "$learning_rate" \\
--sblock_perc "$sblock_perc" \\
--loss_type "$loss_type" \\
--beta "$beta" \\
--beta_delta "$beta_delta" \\
--train_data_files "$train_data_files" \\
--test_data_files "$test_data_files" \\
--train_years "$train_years" \\
--test_year "$test_year" \\
--norm "$norm" \\
--num_workers "$num_workers" \\
--save_model "$save_model" \\
--save_checkpoint_name "$save_checkpoint_name" \\
--save_per_samples "$save_per_samples" \\
--load_checkpoint_name "$load_checkpoint_name" \\
--run_type "$run_type" \\
--seed "$seed" \\
--debug "$debug"
echo "End time: \$(date)"
EOF
chmod +x $sbatch_script
echo "Created: $sbatch_script"
echo "Run with: sbatch $sbatch_script"