Skip to content
Skillv1.0.0

wandb

Weights & Biases platform for ML experiment tracking, hyperparameter optimization, and artifact management. Log metrics, visualize training runs, run sweeps for hyperparameter tuning, and version data

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/wandb/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill wandb. Copyright stays with the author (Apache-2.0).

Weights & Biases (W&B)

Installation

# Install and login
pip install wandb
wandb login  # Enter API key from https://wandb.ai/authorize

Basic Experiment Tracking

# track_experiment.py — Log training metrics and parameters
import wandb
import random

wandb.init(
    project="my-ml-project",
    name="experiment-1",
    config={
        "learning_rate": 0.001,
        "epochs": 50,
        "batch_size": 32,
        "architecture": "resnet50",
        "optimizer": "adam",
    },
)

for epoch in range(wandb.config.epochs):
    train_loss = random.uniform(0.1, 1.0) * (1 - epoch / 50)
    val_loss = train_loss + random.uniform(0, 0.2)
    accuracy = 1 - val_loss + random.uniform(-0.05, 0.05)

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

wandb.finish()

PyTorch Integration

# pytorch_wandb.py — Track PyTorch training with automatic gradient logging
import wandb
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset

wandb.init(project="pytorch-demo", config={"lr": 0.01, "epochs": 20})

model = nn.Sequential(nn.Linear(10, 64), nn.ReLU(), nn.Linear(64, 2))
wandb.watch(model, log="all", log_freq=10)  # Log gradients and parameters

optimizer = torch.optim.Adam(model.parameters(), lr=wandb.config.lr)
criterion = nn.CrossEntropyLoss()

dataset = TensorDataset(torch.randn(1000, 10), torch.randint(0, 2, (1000,)))
loader = DataLoader(dataset, batch_size=32, shuffle=True)

for epoch in range(wandb.config.epochs):
    for x, y in loader:
        loss = criterion(model(x), y)
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
    wandb.log({"loss": loss.item(), "epoch": epoch})

wandb.finish()

Hugging Face Trainer Integration

# hf_wandb.py — Automatic logging with Hugging Face Trainer
import os
os.environ["WANDB_PROJECT"] = "hf-fine-tuning"

from transformers import TrainingArguments

training_args = TrainingArguments(
    output_dir="./results",
    report_to="wandb",
    run_name="distilbert-imdb",
    num_train_epochs=3,
    logging_steps=50,
)
# Trainer will automatically log to W&B

Hyperparameter Sweeps

# sweep_config.yaml — Define a hyperparameter sweep
program: train.py
method: bayes
metric:
  name: val/accuracy
  goal: maximize
parameters:
  learning_rate:
    distribution: log_uniform_values
    min: 0.0001
    max: 0.1
  batch_size:
    values: [16, 32, 64, 128]
  optimizer:
    values: ["adam", "sgd", "adamw"]
  dropout:
    distribution: uniform
    min: 0.1
    max: 0.5
# sweep_train.py — Training script compatible with W&B sweeps
import wandb

def train():
    wandb.init()
    config = wandb.config

    # Use config.learning_rate, config.batch_size, etc.
    for epoch in range(10):
        loss = 1.0 / (epoch + 1) * (1 / config.learning_rate)
        accuracy = 1 - loss / 100
        wandb.log({"val/accuracy": accuracy, "train/loss": loss})

    wandb.finish()

# Create and run sweep
sweep_id = wandb.sweep(sweep="sweep_config.yaml", project="sweep-demo")
wandb.agent(sweep_id, function=train, count=20)

Artifacts (Data and Model Versioning)

# artifacts.py — Version datasets and models with W&B Artifacts
import wandb

# Log a dataset artifact
run = wandb.init(project="artifacts-demo", job_type="data-prep")
artifact = wandb.Artifact("my-dataset", type="dataset", description="Training dataset v1")
artifact.add_dir("./data/processed/")
run.log_artifact(artifact)
run.finish()

# Use the artifact in training
run = wandb.init(project="artifacts-demo", job_type="training")
artifact = run.use_artifact("my-dataset:latest")
data_dir = artifact.download()

# Log a model artifact
model_artifact = wandb.Artifact("my-model", type="model")
model_artifact.add_file("model.pt")
run.log_artifact(model_artifact)
run.finish()

Tables and Media Logging

# tables.py — Log rich media, tables, and images
import wandb
import numpy as np

wandb.init(project="media-demo")

# Log images
images = [wandb.Image(np.random.rand(28, 28), caption=f"Sample {i}") for i in range(5)]
wandb.log({"examples": images})

# Log a table
table = wandb.Table(columns=["input", "prediction", "label", "correct"])
table.add_data("Hello", "positive", "positive", True)
table.add_data("Terrible", "negative", "negative", True)
table.add_data("Okay", "positive", "neutral", False)
wandb.log({"predictions": table})

wandb.finish()

Key Concepts

  • Runs: Individual experiment executions with automatic system metrics (GPU, CPU, memory)
  • Config: Hyperparameters tracked per run — use wandb.config for consistency
  • Sweeps: Bayesian, grid, or random hyperparameter search with early stopping
  • Artifacts: Version datasets, models, and other files with lineage tracking
  • wandb.watch(): Automatically log model gradients and parameters during training
  • Reports: Create shareable dashboards and reports from experiment data in the W&B UI

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-wandb/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-wandb.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-wandb",
  "kind": "skill",
  "name": "wandb",
  "description": "Weights & Biases platform for ML experiment tracking, hyperparameter optimization, and artifact management. Log metrics, visualize training runs, run sweeps for hyperparameter tuning, and version datasets and models.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "data_analysis"
    ],
    "tags": [
      "skill-md",
      "experiment-tracking",
      "hyperparameter-tuning",
      "visualization",
      "artifacts",
      "ml-ops",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Weights & Biases platform for ML experiment tracking, hyperparameter optimization, and artifact management. Log metrics, visualize training runs, run sweeps for hyperparameter tuning, and version datasets and models."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/wandb/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/wandb/SKILL.md",
      "key": "terminalskills/skills/skills/wandb/SKILL.md"
    },
    "compatibility": "python 3.7+, wandb 0.15+, Linux/macOS/Windows",
    "license": "Apache-2.0"
  },
  "instructions": "# Weights & Biases (W&B)\n\n## Installation\n\n```bash\n# Install and login\npip install wandb\nwandb login  # Enter API key from https://wandb.ai/authorize\n```\n\n## Basic Experiment Tracking\n\n```python\n# track_experiment.py — Log training metrics and parameters\nimport wandb\nimport random\n\nwandb.init(\n    project=\"my-ml-project\",\n    name=\"experiment-1\",\n    config={\n        \"learning_rate\": 0.001,\n        \"epochs\": 50,\n        \"batch_size\": 32,\n        \"architecture\": \"resnet50\",\n        \"optimizer\": \"adam\",\n    },\n)\n\nfor epoch in range(wandb.config.epochs):\n    train_loss = random.uniform(0.1, 1.0) ",
  "cost": {
    "context_tokens": 1271
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-wandb/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.