🧐SwanLab: a tool for your machine learning log tracking and experiment management. Join our WeChat ⬇️

SwanHubX SwanHubX Last update: Jan 17, 2024

SwanLab Library

Track and visualize all the pieces of your machine learning pipeline

license license pypi Download Github Discussion

SwanLab Head Image

👀 View Document | 👋 Join our WeChat

English | 中文

Table of Contents


Changelog

Upgrade to the latest version: pip install -U swanlab

[24/03/01] 🚀 Still Very Big Upgrade!We supported Text Chartto meet the needs of tasks in NLP, LLM, Agent and other scenarios; We have made a lot of optimizations to line chart's UI, legend, and rendering speed. We improved the rendering performance of Logs —— now viewing terminal printing information with 200k lines is also not lagging.(v0.2.1)

[24/02/08] 🔥 Very Big Upgrade! We supported Image ChartAudio Chart、Mutil-Experiments Chart and a series of comprehensive optimizations and improvements! Please be sure to upgrade to the latest version via pip install -U swanlab.(v0.2.0)

[24/01/25] 😄 We supported a new Config/Summary table component that supports parameter search. Additionally, we've used new fonts and color schemes.(v0.1.6)

Full Changelog


Key Function

  • 📊 Visualize Training: visualize your entire training process.
  • 🚀 Multimedia Charts: log Image/Audio/Video/Text/object3D...
  • 🧪 Experiments GridView: compare your key metrics for inspiration faster.
  • ⚡️ Auto Save Environment Info: Hyperparameters, Config, Metric, Terminal logging, Environment Information auto save.

  • 🥔 Offline Support: SwanLab can run entirely offile, ithout requiring any access to the Internet. For instance, this may be on your local machine, behind a corporate firewall, or in a datacenter.


Installation

with pip

Requirement:Python 3.8+.

Use pip to install our stable release version. The installation command is as follows:

pip install -U swanlab

with source code

If you need the bleeding edge of the code and can't wait for a new release, you must install the library from source


Getting Started

  1. First, install the SwanLab SDK with pip:
pip install -U swanlab
  1. Second, Use the example code snippet below as a template to integrate SwanLab to your Python script:
import swanlab

# Start a SwanLab Run with swanlab.init
swanlab.init(
  # Save model inputs and hyperparameters in a swanlab.config object
  config={'epochs': 20, 'learning_rate': 0.01}, 
  # Specify the save path of the log file
  logdir="./logs",
)

# Model training code here...

# Log metrics over time for visualizing performance with swanlab.log
for epoch in range(1, swanlab.config.epochs):
    swanlab.log({"loss": loss})

For example, We wrote a simulation experiment script:

import swanlab
import random

offset = random.random() / 5

run = swanlab.init(
    experiment_name="Example",
    description="It's a ML experiment.",
    config={
        "learning_rate": 0.01,
        "epochs": 20,
    },
    logdir="./logs"
)

# Simulate the ML training process
for epoch in range(2, run.config.epochs):
    acc = 1 - 2**-epoch - random.random() / epoch - offset
    loss = 2**-epoch + random.random() / epoch + offset
    swanlab.log({"loss": loss, "accuracy": acc})
  1. Third, open the terminal and use the following command to start a SwanLab dashboard:
$ swanlab watch -l ./logs

SwanLab will give you a URL link (default is http://127.0.0.1:5092). Check the link to see the visualization results of your first experiment in the browser.


Tutorial

Get Started

Python API

CLI API

技巧


Use Case

Learn how to use SwanLab more effectively by following these use cases:

Code Cases Description
Hello World Getting Started
MNIST Handwriting recognition based on a plain net and MNIST dataset with pytroch, swanlab.
Image Classification Cat and dog classification based on ResNet50 with pytorch, swanlab and gradio. Tutorial.
Text Generation Text generation based on Word_language_model (RNN/LSTM/GRU/Transformer)
UIE-Finetune how to use personal data to finetune UIE model and monitor training process through swanlab

LICENSE

This project is currently licensed under Apache 2.0 License.

PRAGMA foreign_keys = off; BEGIN TRANSACTION; COMMIT TRANSACTION; PRAGMA foreign_keys = on;

Subscribe to our newsletter