SwanLab is a robust open-source machine-learning training management tool for researchers. By using SwanLab, researchers can accumulate training experience and discover new ideas.
English | 简体中文
- ⚽ Real-time Indicator Record: A few lines of code can record your training metrics in real time.
- 🧪 Multiple Experimental Comparisons: Support multiple experimental metric comparisons.
- 🤖 ML Support:: Support mainstream training frameworks such as PyTorch, TensorFlow, Transformers, mmdetection.
- 📝 Environmental Record: Support automatic logging, error reporting, system hardware, Python environment and other environmental information.
- 🖥 Local and Public Cloud Support: Supports both local and public cloud (coming soon).
We've got some example code and articles to help you get a better grip on SwanLab:
Hey, whether you're a developer or an everyday user, this quick-start guide will get you started and show you how to use SwanLab:
- Record training settings
- Keep track of key metrics
- Visualize experiments
$ pip install -U swanlab
If we break down the training process in machine learning, it's basically all about tweaking settings, looping, and keeping an eye on the metrics we care about.
The following Python code simulates this:
import swanlab
# Initialization
swanlab.init()
for epoch in range(1, 20):
print("epoch", epoch)
# Tracking index: `epoch`
swanlab.log({"epoch": epoch})
Among them, swanlab.init
is necessary, which is used to initialize the instance and configure parameters; The function of swanlab.log
is responsible for recording data, and the received data type is a dictionary (dict).
When running the above code, you will see the following output result:
[SwanLab-INFO]: Run data will be saved locally in path/swanlog/majestic-hemlock-1
[SwanLab-INFO]: Experiment_name: majestic-hemlock-1
[SwanLab-INFO]: Run `swanlab watch` to view SwanLab Experiment Dashboard
epoch 1
epoch 2
epoch 3
epoch 4
epoch 5
epoch 6
epoch 7
epoch 8
epoch 9
[SwanLab-INFO]: train successfully
And there will be swanlog
folder in the root directory, which contains files automatically generated by SwanLab, recording a series of experimental data.
Now let's check the status of the instructions recorded by SwanLab in each loop step.
Run the command swanlab watch
:
$ swanlab watch
[SwanLab-INFO]: SwanLab Experiment Dashboard ready in 375ms
➜ Local: http://127.0.0.1:5092
Visit http://127.0.0.1:5092, open the experiment dashboard, and access the experiment that was just run.
In this section, let's write an advanced training script to simulate real machine learning training.
First, initialize swanlab and set the experiment name, description, and configuration:
swanlab.init(
# Set experiment name
experiment_name="sample_experiment",
# Set description
description="This is a sample experiment for machine learning training.",
# Record tracked hyperparameters and run metadata.
config={
"learning_rate": lr,
"epochs": epochs,
},
)
Combine into 1 complete training script, use swanlab.log
API to track the loss value loss
and accuracy accuracy
:
import swanlab
import time
import random
lr = 0.01
epochs = 20
offset = random.random() / 5
swanlab.init(
# Set experiment name
experiment_name="sample_experiment",
# Set description
description="This is a sample experiment for machine learning training.",
# Record tracked hyperparameters and run metadata.
config={
"learning_rate": lr,
"epochs": epochs,
},
)
# Simulated machine learning training process
for epoch in range(2, epochs):
acc = 1 - 2**-epoch - random.random() / epoch - offset
loss = 2**-epoch + random.random() / epoch + offset
print(f"epoch={epoch}, accuracy={acc}, loss={loss}")
# Tracking index: 'loss' and 'accuracy'
swanlab.log({"loss": loss, "accuracy": acc})
time.sleep(1)
Similarly, run swanlab watch
to start the experiment dashboard:
- Document:Complete API documentation and guides.
- SwanLab-examples:Official code examples.
Join SwanLab Community to share your ideas, suggestions, or questions and connect with other users and contributors.
WeChat or Github Discussions:
This project is currently licensed under Apache 2.0 License。