HOW-TO

Reproduce an Experiment

Reproduce an Experiment

See also: API: laco.save / laco.load, Concepts: App Loop

Save the Config Before Training

import laco, pathlib

cfg = laco.load("configs/train.py?lr=5e-4")
run_dir = pathlib.Path("runs/2024-01-15_lr5e-4")
run_dir.mkdir(parents=True, exist_ok=True)

laco.save(cfg, run_dir / "config.yaml")
# train…

laco.save writes a Hydra-compatible YAML file including the _laco_: 1 schema marker. All _target_ strings, kwargs, and fully-resolved interpolations are preserved.

Reload and Reproduce

cfg = laco.load(run_dir / "config.yaml")
model = laco.instantiate(cfg.model)
# Identical model to the original run

No .py config file is needed: the YAML is self-contained.

runs/
  {run_id}/
    config.yaml      ← archived by laco.save
    checkpoints/
      epoch_10.pt
    metrics.jsonl

Use a run ID that embeds the date and key hyperparameters for human readability: 2024-01-15_lr5e-4_adam.

What Survives Serialization

SurvivesDoes not survive
_target_ pathsObjects with no _target_ (plain instances)
Primitive kwargsTensors wrapped with L.just (serialized as class path only)
Resolved interpolationsOpen file handles
Nested L.call treesLambda functions

For values that don't survive, store a path, identifier, or descriptor instead.

Automating with @L.task

@L.task
def run(model, optimizer, num_steps=1000):
    laco.save(cfg, run_dir / "config.yaml")  # archive before starting
    ...

Or use laco.main, which accepts a hydra.run.dir override:

python train.py hydra.run.dir=runs/my_run