
Experiment Tracking Swanlab
Wire PyTorch (and similar) training loops to SwanLab for experiment config, metrics logging, and run lifecycle.
Overview
Experiment Tracking SwanLab is an agent skill for the Build phase that documents how to integrate SwanLab experiment tracking into PyTorch-style training loops.
Install
npx skills add https://github.com/orchestra-research/ai-research-skills --skill experiment-tracking-swanlabWhat is this skill?
- Documents SwanLab `init` / `log` / `finish` patterns aligned with public SwanLab docs
- PyTorch training-loop example with config-driven hyperparameters and batch metrics
- Minimal `SwanLabTracker` callback-style wrapper pattern for reusable logging
- Emphasizes structured `config` on run init for reproducible solo ML experiments
Adoption & trust: 2 installs on skills.sh; 9.4k GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
What problem does it solve?
You are training models locally or on a single GPU but lose track of configs, metrics, and run history across iterations.
Who is it for?
Indie ML builders adding SwanLab to PyTorch training code during active model development.
Skip if: Production product analytics, mobile app event pipelines, or teams not using Python training loops.
When should I use this skill?
User is implementing or debugging SwanLab experiment tracking in Python training code (especially PyTorch).
What do I get? / Deliverables
Your training scripts emit structured SwanLab runs with logged hyperparameters and metrics so you can compare experiments without ad-hoc spreadsheets.
- Instrumented training script with SwanLab `init`/`log`/`finish`
- Documented config schema for runs
Recommended Skills
Journey fit
Build is where model training code lives; experiment tracking is integrated as you implement and iterate on learning pipelines. Integrations fits third-party experiment trackers (SwanLab) plugged into training scripts rather than frontend or PM work.
How it compares
Integration skill for experiment tracking—not a full MLOps platform skill or Prism marketplace server.
Common Questions / FAQ
Who is experiment-tracking-swanlab for?
Solo builders and small teams writing PyTorch training code who want SwanLab run logging documented in an agent-friendly skill.
When should I use experiment-tracking-swanlab?
Use it in Build while integrating or refactoring training scripts to log configs and metrics to SwanLab before you benchmark model variants.
Is experiment-tracking-swanlab safe to install?
Check the Security Audits panel on this Prism page; training integrations may need network access to SwanLab—review your environment and secrets handling separately.
SKILL.md
READMESKILL.md - Experiment Tracking Swanlab
# SwanLab Framework Integrations This document focuses on framework patterns that align with the public SwanLab docs. ## PyTorch ### Basic Training Loop ```python import torch import torch.nn as nn import torch.optim as optim import swanlab run = swanlab.init( project="pytorch-training", experiment_name="mnist-mlp", config={ "learning_rate": 1e-3, "batch_size": 64, "epochs": 10, "hidden_size": 128, }, ) model = nn.Sequential( nn.Flatten(), nn.Linear(28 * 28, run.config.hidden_size), nn.ReLU(), nn.Linear(run.config.hidden_size, 10), ) optimizer = optim.Adam(model.parameters(), lr=run.config.learning_rate) criterion = nn.CrossEntropyLoss() for epoch in range(run.config.epochs): model.train() for batch_idx, (data, target) in enumerate(train_loader): optimizer.zero_grad() logits = model(data) loss = criterion(logits, target) loss.backward() optimizer.step() if batch_idx % 100 == 0: swanlab.log( { "train/loss": loss.item(), "train/epoch": epoch, "train/batch": batch_idx, } ) run.finish() ``` ### Minimal Callback Wrapper ```python import swanlab class SwanLabTracker: def __init__(self, project, experiment_name=None, config=None): self.run = swanlab.init( project=project, experiment_name=experiment_name, config=config, ) def log_metrics(self, metrics, step=None): swanlab.log(metrics, step=step) def log_images(self, name, images, captions=None): if captions is None: payload = [swanlab.Image(image) for image in images] else: payload = [ swanlab.Image(image, caption=caption) for image, caption in zip(images, captions) ] swanlab.log({name: payload}) def log_note(self, name, text): swanlab.log({name: swanlab.Text(text)}) def finish(self): self.run.finish() ``` This wrapper deliberately omits fake histogram and file helpers that are not present in current SwanLab APIs. ## Transformers ### `transformers>=4.50.0`: official one-line integration Prefer `report_to="swanlab"` on recent Transformers releases. This is the primary path documented by SwanLab. ```python from transformers import ( AutoModelForSequenceClassification, AutoTokenizer, Trainer, TrainingArguments, ) tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased") model = AutoModelForSequenceClassification.from_pretrained( "bert-base-uncased", num_labels=2, ) training_args = TrainingArguments( output_dir="./results", num_train_epochs=3, per_device_train_batch_size=16, per_device_eval_batch_size=16, evaluation_strategy="epoch", logging_steps=100, report_to="swanlab", run_name="bert-imdb", ) trainer = Trainer( model=model, args=training_args, train_dataset=train_dataset, eval_dataset=eval_dataset, ) trainer.train() ``` Set `SWANLAB_PROJ_NAME` and `SWANLAB_WORKSPACE` environment variables when you need custom routing without switching away from the official integration path. ### `transformers<4.50.0` or custom control: `SwanLabCallback` Use `SwanLabCallback` as the fallback path for older Transformers versions, or when you want SwanLab-specific control without `report_to="swanlab"`. ```python from transformers import ( AutoModelForSequenceClassification, AutoTokenizer, Trainer, TrainingArguments, ) from swanlab.integration.transformers import SwanLabCallback tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased") model = AutoModelForSequenceClassification.from_pretrained( "bert-base-uncased", num_labels=2, ) training_args = TrainingArguments( output_dir="./results", evaluation_strategy="epoch", logging_steps=100, rep