跳到正文
Skillpedia
机器学习14k · #11163

experiment-tracking-swanlab

它能做什么

这项技能设置 SwanLab,这是一个用于记录和比较机器学习训练运行的开源工具。适合希望实验得到跟踪、又不依赖托管云服务的研究人员。

适用场景

  • ✓当你想为每次训练运行记录指标、设置和笔记的时候。
  • ✓当你想比较不同随机种子、检查点或设置下的运行结果的时候。
  • ✓当你想把实验仪表板保存在自己的电脑或服务器上的时候。

技能链接

https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/13-mlops/swanlab/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/13-mlops/swanlab/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我为训练脚本设置 SwanLab,这样我可以记录损失,并在自己的电脑上比较不同的运行?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会安装 SwanLab,在脚本中加入带有运行名称和设置的日志记录,如果你需要,还会启动本地仪表板。它也可以记录图像、音频和文本,并连接常见的训练框架。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

SwanLab: Open-Source Experiment Tracking

When to Use This Skill

Use SwanLab when you need to:

  • Track ML experiments with metrics, configs, tags, and descriptions
  • Visualize training with scalar charts and logged media
  • Compare runs across seeds, checkpoints, and hyperparameters
  • Work locally or self-hosted instead of depending on managed SaaS
  • Integrate with PyTorch, Transformers, PyTorch Lightning, or Fastai

Deployment: Cloud, local, or self-hosted | Media: images, audio, text, GIFs, point clouds, molecules | Integrations: PyTorch, Transformers, PyTorch Lightning, Fastai

Installation

# Install SwanLab plus the media dependencies used in this skill
pip install "swanlab>=0.7.11" "pillow>=9.0.0" "soundfile>=0.12.0"

# Add local dashboard support for mode="local" and swanlab watch
pip install "swanlab[dashboard]>=0.7.11"

# Optional framework integrations
pip install transformers pytorch-lightning fastai

# Login for cloud or self-hosted usage
swanlab login

pillow and soundfile are the media dependencies used by the Image and Audio examples in this skill. swanlab[dashboard] adds the local dashboard dependency required by mode="local" and swanlab watch.

Quick Start

Basic Experiment Tracking

import swanlab

run = swanlab.init(
    project="my-project",
    experiment_name="baseline",
    config={
        "learning_rate": 1e-3,
        "epochs": 10,
        "batch_size": 32,
        "model": "resnet18",
    },
)

for epoch in range(run.config.epochs):
    train_loss = train_epoch()
    val_loss = validate()

    swanlab.log(
        {
            "train/loss": train_loss,
            "val/loss": val_loss,
            "epoch": epoch,
        }
    )

run.finish()

With PyTorch

import torch
import torch.nn as nn
import torch.optim as optim
import swanlab

run = swanlab.init(
    project="pytorch-demo",
    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()

Core Concepts

1. Projects and Experiments

Project: Collection of related experiments
Experiment: Single execution of a training or evaluation workflow

import swanlab

run = swanlab.init(
    project="image-classification",
    experiment_name="resnet18-seed42",
    description="Baseline run on ImageNet subset",
    tags=["baseline", "resnet18"],
    config={
        "model": "resnet18",
        "seed": 42,
        "batch_size": 64,
        "learning_rate": 3e-4,
    },
)

print(run.id)
print(run.config.learning_rate)

2. Configuration Tracking

config = {
    "model": "resnet18",
    "seed": 42,
    "batch_size": 64,
    "learning_rate": 3e-4,
    "epochs": 20,
}

run = swanlab.init(project="my-project", config=config)

learning_rate = run.config.learning_rate
batch_size = run.config.batch_size

3. Metric Logging

# Log scalars
swanlab.log({"loss": 0.42, "accuracy": 0.91})

# Log multiple metrics
swanlab.log(
    {
        "train/loss": train_loss,
        "train/accuracy": train_acc,
        "val/loss": val_loss,
        "val/accuracy": val_acc,
        "lr": current_lr,
        "epoch": epoch,
    }
)

# Log with custom step
swanlab.log({"loss": loss}, step=global_step)

4. Media and Chart Logging

import numpy as np
import swanlab

# Image
image = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)
swanlab.log({"examples/image": swanlab.Image(image, caption="Augmented sample")})

# Audio
wave = np.sin(np.linspace(0, 8 * np.pi, 16000)).astype("float32")
swanlab.log({"examples/audio": swanlab.Audi
常见问题

它需要账号吗?

使用云端或自托管版本需要登录,而本地仪表板可以在你自己的电脑上运行。

它能连接哪些框架?

PyTorch、Transformers、PyTorch Lightning 和 Fastai。

它能显示图像等媒体内容吗?

能。它可以记录图像、音频、文本、GIF、点云和分子。

详情

作者的原始描述

Provides guidance for experiment tracking with SwanLab. Use when you need open-source run tracking, local or self-hosted dashboards, and lightweight media logging for ML workflows.

repo: Orchestra-Research/AI-Research-SKILLs

热度

GitHub 星标
14k
排名
#11163
许可证
MIT
更新时间
2026/10/10

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能