runner
Runner class for running networks.
- class Runner(params, network, data, runner_dict=None)[source]
Bases:
object
Parent class for all classes that in some sense “run” the network.
That can be training, benchmarking, inference, etc.
- Parameters:
params (mala.common.parametes.Parameters) – Parameters used to create this Runner object.
network (mala.network.network.Network) – Network which is being run.
data (mala.datahandling.data_handler.DataHandler) – DataHandler holding the data for the run.
- classmethod load_run(run_name, path='./', zip_run=True, params_format='json', load_runner=True, prepare_data=False, load_with_mpi=None, load_with_gpu=None, load_with_ddp=None)[source]
Load a run.
- Parameters:
run_name (str) – Name under which the run is saved.
path (str) – Path where the run is saved.
zip_run (bool) – If True, MALA will attempt to load from a .zip file. If False, then separate files will be attempted to be loaded.
params_format (str) – Can be “json” or “pkl”, depending on what was saved by the model. Default is “json”.
load_runner (bool) – If True, a Runner object will be created/loaded for further use.
prepare_data (bool) – If True, the data will be loaded into memory. This is needed when continuing a model training.
load_with_mpi (bool or None) – Can be used to actively enable/disable MPI during loading. Default is None, so that the MPI parameters set during training/saving of the model are not overwritten. If MPI is to be used in concert with GPU during training, MPI already has to be activated here, if it was not activated during training!
load_with_gpu (bool or None) – Can be used to actively enable/disable GPU during loading. Default is None, so that the GPU parameters set during training/saving of the model are not overwritten. If MPI is to be used in concert with GPU during training, it is advised that GPU usage is activated here, if it was not activated during training. Can also be used to activate a CPU based inference, by setting it to False.
load_with_ddp (bool or None) – Can be used to actively disable DDP (pytorch distributed data parallel used for parallel training) during loading. Default is None, which for loading a Trainer object will not interfere with DDP settings. For Predictor and Tester class, this command will automatically disable DDP during loading, as inference is using MPI rather than DDP for parallelization.
- Returns:
loaded_params (mala.common.parameters.Parameters) – The Parameters saved to file.
loaded_network (mala.network.network.Network) – The network saved to file.
new_datahandler (mala.datahandling.data_handler.DataHandler) – The data handler reconstructed from file.
new_runner (cls) – (Optional) The runner reconstructed from file. For Tester and Predictor class, this is just a newly instantiated object.
- classmethod run_exists(run_name, params_format='json', zip_run=True)[source]
Check if a run exists.
- Parameters:
run_name (str) – Name under which the run is saved.
zip_run (bool) – If True, MALA will look for a .zip file. If False, then separate files will be attempted to be loaded.
params_format (str) – Can be “json” or “pkl”, depending on what was saved by the model. Default is “json”.
- Returns:
exists – If True, the model exists.
- Return type:
bool
- save_run(run_name, path='./', zip_run=True, save_runner=False, additional_calculation_data=None)[source]
Save the current run.
- Parameters:
run_name (str) – Name under which the run should be saved.
path (str) – Path where to which the run.
zip_run (bool) – If True, the entire run will be saved as a .zip file. If False, then the model will be saved as separate files.
save_runner (bool) – If True, the Runner object will also be saved as object. This is unnecessary for most use cases, but used internally when a checkpoint is created during model training.
additional_calculation_data (string or bool) – If this variable is a string, then additional calculation data will be copied from the file this variable points to and included in the saved model. If a a bool (and True), additional calculation data will be saved directly from the DataHandler object. Only has an effect in the .zip mode. If additional calculation data is already present in the DataHandler object, it can be saved by setting.