Skip to content

Commit baa8ef4

Browse files
authored
Setting up GitHub actions for model validation (#1)
Combined preprocessing, training, deployment and validation steps in a unique Snakemake workflow executed on CINECA Leonardo via GitHub actions.
1 parent 04e7f52 commit baa8ef4

8 files changed

Lines changed: 149 additions & 394 deletions

File tree

.github/workflows/train.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Train models
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: pull_request-${{ github.head_ref }}
10+
cancel-in-progress: true
11+
12+
13+
jobs:
14+
pid-2016MagUp-Sim10b:
15+
uses: LamarrSim/release-models/.github/workflows/release.yaml@main
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
with:
20+
name: pp-2016-MU-Sim10b-${{ github.head_ref }}
21+
snakemake_dir: pidgan
22+
target: cache_container validate_all
23+
model_prefix: pid
24+
additional_config: |
25+
storage_folder: pid-2016MagUp-Sim10b
26+
27+
additional_profile: |
28+
jobs: 1
29+
30+
generated_model_path: /tmp/compiled_model.c
31+
secrets:
32+
SECRETS_YAML: ${{ secrets.STORAGE_SECRETS }}
33+

pidgan/config/config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ apptainer_cached_image: /tmp/lb-pidsim-train.sif
66
sample: 2016MU
77
storage_folder: tests
88
temp_dir: /tmp
9-
training_time_limit_seconds: 60 #0
10-
entries_for_validation: 10000 #00
9+
training_time_limit_seconds: 600
10+
entries_for_validation: 1000000
1111

1212
nbconvert_args:
1313
- --allow-errors
@@ -19,7 +19,6 @@ training_data:
1919
- training-data/2016MU-sim10b/LamarrTraining-j109.10.root
2020
- training-data/2016MU-sim10b/LamarrTraining-j109.100.root
2121
- training-data/2016MU-sim10b/LamarrTraining-j109.101.root
22-
other:
2322

2423
- training-data/2016MU-sim10b/LamarrTraining-j109.102.root
2524
- training-data/2016MU-sim10b/LamarrTraining-j109.103.root

pidgan/workflow/Snakefile

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ PARTICLES = ['muon', 'pion', 'kaon', 'proton']
99
ITEMS = ['model.keras', 'tX.pkl', 'tY.pkl']
1010

1111

12-
rule build_container:
12+
rule validate_all:
13+
input: smkstore(expand("validate-{particle}.html", particle=PARTICLES), 's3reports')
14+
15+
16+
rule build_apptainer_image:
1317
input:
14-
definition_file="workflow/envs/pidgan.def"
18+
definition_file=ancient("workflow/envs/pidgan.def")
1519

1620
output:
1721
sif=smkstore("lhcb-pidsim.sif", 's3images')
@@ -38,7 +42,7 @@ rule build_container:
3842

3943

4044
rule cache_container:
41-
input: ancient(smkstore("lhcb-pidsim.sif", 's3images'))
45+
input: smkstore("lhcb-pidsim.sif", 's3images')
4246
output: config['apptainer_cached_image']
4347
shell: "cp {input} {output}"
4448

@@ -59,7 +63,7 @@ rule preprocessing:
5963
report=report(
6064
smkstore("{model}-{particle}-preprocessing.html", 's3reports'),
6165
category="Preprocessing",
62-
labels=dict(model="{model}", particle="{particle}")
66+
labels=dict(model="{model}", particle="{particle}", type='html')
6367
)
6468

6569
log: smkstore("{model}-{particle}-preprocessing.html", 's3reports')
@@ -120,16 +124,16 @@ rule train:
120124
history_csv=report(
121125
smkstore("history/generator-{model}-{particle}.csv", 's3reports'),
122126
category="Training",
123-
labels=dict(model="{model}", particle="{particle}")
127+
labels=dict(model="{model}", particle="{particle}", type='csv')
124128
),
125129

126130
output_validation_set=smkstore("ready2validate/{model}-{particle}.npz", 's3reports'),
127131
output_model=smkstore("{model}/{particle}/model.keras", "s3models"),
128132

129133
report=report(
130134
smkstore("{model}-{particle}-train.html", 's3reports'),
131-
category="Preprocessing",
132-
labels=dict(model="{model}", particle="{particle}")
135+
category="Training",
136+
labels=dict(model="{model}", particle="{particle}", type='html')
133137
)
134138

135139
log: smkstore("{model}-{particle}-train.html", 's3reports')
@@ -138,8 +142,8 @@ rule train:
138142

139143

140144
resources:
141-
cpu=8,
142-
mem_mb=32000,
145+
cpu=4,
146+
mem_mb=15000,
143147
gpu=1
144148

145149
params:
@@ -193,12 +197,12 @@ rule deploy:
193197

194198
output:
195199
hook=touch("/tmp/deploy.touch"),
196-
generated_c_file="/tmp/compiled_pid_model.c",
200+
generated_c_file="/tmp/compiled_model.c",
197201
generated_library=smkstore("pid_compiled_model/generated.so", 's3models'),
198202
report=report(
199203
smkstore("deploy.html", 's3reports'),
200204
category="Deploy",
201-
labels=dict(model="ALL", particle="ALL")
205+
labels=dict(model="ALL", particle="ALL", type='html')
202206
)
203207

204208
params:
@@ -243,8 +247,8 @@ rule validate:
243247

244248
report=report(
245249
smkstore("validate-{particle}.html", 's3reports'),
246-
category="Preprocessing",
247-
labels=dict(model="ALL", particle="{particle}")
250+
category="Validation",
251+
labels=dict(model="ALL", particle="{particle}", type="html")
248252
)
249253

250254
log: smkstore("validate-{particle}.html", 's3reports')
@@ -259,15 +263,15 @@ rule validate:
259263
max_entries=config['entries_for_validation'],
260264

261265
resources:
262-
cpu=8,
263-
mem_mb=32000,
266+
cpu=4,
267+
mem_mb=15000,
264268
gpu=0
265269

266270
shell:
267271
"""
268272
INPUT_FILES='{params.data_files}' \
269273
PARTICLE='{wildcards.particle}' \
270-
GENERATED_LIBRARY='{input.generated_library}' \
274+
SHARED_OBJECT='{input.generated_library}' \
271275
MAX_ENTRIES='{params.max_entries}' \
272276
SAMPLE='{params.sample}' \
273277
jupyter nbconvert --to html --execute \
@@ -278,7 +282,5 @@ rule validate:
278282
{input.notebook} --output {log}
279283
"""
280284

281-
rule validate_all:
282-
input: smkstore(expand("validate-{particle}.html", particle=PARTICLES), 's3reports')
283285

284286

0 commit comments

Comments
 (0)