Skip to content

dongyeoplee2/Malet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

139 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Malet

Malet: a tool for machine learning experiment

Full Documentation | Changelog

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

This is a pet project I'm developing for personal research, and it is yet unstable. Kinda having fun with its architecture, cosmetics, and documentations. Don't really know where this is going:)

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},
}

About

Hyperparameter search and metric visualization tool for personal research.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages