miprometheus.grid_workers¶
GridWorker¶
-
class
miprometheus.grid_workers.
GridWorker
(name='GridWorker', use_gpu=False)[source]¶ Base abstract class for the grid workers. All grid workers should subclass it and override the relevant methods.
-
__init__
(name='GridWorker', use_gpu=False)[source]¶ Base constructor for all grid workers:
Initializes the AppState singleton:
>>> self.app_state = AppState()
Initializes the Parameter Registry:
>>> self.params = ParamInterface()
Defines the logger:
>>> self.logger = logging.getLogger(name=self.name)
Creates parser and adds default worker command line arguments (you can display them with
--h
).
Parameters: - name (str) – Name of the worker (DEFAULT: “GridWorker”).
- use_gpu (bool) – Indicates whether the worker should use GPU or not. Value coming from the subclasses (e.g.
miprometheus.grid_workers.GridTrainerCPU
vsmiprometheus.grid_workers.GridTrainerGPU
) (DEFAULT: False).
-
setup_grid_experiment
()[source]¶ Setups the overall grid of experiments.
Base method:
- Parses command line arguments,
- Sets the 3 default sections (training / validation / test) for the param registry, sets seeds to unspecified and disable multiprocessing.
Note
Child classes should override this method, but still call its parent to draw the basic functionality implemented here.
-
run_grid_experiment
()[source]¶ Main function of the
miprometheus.grid_workers.GridWorker
, which essentially maps an experiment to available core or device.Note
Abstract. Should be implemented in the subclasses.
-
GridTrainerCPU¶
-
class
miprometheus.grid_workers.
GridTrainerCPU
(name='GridTrainerCPU', use_gpu=False)[source]¶ Grid Worker managing several training experiments on CPUs.
Reuses a
miprometheus.workers.Trainer
(can specifymiprometheus.workers.OfflineTrainer
ormiprometheus.workers.OnlineTrainer
) to start one experiment.-
__init__
(name='GridTrainerCPU', use_gpu=False)[source]¶ Constructor for the
miprometheus.grid_workers.GridTrainerCPU
:- Calls the base constructor to set the worker’s name and add default command lines arguments,
- Adds some
GridTrainer
specific command line arguments.
Parameters:
-
setup_grid_experiment
()[source]¶ Setups a specific experiment.
- Calls
GridWorker.setup_grid_experiment()
to parse arguments, sets the 3 default sections (training / validation / test) and sets theirtorch.utils.data.DataLoader
params. - Verifies that the specified config file is valid,
- Parses it and recursively creates the configurations files for the grid tasks, overwriting specific sections if indicated: grid_overwrite and/or overwrite (task specific),
- Creates the output dir.
- Calls
-
run_grid_experiment
()[source]¶ Main function of the
miprometheus.grid_workers.GridTrainerCPU
.Maps the grid experiments to CPU cores in the limit of the maximum concurrent runs allowed or maximum available cores.
-
run_experiment
(experiment_configs: str, prefix='')[source]¶ Setups the overall grid of experiments.
Parameters: Note
- Visualization is deactivated to avoid any user interaction.
- Command-line arguments such as the logging interval (
--li
), tensorboard (--t
) and log level (--ll
) are passed to the usedmiprometheus.workers.Trainer
- Not using the –model command-line argument of the
miprometheus.workers.Trainer
to load a pretrained model. Please use instead the configuration parameter load in the model section.
-
GridTrainerGPU¶
-
class
miprometheus.grid_workers.
GridTrainerGPU
(name='GridTrainerGPU', use_gpu=True)[source]¶ Grid Worker managing several training experiments on GPUs.
Reuses a
miprometheus.workers.Trainer
(can specifymiprometheus.workers.OfflineTrainer
ormiprometheus.workers.OnlineTrainer
) to start one experiment.Inherits from
miprometheus.grid_workers.GridTrainerCPU
as the constructor &GridTrainerCPU.setup_grid_experiment()
are identical.-
__init__
(name='GridTrainerGPU', use_gpu=True)[source]¶ Constructor for the
miprometheus.grid_workers.GridTrainerGPU
:- Calls the constructor of
miprometheus.grid_workers.GridTrainerCPU
as it is identical.
Parameters: - Calls the constructor of
-
setup_grid_experiment
()[source]¶ Setups a specific experiment.
- Calls
GridTrainerGPU.setup_grid_experiment()
to parse arguments, parse config files etc. - Checks the presence of CUDA-compatible devices.
- Calls
-
run_grid_experiment
()[source]¶ Main function of the
miprometheus.grid_workers.GridTrainerGPU
.Maps the grid experiments to CUDA devices in the limit of the maximum concurrent runs allowed.
-
GridTesterCPU¶
-
class
miprometheus.grid_workers.
GridTesterCPU
(name='GridTesterCPU', use_gpu=False)[source]¶ Implementation of the Grid Tester running on CPUs.
Reuses the
miprometheus.workers.Tester
to start one test experiment.-
__init__
(name='GridTesterCPU', use_gpu=False)[source]¶ Constructor for the
miprometheus.grid_workers.GridTesterCPU
:- Calls the base constructor to set the worker’s name and add default command lines arguments,
- Adds some
GridTester
specific command line arguments.
Parameters:
-
setup_grid_experiment
()[source]¶ - Setups the overall grid of experiments:
- Calls
GridWorker.setup_grid_experiment()
to parse arguments, - Recursively creates the paths to the experiments folders, verifying that they are valid (e.g. they contain a saved model, model_best.pt).
- Calls
-
run_grid_experiment
()[source]¶ Main function of the
miprometheus.grid_workers.GridTesterCPU
.Maps the grid experiments to CPU cores in the limit of the maximum concurrent runs allowed or maximum available cores.
-
run_experiment
(experiment_path: str, prefix='')[source]¶ Runs a test on the specified model (experiment_path) using the
miprometheus.workers.Tester
.Parameters: ..note:
- Visualization is deactivated to avoid any user interaction. - Command-line arguments such as the logging interval (``--li``) and log level (``--ll``) are passed to the :py:class:`miprometheus.workers.Tester`.
-
GridTesterGPU¶
-
class
miprometheus.grid_workers.
GridTesterGPU
(name='GridTesterGPU', use_gpu=True)[source]¶ Implementation of the
GridTester
running on GPUs.Reuses the
miprometheus.workers.Tester
to start one test experiment.Inherits from
miprometheus.grid_workers.GridTesterCPU
as the constructor is identical.-
__init__
(name='GridTesterGPU', use_gpu=True)[source]¶ Constructor for the
miprometheus.grid_workers.GridTesterGPU
:- Calls the constructor of
miprometheus.grid_workers.GridTesterCPU
as it is identical.
Parameters: - Calls the constructor of
-
setup_grid_experiment
()[source]¶ Setups a specific experiment.
- Calls
GridTesterCPU.setup_grid_experiment()
to parse arguments, parse config files etc. - Checks the presence of CUDA-compatible devices.
- Calls
-
run_grid_experiment
()[source]¶ Main function of the
miprometheus.grid_workers.GridTesterGPU
.Maps the grid experiments to CUDA device in the limit of the maximum concurrent runs allowed or maximum available devices.
-
GridAnalyzer¶
-
class
miprometheus.grid_workers.
GridAnalyzer
(name='GridAnalyzer')[source]¶ Implementation of the
miprometheus.grid_workers.GridAnalyzer
.Post-processes the test results of a grid of experiments and gather them in a csv file.
This csv file will gather the training statistics (seeds, accuracies, terminal conditions,…), the validation statistics and the test statistics.
Inherits from
miprometheus.grid_workers.GridWorker
.-
__init__
(name='GridAnalyzer')[source]¶ Constructor for the
miprometheus.grid_workers.GridAnalyzer
:- Calls basic constructor of
miprometheus.grid_workers.GridWorker
Parameters: name (str) – Name of the worker (DEFAULT: “GridAnalyzer”). - Calls basic constructor of
-
static
check_if_file_exists
(dir_, filename_)[source]¶ Checks if
filename_
exists indir_
.Parameters: Returns: True if the file exists in the directory, else False
-
check_file_content
(dir_, filename_)[source]¶ Checks if the number of lines in the file is > 1.
Parameters: Returns: True if the number of lines in the file is strictly greater than one.
-
static
get_lines_number
(filename_)[source]¶ Returns the number of lines in
filename_
.Parameters: filename (str) – Filepath to be opened and line-read. Returns: Number of lines in the file.
-
get_experiment_tests
(experiment_path_)[source]¶ Returns a list of folders containing valid test experiments data:
- A configuration (testing_configuration.yaml),
- A csv file containing a data point for the aggregated statistics (testing_set_agg_statistics.csv)
Parameters: experiment_path (str) – Path to experiment (training) folder. Returns: A list of valid test experiment folders.
-
setup_grid_experiment
()[source]¶ Setups the overall experiment:
Parses arguments and sets logger level,
Checks the presence of experiments folder,
Recursively traverses the experiment folders, cherry-picking subfolders containing:
- ‘training_configuration.yaml’ (training configuration file),
- ‘models/model_best.pt’ (checkpoint of the best saved model).
-
run_experiment
(experiment_path: str)[source]¶ Collects the training / validation / test statistics for a given experiment path.
Analyzes whether the given training experiment folder contains subfolders with test experiments data:
Loads and parses training configuration file,
Loads checkpoint with model and training and validation statistics,
Recursively traverses subdirectories looking for test experiments,
Note
We require that the test statistics csv files are valid, i.e. contain at least one line with collected statistics (excluding the header).
Collects statistics from training, validation (from model checkpoint) and test experiments (from test csv files found in subdirectories).
Parameters: experiment_path (str) – Path to an experiment folder containing a training statistics. Returns: Four dictionaries containing: - Status info (model, problem etc.), - Training statistics, - Validation statistics, - Test statistics.
-