Skip to content

Commit

Permalink
Added deepsets (for real now) (documentation is WIP).
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Odagiu committed Nov 2, 2023
1 parent 8ae169b commit e3afaed
Show file tree
Hide file tree
Showing 2,614 changed files with 7,876 additions and 1 deletion.
1 change: 0 additions & 1 deletion deepsets
Submodule deepsets deleted from 92844d
21 changes: 21 additions & 0 deletions deepsets/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Patrick Odagiu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions deepsets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# deepsets_synth
Synthesizing the invariant version of the deepsets architecture using hls4ml. This architecture is meant to be used in a fast inference regime.
11 changes: 11 additions & 0 deletions deepsets/bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Deepsets Training Required Packages
---

Suggested to install the following using conda, with channel conda-forge.

* numpy
* tensorflow (only available on pip)
* tensorflow-model-optimization (only available on pip)
* matplotlib
* scikit-learn
* qkeras (only available on pip)
61 changes: 61 additions & 0 deletions deepsets/bin/deepsets_hyperopt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

# Run the training of the interaction network..
import argparse
import os
import sys
sys.path.append("..")

from deepsets.hyperparam_optimisation import main
parser = argparse.ArgumentParser(formatter_class=argparse.
ArgumentDefaultsHelpFormatter)
parser.add_argument("--test_kfold", type=int, default=-1,
help="Which kfold to use for test.")
parser.add_argument("--gpu", type=str, default="",
help="Sets the number of the GPU to run on.")
args = parser.parse_args()

if args.gpu:
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu

kfolds = 5
const = 32
train_kfolds = [kfold for kfold in range(kfolds) if kfold != args.test_kfold]
data_hyperparams = {
"fpath": f'../../ki_data/jets_{const}constituents_ptetaphi_robust_fast',
"fnames_train": [f'jet_images_c{const}_minpt2.0_ptetaphi_robust_fast_{train_kfold}'
for train_kfold in train_kfolds],
"fname_test": f'jet_images_c{const}_minpt2.0_ptetaphi_robust_fast_{args.test_kfold}',
}

training_hyperparams = {
"batch": [64, 128, 256, 512],
"epochs": 150,
"lr": [0.0001, 0.01],
"valid_split": 0.2,
}

compilation_hyperparams = {
"optimizer": ['adam'],
"loss": 'softmax_with_crossentropy',
"metrics": ['categorical_accuracy'],
}

model_hyperparams = {
"nnodes_phi": [24, 32],
"nnodes_rho": [32],
"activ": ['relu'],
}

args = {
"study_name": f'synthable_{const}const_ptetaphi',
"storage": 'deepsets_inv',
"deepsets_type": 'invariant',
"outdir": 'deepsets_hyperopt',
"data_hyperparams": data_hyperparams,
"training_hyperparams": training_hyperparams,
"model_hyperparams": model_hyperparams,
"compilation": compilation_hyperparams,
}

main(args)
6 changes: 6 additions & 0 deletions deepsets/bin/deepsets_hyperopt_allgpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

nohup python -u deepsets_hyperopt --test_kfold 4 --gpu 0 > logs/synthable_32const_ptetaphi_0.out &
nohup python -u deepsets_hyperopt --test_kfold 4 --gpu 1 > logs/synthable_32const_ptetaphi_1.out &
nohup python -u deepsets_hyperopt --test_kfold 4 --gpu 2 > logs/synthable_32const_ptetaphi_2.out &
nohup python -u deepsets_hyperopt --test_kfold 4 --gpu 3 > logs/synthable_32const_ptetaphi_3.out &
26 changes: 26 additions & 0 deletions deepsets/bin/deepsets_synth
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

# Run the testing of the interaction network.
import argparse
import sys
import os
sys.path.append("..")

from deepsets.synthesize import main
parser = argparse.ArgumentParser(formatter_class=argparse.
ArgumentDefaultsHelpFormatter)
parser.add_argument("--model_dir", type=str, default="./trained_deepsets/test",
help="The output directory name.")
parser.add_argument("--gpu", type=str, default="0",
help="Sets the number of the GPU to run on.")
args = parser.parse_args()


os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu

args = {
"model_dir": args.model_dir,
"const_seed": 318
}

main(args)
28 changes: 28 additions & 0 deletions deepsets/bin/deepsets_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python

# Run the testing of the interaction network.
import argparse
import sys
import os
sys.path.append("..")

from deepsets.test import main
parser = argparse.ArgumentParser(formatter_class=argparse.
ArgumentDefaultsHelpFormatter)
parser.add_argument("--model_dir", type=str, default="./trained_deepsets/test",
help="The output directory name.")
parser.add_argument("--gpu", type=str, default="0",
help="Sets the number of the GPU to run on.")
args = parser.parse_args()


os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu


args = {
"model_dir": args.model_dir,
"kfolds": True,
"const_seed": 318
}

main(args)
70 changes: 70 additions & 0 deletions deepsets/bin/deepsets_train
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python

# Run the training of the deepsets network given the hyperparameters listed below.
import argparse
import os
import sys
sys.path.append("..")

from deepsets.train import main
parser = argparse.ArgumentParser(formatter_class=argparse.
ArgumentDefaultsHelpFormatter)
parser.add_argument("--gpu", type=str, default="",
help="Sets the number of the GPU to run on.")
parser.add_argument("--test_kfold", type=int, default=-1,
help="Which kfold to use for test.")
parser.add_argument("--nbits", type=int, default=-1,
help="The number of bits for quantisation of the model.")
parser.add_argument("--outdir", type=str, default="test",
help="The output directory name.")
args = parser.parse_args()

if args.gpu:
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu

# Import the data.
kfolds = 5
nconst = 32

data_folder_path = '../../ds_data'
jets_path = f'jets_{nconst}constituents_ptetaphi_robust_fast'

train_kfolds = [kfold for kfold in range(kfolds) if kfold != args.test_kfold]
test_kfold = args.test_kfold
data_hyperparams = {
"fpath": os.path.join(data_folder_path, jets_path),
"fnames_train": [f'jet_images_c{nconst}_minpt2.0_ptetaphi_robust_fast_{train_kfold}'
for train_kfold in train_kfolds],
"fname_test": f'jet_images_c{nconst}_minpt2.0_ptetaphi_robust_fast_{test_kfold}',
}

training_hyperparams = {
"epochs": 300,
"batch": 256,
"lr": 0.0032,
"pruning_rate": 0.5
}

compilation_hyperparams = {
"optimizer": "adam",
"loss": "categorical_crossentropy",
"metrics": ["categorical_accuracy"],
}

model_hyperparams = {
"nnodes_phi": 32,
"nnodes_rho": 32,
"activ": 'relu',
"nbits": args.nbits,
}

args = {
"data_hyperparams": data_hyperparams,
"training_hyperparams": training_hyperparams,
"model_hyperparams": model_hyperparams,
"compilation": compilation_hyperparams,
"outdir": args.outdir,
"deepsets_type": "sinvariant",
}

main(args)
7 changes: 7 additions & 0 deletions deepsets/bin/deepsets_train_all_kfolds
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

nohup python -u deepsets_train --test_kfold 0 --gpu 0 --nbits 8 --outdir deepsinv_synthable_8bits_32const_ptetaphi_kfolds/kfold_0 > ./logs/deepsinv_synthable_8bits_32const_ptetaphi_kfold_0 &
nohup python -u deepsets_train --test_kfold 1 --gpu 1 --nbits 8 --outdir deepsinv_synthable_8bits_32const_ptetaphi_kfolds/kfold_1 > ./logs/deepsinv_synthable_8bits_32const_ptetaphi_kfold_1 &
nohup python -u deepsets_train --test_kfold 2 --gpu 2 --nbits 8 --outdir deepsinv_synthable_8bits_32const_ptetaphi_kfolds/kfold_2 > ./logs/deepsinv_synthable_8bits_32const_ptetaphi_kfold_2 &
nohup python -u deepsets_train --test_kfold 3 --gpu 3 --nbits 8 --outdir deepsinv_synthable_8bits_32const_ptetaphi_kfolds/kfold_3 > ./logs/deepsinv_synthable_8bits_32const_ptetaphi_kfold_3 &
nohup python -u deepsets_train --test_kfold 4 --gpu 2 --nbits 8 --outdir deepsinv_synthable_8bits_32const_ptetaphi_kfolds/kfold_4 > ./logs/deepsinv_synthable_8bits_32const_ptetaphi_kfold_4 &
Empty file added deepsets/bin/run.snip
Empty file.
Loading

0 comments on commit e3afaed

Please sign in to comment.