Skip to content
LaunchHelm
Documentation — Examples

Examples

Runnable Python files. Download one, export the four LAUNCHHELM_* variables from Getting started, and run it on your training machine.

Every example uses the project name quickstart — the project your key was issued for must match, so change the literal or name the project to match.

First run — log_run.py

python log_run.py
import launchhelm

with launchhelm.init("quickstart", name="first-run", config={"lr": 0.0003}) as run:
    for step in range(8):
        loss = 2.0 / (step + 1)
        run.log({"loss": loss, "lr": 0.0003}, step=step)

print("run finished:", run.run_id)

python-log_run.py · verbatim from sdks/python/examples/log_run.py

Rich values — rich_values.py

Text, an image, a table and histograms on one run, then a read-back.

    run.rows("sweep", [
        {"trial": "a", "lr": 0.001, "loss": 0.42},
        {"trial": "b", "lr": 0.003, "loss": 0.31},
    ], step=3)

    run.histogram("gradients", [0.0, 0.1, 0.4, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 1.0],
                  bins=4, step=3)

python-rich_values.py · verbatim from sdks/python/examples/rich_values.py

Reading points back — query_points.py

Prints one bounded page for a stream id — copy the id from the run page:

python query_points.py <stream-id>
result = client.query(
    stream_id,
    start="1970-01-01T00:00:00Z",
    end="2261-01-01T00:00:00Z",
    limit=1000,
)
for point in result.get("items", []):
    print(point.get("observed_at"), point.get("value"))

python-query_points.py · verbatim from sdks/python/examples/query_points.py

Artifacts — artifact_upload.py

Uploads a file to a run and verifies the recorded sha256 digest.

    with launchhelm.init("quickstart", name="artifact-demo") as run:
        artifact = run.artifact(path, step=0, name="weights")
        print("artifact:", artifact.id)
        print("sha256 match:", artifact.spec.get("sha256") == expected)

python-artifact_upload.py · verbatim from sdks/python/examples/artifact_upload.py

System metrics — system_metrics.py

Host metrics on a run without torch. Requires the system extra.

with launchhelm.init("quickstart", name="system-demo") as run:
    launchhelm.system.start(run, interval=2.0)
    for step in range(8):
        run.log({"loss": 2.0 / (step + 1)}, step=step)
        time.sleep(0.5)

python-system_metrics.py · verbatim from sdks/python/examples/system_metrics.py

PyTorch — torch_quickstart.py

A real training step with a dashboard-tunable dropout. Requires the torch extra.

tr = lht.init("quickstart", name="torch-quickstart", config={"lr": 0.01})
tr.watch(model, optimizer)
dropout_p = tr.tunable("dropout_p", 0.0, minimum=0.0, maximum=0.9)

python-torch_quickstart.py · verbatim from sdks/python/examples/torch_quickstart.py

Checkpoints — torch_checkpoint.py

Saves a checkpoint, ends the session with the run left open, then resumes it in a fresh trainer and restores the latest checkpoint. Requires the torch extra.

model2, optimizer2 = build()
tr2 = lht.init("quickstart", resume=run_id)
tr2.watch(model2, optimizer2)
extra = tr2.load_checkpoint("latest")

python-torch_checkpoint.py · verbatim from sdks/python/examples/torch_checkpoint.py

DDP — torch_ddp.py

Two-rank CPU DDP under torchrun:

torchrun --master_addr=127.0.0.1 --master_port=29500 \
    --nproc_per_node=2 torch_ddp.py
    tr = lht.init("quickstart", name="ddp-run", system_metrics=True)
    tr.watch(model, optimizer)

python-torch_ddp.py · verbatim from sdks/python/examples/torch_ddp.py

Commands — change_learning_rate.py

Registers set_lr at the after_step safe point; issue it from the run's Controls tab while it runs.

schedule = Schedule()
with launchhelm.init("quickstart", config={"lr": schedule.lr}) as run:
    run.command("after_step")(schedule.set_lr)

python-change_learning_rate.py · verbatim from sdks/python/examples/change_learning_rate.py

Two commands, one safe point — experiment.py

set_schedule and duplicate_layer share after_step; sync services whichever is waiting.

with launchhelm.init("quickstart", config={"lr": experiment.lr}) as run:
    run.command("after_step")(experiment.set_schedule)
    run.command("after_step")(experiment.duplicate_layer)

python-experiment.py · verbatim from sdks/python/examples/experiment.py

Custom trainer — placeholder_trainer.py

A stand-in trainer with a resumable run (LAUNCHHELM_RESUME), two commands, and run.keep state snapshots.

    with launchhelm.init("quickstart", name="placeholder", resume=resume) as run:
        if run.restored:
            trainer.load(run.restored)
        run.command("after_step")(trainer.set_schedule)
        run.command("after_step")(trainer.duplicate_layer)

python-placeholder_trainer.py · verbatim from sdks/python/examples/placeholder_trainer.py

Framework callbacks — hf_trainer.py, lightning_trainer.py

One callback each for transformers.Trainer (hf extra) and PyTorch Lightning (lightning extra). See Hugging Face and Lightning.

    callbacks=[LaunchHelmCallback("quickstart")],

python-hf_trainer.py · verbatim from sdks/python/examples/hf_trainer.py

    callbacks=[LaunchHelmCallback("quickstart", name="lightning-example")],

python-lightning_trainer.py · verbatim from sdks/python/examples/lightning_trainer.py