Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Note that the this documentation is a tad bit outdated. Will be updating as soon as I can

ml-pipeline

I use this pipeline to simplify my life when working on ML projects.

Installation

This can be installed using pip

pip install mlpipeline

Usage (tl;dr version)

  1. Extend mlpipeline.helper.Experiment and mlpipeline.helper.Dataloader to suit your needs.
  2. Define the versions using the interface provided by mlpipeline.utils.Versions.
    • Version parameters that must be defined:
      • mlpipeline.utils.version_parameters.NAME
      • mlpipeline.utils.version_parameters.DATALOADER
      • mlpipeline.utils.version_parameters.BATCH_SIZE
      • mlpipeline.utils.version_parameters.EPOC_COUNT
  3. Place the script(s) containing above in a specified directory.
  4. Add the directory to mlp.config
  5. Add the name of the script to the experiments.config
  6. (optional) Add the name of the script to the experiments_test.config
  7. (optional) Run the experiment in test mode to ensure the safety of your sanity.
mlpipeline
  1. Execute the pipeline
mlpipeline -r -u
  1. Anything saved to the experiment_dir passed through the mlpipeline.utils.Experiment.train_loop and mlpipeline.utils.Experiment.evaluate_loop will be available to access. The output and logs can be found in outputs/log-<hostname> and outputs/output-<hostname> files relative to the directory in 3. above.

Usage (Long version)

Experiment scripts

The experiment script is a python script that contain a global variable EXPERIMENT which holds an mlpipeline.helper.Experiment object. Ideally, one would extend the mlpipeline.helper.Experiment class and implement it's methods to perform the intended tasks (Refer documentation in mlpipeline.helper for more details).

Place experiment scripts in a separate folder. Note that this folder can be anywhere in your system. Add the path to the folder in which the code is placed in the mlp.config file. The directory structure recommended to use in this case would be as follows:

/<project>
  /experiment
    <experimentscripts>
  mlp.config
  experiments.config
  experiments_test.config

The mlpipeline will be executed from the directory.

For example: A sample experiment can be seen in examples/sample-project/experiments/sample_experiment.py. The default mlp.config file has points to the experiments folder. The examples/sample-project/ is a sample directory structure for a project.

Versions (I should choose a better term for this)

  • mlpipeline.utils.version_parameters.NAME: This is a string used to keep track of the training and history and this name will be appended to the logs and outputs. This parameters must be set for each version.
  • mlpipeline.utils.version_parameters.DATALOADER: An mlpipeline.helper.DataLoader object. Simply put, it is a wrapper for a dataset. You'll have extend the mlpipeline.helper.DataLoader class to fit your needs. This object will be used by the pipeline to infer details about a training process, such as the number of steps (Refer documentation in mlpipeline.helper for more details). As of the current version of the pipeline, this parameter is mandatory.
  • mlpipeline.utils.version_parameters.EXPERIMENT_DIR_SUFFIX: Each version of the experiment that's completed the training loop will be allocated a directory which can be used to save outputs (e.g. checkpoint files). When a experiment is being trained with a different set of versions if allow_delete_experiment_dir is set to True in the EXPERIMENT, the directory will be cleared as defined in mlpipeline.helper.Experiment.clean_experiment_dir (Note that the behaviour of this function is not implemented by default to avoid a disaster). Some times you may want to have different directories to for each version of the experiment, in such a case, pass a string to this parameter, which will be appended to the directory name.
  • mlpipeline.utils.version_parameters.BATCH_SIZE: The batch size used in the experiment's training loop. As of the current version of the pipeline, this parameter is mandatory.
  • mlpipeline.utils.version_parameters.EPOC_COUNT: The number of epocs that will be used. As of the current version of the pipeline, this parameter is mandatory.
  • mlpipeline.utils.version_parameters.ORDER: This is set to ensure the versions are loaded in the order they are defined. This value can be passed to a version to override this behaviour.

Executing experiments

You can have any number of experiments in the experiments folder. Add the names of the scripts to the experiments.config file. If the use_blacklist is false, only the scripts whose names are under [WHITELISTED_EXPERIMENTS] will be executed. if it is set to true all scripts except the ones under the [BLACKLISTED_EXPERIMENTS] will be executed. Note that experiments can be added or removed (assuming it has not been executed) to the execution queue while the pipeline is running. That is after each experiment is executed, the pipeline will re-load the config file.

You can execute the pipeline by running the python script:

python pipeline.py

Note: this will run the pipeline in test mode (Read The two modes for more information)

Outputs

The outputs and logs will be saved in files in a folder named outputs in the experiments folder. There are two files the user would want to keep track of (note that the <hostname> is the host name of the system on which the pipeline is being executed):

  • log-<hostname>: This file contains the logs
  • output-<hostname>: This file contains the output results of each "incarnation" of a experiment.

Note that the other files are used by the pipeline to keep track of training sessions previously launched.

The two modes

The pipeline can be executed in two modes: test mode and execution mode. When you are developing a experiment, you'd want to use the test mode. The pipeline when executed without any additional arguments will be executed in the test mode. Note that the test mode uses it's own config file experiments_test.config, that functions similar to the experiments.config file. To execute in execution mode, pass -r to the above command:

python pipeline.py -r

Differences between test mode and execution mode (default behaviour):

Test mode Execution mode
Uses experiments_test.config Uses experiments.config
The experiment directory is a temporary directory which will be cleared each time the experiment is executed The experiment directory is a directory defined by the name of the experiment and versions EXPERIMENT_DIR_SUFFIX
If an exception is raised, the pipeline will halt is execution by raising the exception to the top level Any exception raised will not stop the pipeline, the error will be logged and the pipeline will continue process with other versions and experiments
No results or logs will be recorded in the output files All logs and outputs will be recorded in the output files

Extra

I use an experiment log to maintain the experiments, which kinda ties into how I use the pipeline. For more info on that: Experiment log - How I keep track of my ML experiments

The practices I have grown to follow are described in this post: Practices I follow with the machine learning pipeline

Other projects that address similar problems (I'd be trying to combine them in the future iterations of the pipeline):

Release files for mlpipeline 1.1a3.post11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mlpipeline 1.1a3.post11
File Size Uploaded
mlpipeline-1.1a3.post11.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mlpipeline 1.1a3.post11
File Interpreter ABI Platform
mlpipeline-1.1a3.post11-py3-none-any.whl Python 3 none any Details

Total release size: 46.7 kB

Release files / mlpipeline-1.1a3.post11.tar.gz

Download URL mlpipeline-1.1a3.post11.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4654de5c655d6d293cdf9f1107c25bb15bd053349e7ab57d30c5e6aef5c2ddcf
BLAKE2b-256 checksum
How to use checksums
aee6200d424579884b35a7aaab35377d5faf18a4f129db3923cfd6afeca8fae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.3

Release files / mlpipeline-1.1a3.post11-py3-none-any.whl

Download URL mlpipeline-1.1a3.post11-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52852e12258e1db8e37d482a9af66fa9b25ac3033a920a4de12720dc9d6d5fad
BLAKE2b-256 checksum
How to use checksums
d2895ca93fae06a6dad05e8d3ea6be0ac7e49e12a008a10454b13fab9fe047c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.1a3.post11 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page