Four-Way SDK Approach¶
WeightsLab is structured in four independent levels:
Model interaction
Data exploration
Config management (hyperparameters)
Logger and signals
You can use each level alone, or combine all four in one script, with or without Weights Studio.
Level map¶
Level |
Main goal |
Main page |
|---|---|---|
Model interaction |
Inspect and control model/optimizer/loss runtime behavior |
|
Data exploration |
Tag, discard, and query difficult samples |
|
Config management |
Live update experiment configuration |
|
Logger and signals |
Persist and analyze per-step/per-sample trajectories |
Standalone examples, one per level¶
Each level ships as a self-contained, runnable MNIST script that registers only
that level. Run any of them with no arguments, then attach the CLI
(weightslab cli) or open the studio (weightslab start) from another shell.
Level |
Run it |
Bundled example |
What it proves |
|---|---|---|---|
Model interaction |
|
|
Trains MNIST with only the model + optimizer wrapped; logs
|
Data exploration |
|
|
Tags, discards, queries and exports MNIST samples with no model at all |
Config management |
|
|
A live |
Logger and signals |
|
|
Train/eval curves, history export and |
What each level needs on its own:
An experiment directory. The config level provides it via
root_log_dir; the other three readWEIGHTSLAB_ROOT_LOG_DIR(the variableweightslab start [DIR]exports), which the examples set themselves.wl.serve()warns instead of failing when no serving config was wrapped, andwl.start_training()only waits on the levels you actually registered, so a single-level run reaches its first guarded step.
Two boundaries are worth knowing before mixing and matching:
Per-sample and per-instance signals need the data level, because sample ids are routed into the tracked sample dataframe. Step-level curves do not.
evaluatein the CLI needs a registered loader to evaluate.
Minimal integration order¶
import weightslab as wl
import torch.nn as nn
import torch.optim as optim
# ...
# 1) Register shared hyperparameters
hp = wl.watch_or_edit(parameters, flag="hyperparameters", defaults=parameters)
# ...
# 2) Register tracked loaders
train_loader = wl.watch_or_edit(train_dataset, flag="data", loader_name="train_loader", is_training=True)
val_loader = wl.watch_or_edit(val_dataset, flag="data", loader_name="val_loader")
# ...
# 3) Register model stack
model = wl.watch_or_edit(my_model, flag="model", device="cuda")
optimizer = wl.watch_or_edit(optim.Adam(model.parameters(), lr=hp["optimizer"]["lr"]), flag="optimizer")
train_loss = wl.watch_or_edit(nn.CrossEntropyLoss(reduction="none"), flag="loss", signal_name="train/loss", per_sample=True, log=True)
# ...
# 4) Start WeightsLab services
wl.serve(serving_grpc=True, serving_cli=True)
wl.start_training(timeout=3)
# ...
# 5) Route train/eval steps explicitly
with wl.guard_training_context:
pass
with wl.guard_testing_context:
pass
# ...
# 6) Keep services alive for post-run UI/CLI analysis
wl.keep_serving()
Where the agent fits¶
After the four levels are in place, use Experiment Agent Assistant as an optional accelerator for natural-language operations from UI or CLI (tag/discard/filter/report/model actions) without changing your training loop.
Recommended next reading¶
Now that you understand the four levels, you can explore them in more detail:
Model Interaction: inspect and control model/optimizer/loss runtime behavior.
Data Exploration: tag, discard, and query difficult samples.
Config Management: live update experiment configuration.
Logger and Signals: persist and analyze per-step/per-sample trajectories.