Skip to content

Commit 0fc7d47

Browse files
committedFeb 20, 2025·
params update, readme update
1 parent 40535e8 commit 0fc7d47

5 files changed

+80
-79
lines changed
 

‎workflows/hpo/deephyper/README.md

+70-49
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,80 @@
1-
# Run HPO using DeepHyper on Lambda with conda
1+
# Hyperparameter Optimization using DeepHyper
2+
3+
## Overview
4+
5+
The scripts contained here run Hyperparameter Optimization (HPO) using DeepHyper.
6+
7+
## Requirements
8+
9+
* [IMPROVE general environment](https://jdacs4c-improve.github.io/docs/content/INSTALLATION.html)
10+
* [DeepHyper](https://deephyper.readthedocs.io/en/stable/)
11+
* MPI (these instructions use [openmpi](https://www.open-mpi.org/))
12+
* [mpi4py](https://mpi4py.readthedocs.io/en/stable/)
13+
* An IMPROVE-compliant model and its environment
14+
15+
## Installation and Setup
16+
17+
Create conda environment for DeepHyper:
18+
19+
```
20+
module load openmpi
21+
conda create -n dh python=3.9 -y
22+
conda activate dh
23+
conda install gxx_linux-64 gcc_linux-64
24+
pip install "deephyper[default]"
25+
pip install mpi4py
26+
pip install improvelib
27+
```
28+
29+
Install the model of choice, IMPROVE, and benchmark datasets:
230

3-
## 1. Install conda environment for the curated model
4-
Install model, IMPROVE, and datasets:
531
```
632
cd <WORKING_DIR>
733
git clone https://github.com/JDACS4C-IMPROVE/<MODEL>
834
cd <MODEL>
935
source setup_improve.sh
1036
```
1137

12-
Install model environment (get the name of the yml file from model repo readme):
13-
The workflow will need to know the ./<MODEL_ENV_NAME>/.
38+
Create a Conda environment path for the model in the model directory:
39+
The workflow will need to know the `<MODEL_ENV_NAME>`.
40+
1441
```
1542
conda env create -f <MODEL_ENV>.yml -p ./<MODEL_ENV_NAME>/
1643
```
1744

18-
## 2. Perform preprocessing
19-
Run the preprocess script.
20-
The workflow will need to know the <PATH/TO/PREPROCESSED/DATA>.
45+
46+
Run the preprocess script:
47+
The workflow will need to know the `<PATH/TO/PREPROCESSED/DATA>`.
2148

2249
```
23-
cd PathDSP
50+
cd <MODEL>
2451
conda activate ./<MODEL_ENV_NAME>/
2552
python <MODEL_NAME>_preprocess_improve.py --input_dir ./csa_data/raw_data --output_dir <PATH/TO/PREPROCESSED/DATA>
2653
conda deactivate
2754
```
2855

29-
## 3. Install conda environment for DeepHyper
30-
```
31-
module load openmpi
32-
conda create -n dh python=3.9 -y
33-
conda activate dh
34-
conda install gxx_linux-64 gcc_linux-64
35-
pip install "deephyper[default]"
36-
pip install mpi4py
37-
```
56+
## Parameter Configuration
57+
58+
**Workflow Parameters**
59+
60+
This workflow uses IMPROVE parameter handling. You should create a config file following the template of `hpo_deephyper_params.ini` with the parameters appropriate for your experiment. Parameters may also be specified on the command line.
61+
62+
63+
* `model_scripts_dir` should be set to the path to the model directory containing the model scripts (from step 1).
64+
* `input_dir` should be set to the location of the preprocessed data (above). We highly recommend that the name of this directory includes the source and split (e.g. ./ml_data/CCLE-CCLE/split_0). You can provide a complete or relative path, or the name of the directory if it is in `model_scripts_dir`.
65+
* `model_name` should be set to your model name (this should have the same capitalization pattern as your model scripts, e.g. deepttc for deepttc_preprocess_improve.py, etc).
66+
* `model_environment` should be set to the location of the model environment (from step 1). You can provide a complete or relative path, or the name of the directory if it is in `model_scripts_dir`.
67+
* `output_dir` should be set to path you would like the output to be saved to. We highly recommend that the name of this directory includes the source and split (e.g. ./deephyper/CCLE/split_0)
68+
69+
* `max_evals` should be set to the maximum number of evaluations to check for before launching additional training runs.
70+
* `hyperparameter_file` can be set to an alternate .json file containing hyperparameters. You can provide a complete or relative path, or the name of the directory if it is in `model_scripts_dir`. See below (step 5) for how to change hyperparameters.
71+
* `val_metric` can be set to any IMPROVE metric you would like to optimize. 'mse' and 'rmse' are minimized, all other metrics are maximized. Note that this does not change what val loss is used by the model, only what HPO tries to optimize. Default is 'mse'.
72+
* `num_gpus_per_node` should be set to the number of GPUs per node on your system. Default is 2.
73+
* `epochs`: Number of epochs to train for. If None is specified, model default parameters will be used (default: None).
74+
* Parameters beginning with `CBO_` can be used to change the optimization protocol. The names of these parameters can be found by running `python hpo_deephyper_subprocess.py --help` or looking in `hpo_deephyper_params_def.py`. Documentation of the DeepHyper CBO can be found [here](https://deephyper.readthedocs.io/en/stable/_autosummary/deephyper.hpo.CBO.html#deephyper.hpo.CBO).
75+
76+
**Hyperparameters**
3877

39-
## 4. Modify configuration file
40-
`hpo_deephyper_params.ini` is an example configuration file for this workflow.
41-
You will need to change the following parameters for your model:
42-
`model_scripts_dir` should be set to the path to the model directory containing the model scripts (from step 1).
43-
`input_dir` should be set to the location of the preprocessed data (above). We highly recommend that the name of this directory includes the source and split (e.g. ./ml_data/CCLE-CCLE/split_0). You can provide a complete or relative path, or the name of the directory if it is in `model_scripts_dir`.
44-
`model_name` should be set to your model name (this should have the same capitalization pattern as your model scripts, e.g. deepttc for deepttc_preprocess_improve.py, etc).
45-
`model_environment` should be set to the location of the model environment (from step 1). You can provide a complete or relative path, or the name of the directory if it is in `model_scripts_dir`.
46-
`output_dir` should be set to path you would like the output to be saved to. We highly recommend that the name of this directory includes the source and split (e.g. ./deephyper/CCLE/split_0)
47-
`epochs` should be set to the maximum number of epochs to train for.
48-
`max_evals` should be set to the maximum number of evaluations to check for before launching additional training runs.
49-
`interactive_session` should be set to True to run on Lambda, Polaris, and Biowulf. Other implementations have not yet been tested.
50-
`hyperparameter_file` can be set to an alternate .json file containing hyperparameters. You can provide a complete or relative path, or the name of the directory if it is in `model_scripts_dir`. See below (step 5) for how to change hyperparameters.
51-
`val_metric` can be set to any IMPROVE metric you would like to optimize. 'mse' and 'rmse' are minimized, all other metrics are maximized. Note that this does not change what val loss is used by the model, only what HPO tries to optimize. Default is 'mse'.
52-
`num_gpus_per_node` should be set to the number of GPUs per node on your system. Default is 2.
53-
Parameters beginning with `CBO_` can be used to change the optimization protocol. The names of these parameters can be found by running `python hpo_deephyper_subprocess.py --help` or looking in `hpo_deephyper_params_def.py`. Documentation of the DeepHyper CBO can be found here: https://deephyper.readthedocs.io/en/stable/_autosummary/deephyper.hpo.CBO.html#deephyper.hpo.CBO
54-
55-
56-
## 5. Modify hyperparameters file
5778
`hpo_deephyper_hyperparameters.json` contains dictionaries for the hyperparameters.
5879
The default settings are as follows:
5980

@@ -73,27 +94,18 @@ You can add more hyperparameters to test by adding additional dictionaries to th
7394
```
7495
Note that boolean values must be lowercase in JSON files.
7596

97+
## Usage
7698

77-
## 6. Perform HPO
78-
Navigate to the DeepHyper directory
79-
```
80-
cd <WORKING_DIR>/IMPROVE/workflows/deephyper_hpo
81-
```
82-
If necesssary (i.e not proceeding directly from above steps), activate environment:
99+
Activate the DeepHyper environment:
83100
```
84101
module load openmpi
85102
conda activate dh
86103
export PYTHONPATH=../../../IMPROVE
87104
```
88105

89-
Run HPO:
90-
```
91-
mpirun -np 10 python hpo_deephyper_subprocess.py
92-
```
93-
94-
To run HPO with a different config file:
106+
Run HPO with DeepHyper:
95107
```
96-
mpirun -np 10 python hpo_deephyper_subprocess.py --config <ALTERNATE_CONFIG_FILE>
108+
mpirun -np 10 python hpo_deephyper_subprocess.py --config <your_config.ini>
97109
```
98110

99111

@@ -131,5 +143,14 @@ export CUDA_VISIBLE_DEVICES=0,1,2,3
131143
mpirun -n ${NTOTRANKS} --ppn ${NRANKS_PER_NODE} --depth=${NDEPTH} --cpu-bind depth --env OMP_NUM_THREADS=${NTHREADS} python hpo_deephyper_subprocess.py
132144
```
133145

146+
To submit a job on Biowulf:
147+
148+
```
149+
```
150+
151+
152+
## Output
153+
154+
The output will be in the specified `output_dir` with the following structure
134155

135156

‎workflows/hpo/deephyper/hpo_deephyper_params.ini

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ model_scripts_dir = <PATH/TO/MODEL/DIR>
33
input_dir = <PATH/TO/PREPROCESSED/DATA>
44
model_name = <MODEL_NAME>
55
model_environment = <MODEL_ENV_NAME>
6-
epochs = 3
7-
output_dir = ./test_PathDSP
6+
output_dir = ./test
87
max_evals = 5
9-
interactive_session = True

‎workflows/hpo/deephyper/hpo_deephyper_params_def.py

+2-17
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,8 @@
1818
},
1919
{"name": "epochs",
2020
"type": int,
21-
"default": 10,
22-
"help": "Number of epochs"
23-
},
24-
{"name": "use_singularity",
25-
"type": bool,
26-
"default": True,
27-
"help": "Do you want to use singularity image for running the model?"
28-
},
29-
{"name": "singularity_image",
30-
"type": str,
31-
"default": '',
32-
"help": "Singularity image file of the model"
21+
"default": None,
22+
"help": "Number of epochs. If None, model default will be used."
3323
},
3424
{"name": "val_metric",
3525
"type": str,
@@ -41,11 +31,6 @@
4131
"default": 20,
4232
"help": "Number of evaluations"
4333
},
44-
{"name": "interactive_session",
45-
"type": bool,
46-
"default": True,
47-
"help": "Are you using an interactive session?"
48-
},
4934
{"name": "hyperparameter_file",
5035
"type": str,
5136
"default": './hpo_deephyper_hyperparameters.json',

‎workflows/hpo/deephyper/hpo_deephyper_subprocess.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def run(job, optuna_trial=None):
4141
str(params['epochs']),
4242
str(os.environ["CUDA_VISIBLE_DEVICES"])
4343
]
44+
if params['epochs'] is not None:
45+
train_run = train_run + ['epochs'] + [params['epochs']]
4446
for hp in params['hyperparams']:
4547
train_run = train_run + [str(hp)]
4648
train_run = train_run + [str(job.parameters[hp])]
@@ -123,12 +125,8 @@ def run(job, optuna_trial=None):
123125
comm = MPI.COMM_WORLD
124126
rank = comm.Get_rank()
125127
size = comm.Get_size()
126-
if params['interactive_session']:
127-
os.environ["CUDA_VISIBLE_DEVICES"] = str(rank % params['num_gpus_per_node'])
128-
cuda_name = "cuda:" + str(rank % params['num_gpus_per_node'])
129-
else:
130-
# CUDA_VISIBLE_DEVICES is now set via set_affinity_gpu_polaris.sh
131-
local_rank = os.environ["PMI_LOCAL_RANK"]
128+
os.environ["CUDA_VISIBLE_DEVICES"] = str(rank % params['num_gpus_per_node'])
129+
cuda_name = "cuda:" + str(rank % params['num_gpus_per_node'])
132130

133131
# Run DeepHyper
134132
with Evaluator.create(

‎workflows/hpo/deephyper/hpo_deephyper_subprocess_train.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ echo "Activated conda env $CONDA_ENV"
2020
SCRIPT=$2
2121
input_dir=$3
2222
output_dir=$4
23-
epochs=$5
24-
CUDA_VISIBLE_DEVICES=$6
23+
CUDA_VISIBLE_DEVICES=$5
2524

26-
command="python $SCRIPT --input_dir $input_dir --output_dir $output_dir --epochs $epochs "
25+
command="python $SCRIPT --input_dir $input_dir --output_dir $output_dir "
2726

2827

2928
# append hyperparameter arguments to python call
30-
for i in $(seq 7 $#)
29+
for i in $(seq 6 $#)
3130
do
3231
if [ $(($i % 2)) == 0 ]; then
3332
command="${command} ${!i}"

0 commit comments

Comments
 (0)
Please sign in to comment.