Logging Artifacts

LitLogger can store and retrieve files and model artifacts associated with your experiments. The modern path is the file-like API with File and Model, while the older helper methods remain available for compatibility.

New Dict-Style API

Use the returned Experiment and assign file-like wrappers directly:

import litlogger
from litlogger import File, Model

experiment = litlogger.init(name="my-experiment")
experiment["config"] = File("config.yaml")
experiment["checkpoint"] = Model("checkpoint.ckpt")

experiment["reports"].append(File("report-0.txt"))
experiment["checkpoints"].append(Model("checkpoint-1.ckpt", version="step-1"))

experiment.finalize()

Log and Retrieve Files

The legacy helper API is still supported for explicit file upload/download workflows through log_file() and get_file():

import litlogger

litlogger.init(name="my-experiment")
litlogger.log_file("config.yaml")
litlogger.log_file("checkpoint.pt", remote_path="checkpoints/best.pt")
litlogger.finalize()

litlogger.init(name="my-experiment")
litlogger.get_file("/tmp/config.yaml", remote_path="config.yaml")
litlogger.get_file("/tmp/best.pt", remote_path="checkpoints/best.pt")
litlogger.finalize()

Logging Multiple Files

log_files() uploads a list of files in parallel for better throughput:

exp = litlogger.init(name="my-experiment")
exp.log_files(
    paths=["img_0.png", "img_1.png", "img_2.png"],
    remote_paths=["images/0.png", "images/1.png", "images/2.png"],
)

Log and Retrieve Models

LitLogger integrates with litmodels for storing and loading model objects. The legacy helper API still supports direct model-object logging through log_model() and get_model():

import torch.nn as nn
import litlogger

litlogger.init(name="my-experiment")
model = nn.Linear(10, 1)
litlogger.log_model(model)
litlogger.finalize()

litlogger.init(name="my-experiment")
loaded_model = litlogger.get_model()
litlogger.finalize()

Logged models appear in the Weights tab of Lightning AI rather than the experiment’s Experiments tab, because model storage is handled through the model registry rather than the artifact list. For background, see the Lightning model registry docs.

Logging Model Files

If you already have saved model files on disk, use log_model_artifact():

exp = litlogger.init(name="my-experiment")
exp.log_model_artifact("checkpoints/epoch_10.ckpt", version="epoch-10")
exp.log_model_artifact("model_export/", version="export-v2")

Download model artifacts back with get_model_artifact():

exp.get_model_artifact("local_checkpoint.ckpt", version="epoch-10")

Automatic Checkpoint Logging

When using lightning.pytorch.loggers.LitLogger with log_model=True, checkpoints saved by Lightning’s ModelCheckpoint callback are automatically uploaded as model artifacts.

Was this page helpful?

What went wrong?

↑↓ Navigate↵ Open⌘↵ New tabesc Close