Launch experiments locally or on SLURM clusters with ease. Fork from 'experiment-launcher'.
Project description
Experiment Launcher
Launch experiments locally or on a cluster running SLURM in a single file.
Fork from experiment_launcher
Description
The experiment_launcher package provides a simple way to run multiple experiments using SLURM or Joblib with minimum
effort - you just have to set the local parameter to True to run locally,
or to False to run with a cluster using SLURM.
It is particularly useful to run multiple seeds and/or test multiple configurations of hyperparameters such as learning rates, batch size.
Installation
You can install the package from pip with:
pip install "experiment-launcher-meco
If you want to install it locally, you can do so with:
pip install -e .
How to Use
Basic Usage
The best way to understand experiment launcher is to look at the basic example in examples/basic.
- The file examples/basic/test.py contains a single experiment
- The file examples/basic/launch_test.py contains the launcher file configurations and call
Single experiment
- examples/basic/test.py consists of:
-
The function
experimentis the entry point of your experiment- It takes as arguments your experiment settings (e.g., the number of layers in a neural network, the learning rate, ...)
- The arguments need to be assigned a type and default value in the function definition
- Current accepted types are
int,float,str,bool,list - The arguments
seedandresults_dirmust always be included - Python kwargs can also be added as
**kwargs(accepted types are the same as above)
- Current accepted types are
- This function must be decorated with a decorator, e.g.
@single_experiment. This will take care of creating proper results directories.
-
The
if __name__ == '__main__'block- This must contain one single line:
run_experiment(experiment)
- This must contain one single line:
-
- You can test your code by running
cd examples/basic python test.py
Launch file
- examples/basic/launch_test.py consists of:
- Creating an instance of the
LauncherConfigobject, that contains the SLURM or Joblib (if run locally) parameters. These are some of the important parameters. For more consult the class definition.exp_nameis the experiment name, under which a results directory will be createdexp_fileis the path to the python file where theexperimentis implemented (without the extension.py)n_seedsis the number of random seeds for each single experiment configuration
- Advanced configs are provided via nested Pydantic objects:
ResourceConfigspecifies:n_exps_in_parallelis the number of experiments to be run in parallel. This is useful to run multiple jobs in a single GPU in the clustern_coresis the number of cores for each experiment. Note that ifn_exps_in_parallel > 1, thenn_exps_in_paralleljobs will sharen_cores.memory_per_coreis amount of memory in MB requested for each core in SLURM. If you specify this too low, SLURM might crash.
SlurmConfigspecifies:partitionis the SLURM partition, which is cluster dependentgresare special resources asked for a SLURM experimentproject_nameis the project name in the cluster
EnvironmentConfigspecifies:conda_envif you are using a conda environment, specify its name here
DurationConfigspecifies the max runtime of the SLURM job (days, hours, minutes, seconds).
- Creating an instance of the
Launcherobject:launcher = Launcher(config) - Adding experiments with
launcher.add_experiment- Use
launcher.add_experimentto create an experiment for a particular configuration (e.g., different learning rates) - You can use the
Sweepclass to automatically sweep over a list of parameters. - E.g.
launcher.add_experiment(learning_rate=Sweep(values=[1e-3, 1e-4]), batch_size=32)creates two experiments: one with1e-3and another with1e-4. - Swept parameters automatically are used to organize the results directories. Results directories are going to be created by default as:
./logs/exp_name_DATE/learning_rate_0.001/SEED/and./logs/exp_name_DATE/learning_rate_0.0001/SEED/
- If multiple sweeps are provided, the Cartesian product of all sweep values is calculated to generate the experiments.
- Use
- Running the experiments with
launcher.run(LOCAL)- This runs your experiment either locally (LOCAL:
True) or in the cluster (LOCAL:False)
- This runs your experiment either locally (LOCAL:
- Creating an instance of the
Running the experiment
- To run the launcher simply call
cd examples/basic python launch_test.py
- Log files will be placed in
./logsif running locally or in the IAS cluster/work/scratch/$USERNAMEif ran in theLichtenberg-Hochleistungsrechner of the TU Darmstadt
Integration with Weights and Biases
The experiment launcher provides an easy way to integrate with Weights and Biases.
- In the experiment file add
**kwargsin theexperimentfunction definition
- In the launcher file, create wandb options and pass them to the
launcher.add_experiment()wandb_options = dict( wandb_enabled=False, # If True, runs and logs to wandb. wandb_entity='joaocorreiacarvalho', wandb_project='experiment_launcher_test', wandb_group='group_test' )
- To use wandb, you need to install it with
pip install wandband log in withwandb login
Running experiments with parameters in configuration files
- If you have many parameters that you need to change, a good idea can be to use configuration files.
- If you want to specify your parameters in a configuration file, look at the example under
examples/config_files
Notes
- For reproducibility, the seeds are created sequentially from
0ton_exps-1.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file experiment_launcher_meco-4.0.1.tar.gz.
File metadata
- Download URL: experiment_launcher_meco-4.0.1.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cff7efe0da905d2899fcff3707127dd089d15f24ac971a1ff0fb0a71b7e62c03
|
|
| MD5 |
627bbddec4028fdcc8b3a64fd7063ca0
|
|
| BLAKE2b-256 |
306920c89a64a2254db296208f935942f9f7470c5f3b555180f3d30c07696aae
|
Provenance
The following attestation bundles were made for experiment_launcher_meco-4.0.1.tar.gz:
Publisher:
publish.yaml on meco-group/experiment-launcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
experiment_launcher_meco-4.0.1.tar.gz -
Subject digest:
cff7efe0da905d2899fcff3707127dd089d15f24ac971a1ff0fb0a71b7e62c03 - Sigstore transparency entry: 1198271534
- Sigstore integration time:
-
Permalink:
meco-group/experiment-launcher@f5f04d2a8eb8c5fad06d4b5d2c4c75ceda2271c6 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/meco-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@f5f04d2a8eb8c5fad06d4b5d2c4c75ceda2271c6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file experiment_launcher_meco-4.0.1-py3-none-any.whl.
File metadata
- Download URL: experiment_launcher_meco-4.0.1-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19557cb0471995b72bb2bdef80a39cb8117b07be8a4d099a3f28e9a7d679616b
|
|
| MD5 |
650ddf59af4ebfb625e9daf3dc71e47e
|
|
| BLAKE2b-256 |
d4a29f779c5aa73ff3a12bba20161de09f8b7b82686a4759452cb617ee6a7f95
|
Provenance
The following attestation bundles were made for experiment_launcher_meco-4.0.1-py3-none-any.whl:
Publisher:
publish.yaml on meco-group/experiment-launcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
experiment_launcher_meco-4.0.1-py3-none-any.whl -
Subject digest:
19557cb0471995b72bb2bdef80a39cb8117b07be8a4d099a3f28e9a7d679616b - Sigstore transparency entry: 1198271610
- Sigstore integration time:
-
Permalink:
meco-group/experiment-launcher@f5f04d2a8eb8c5fad06d4b5d2c4c75ceda2271c6 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/meco-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@f5f04d2a8eb8c5fad06d4b5d2c4c75ceda2271c6 -
Trigger Event:
release
-
Statement type: