Skip to main content

Malet: a tool for machine learning experiment

Project description

Malet

Malet: a tool for machine learning experiment

Full Documentation | Changelog

Malet (Machine Learning Experiment Tool) is a tool for hyperparameter grid searches, metric logging, advanced analyses and visualizations.

Gallery

Minimum metric plot Animated curve plot Lambda schedule plot Animated lambda learning-rate plot Interval validation accuracy plot Lambda distribution plot Dense lambda validation accuracy plot Lambda distribution plot Small lambda distribution plot Lambda distribution plot Lambda distribution plot Lambda distribution plot

Features

  • 🔎 Easy & powerful hyperparameter grid search syntax
  • 📝 Experiment metric logging and resuming system
  • 📊 Flexible data process and visualization tools
  • 🚀 Search parallelization for multi-gpus

Installation

pip install malet

From source:

pip install git+https://github.com/dongyeoplee2/Malet.git

For development (uses uv):

uv sync

Quick Start

1. Prerequisite

Experiment Folder

Using Malet starts with making a folder with a single yaml config file. Various files resulting from some experiment is saved in this single folder. We advise to create a folder for each experiment under experiments folder.

experiments/
└── {experiment folder}/
    ├── exp_config.yaml : experiment config yaml file            (User created)
    ├── log.tsv         : log file for saving experiment results (generated by malet.experiment)
    ├── (log_splits)    : folder for splitted logs               (generated by malet.experiment)
    └── figure          : folder for figures                     (generated by malet.plot)

Pre-existing training pipeline

Say you have some training pipeline that takes in a configuration (any object w/ dictionary-like interface). We require you to return the result of the training so it gets logged.

def train(config, ...):
    ...
    # training happens here
    ...
    metric_dict = {
        'train_accuracies': train_accuracies,
        'val_accuracies': val_accuracies,
        'train_losses': train_losses,
        'val_losses': val_losses,
    }
    return metric_dict

2. Running experiments

Experiment config yaml

You can configure as you would do in the yaml file. But we provide useful special keyword grid, used as follows:

# static configs
model: LeNet5
dataset: mnist

num_epochs: 100
batch_size: 128
optimizer: adam

# grided fields
grid:
  seed: [1, 2, 3]
  lr: [0.0001, 0.001, 0.01, 0.1]
  weight_decay: [0.0, 0.00005, 0.0001]

Specifying list of config values under grid lets you run all possible combination (i.e. grid) of your configurations, with field least frequently changing in the order of declaration in grid.

Running experiments

The following will run the train_fn on grid of configs based on {exp_folder_path} and train_fn.

from functools import partial
from malet.experiment import Experiment

train_fn = partial(train, ...{other arguments besides config}..)
metric_fields =  ['train_accuracies', 'val_accuracies', 'train_losses', 'val_losses']
experiment = Experiment({exp_folder_path}, train_fn, metric_fields)
experiment.run()

Note that you need to partially apply your original function so that you pass in a function with only config as its argument.

Experiment logs

The experiment log will be automatically saved in the {exp_folder_path} as log.tsv, where the static configs and the experiment log are each saved in yaml and tsv like structure respectively. You can retrieve these data in python using ExperimentLog in malet.experiment as follows:

from malet.experiment import ExperimentLog

log = ExperimentLog.from_tsv({tsv_file})

static_configs = log.static_configs
df = log.df

Experiment logs also enable resuming to the most recently run config when a job is suddenly killed.

3. Plot making

Running malet.plot lets you make plots based on log.tsv in the experiment folder.

malet-plot \
-exp_folder ../experiments/{exp_folder} \
-mode curve-epoch-train_accuracy

The key intuition for using this is to leave only two fields in the dataframe for the x-axis and the y-axis by

  1. specifying a specific value (_e.g._ther hyperparameters),

which will leave only one value for each field.

Available plot modes: curve, curve_best, bar, heatmap, scatter, scatter_heat.

For the full list of CLI arguments, plot configuration options, advanced gridding, parallel GPU training, checkpointing, and more, see the full documentation.

Citation

If you find Malet useful, please cite it as:

@software{lee2024malet,
  author       = {Dongyeop Lee},
  title        = {Malet: Machine Learning Experiment Tool},
  year         = {2024},
  url          = {https://github.com/dongyeoplee2/Malet},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

malet-0.2.2.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

malet-0.2.2-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file malet-0.2.2.tar.gz.

File metadata

  • Download URL: malet-0.2.2.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for malet-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a8440ecba5b5b0f7722d867314233dd45962e2853ace92b65b47718b0b85ce4e
MD5 8056a24d5ca54d14b40e5f9deee03bde
BLAKE2b-256 109230fee3f5320fb4a1c8ebe1c1eac87966e34207333ca55a11857c2df75565

See more details on using hashes here.

File details

Details for the file malet-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: malet-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for malet-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6176de20bb83642d0c6a12076bb07e7df9864595ecdbb73615bb21e118581394
MD5 2dbf0cfc8f5135d9d87b18de45e76730
BLAKE2b-256 e8335b36855777ec139d14c146a2e929eae1469bc17b48c0aa0c508dc36c532d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page