Dora Search

0.1.12 · active · verified Sun Apr 12

Dora Search is an experiment management tool developed by Facebook Research, designed to simplify grid searches and hyperparameter tuning for machine learning projects. It helps organize experiments, log results, and ensure reproducibility. Currently at version 0.1.12, it has an active development pace with frequent minor updates, focusing on robust experiment tracking and launch capabilities.

Warnings

Install

Imports

Quickstart

This quickstart defines a simple `train_model` function that accepts a configuration dictionary. It then sets up a hyperparameter grid using `dora.xp.arg` and uses `dora.main` to launch multiple experiments, one for each combination in the grid. Dora automatically creates and manages experiment directories, passing configuration parameters and internal metadata (like `_xp_id` and `_xp_dir`) to your function.

import dora
import dora.xp as xp
import time
import os
from typing import Dict

def train_model(config: Dict):
    """Simulates a training run with a given configuration."""
    print(f"[Experiment {config.get('_xp_id', 'local')}] Running with config: {config}")
    # Simulate some work
    time.sleep(0.1)
    result = config["lr"] * config["batch_size"]
    print(f"[Experiment {config.get('_xp_id', 'local')}] Result: {result}")

    # Dora automatically saves results in the experiment directory
    xp_dir = config.get('_xp_dir')
    if xp_dir:
        os.makedirs(xp_dir, exist_ok=True)
        with open(os.path.join(xp_dir, 'metrics.json'), 'w') as f:
            import json
            json.dump({'loss': result, 'accuracy': 1 - result / 100}, f)

    return {"loss": result, "accuracy": 1 - result / 100}

# Define the grid search parameters
grid = [
    xp.arg("lr", [0.01, 0.1, 1.0]),
    xp.arg("batch_size", [16, 32])
]

if __name__ == "__main__":
    print("Launching Dora experiments...")
    # dora.main is the recommended way to launch experiments
    # It will iterate through the grid, call train_model for each configuration,
    # and manage experiment directories and logs.
    dora.main(train_model, grid=grid)
    print("Dora experiments finished.")

view raw JSON →