Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate SwanLab for offline/online experiment tracking and local visualization #36433

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ShaohonChen
Copy link

@ShaohonChen ShaohonChen commented Feb 26, 2025

What does this PR do?

This PR introduces SwanLab, a lightweight open-source experiment tracking tool, as a new logging option for the training framework. The integration provides both online and offline tracking capabilities, along with a local dashboard for visualizing results.

SwanLab has previously supported tracking the Transformers training framework through external callbacks (find more information here), serving a wide range of users—especially those in regions with limited network connectivity, such as China. With this official integration, we aim to further enhance the developer experience by making tracking more seamless and user-friendly.

image

Additional information about this PR is a detailed overview of the changes and usage instructions.

swanlab-terminal swanlab-web

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests? (I don't see any tests for any of the callbacks but please let me know if I missed them somewhere. )

Who can review?

@SunMarc I have reviewed recent merges related to training tracking, and it seems that you are the most relevant reviewer for this PR. Could you please help review it or forward it to the appropriate person? Thank you!


Additional information about this PR

Key Features of SwanLab Integration

1. Online and Offline Tracking:

  • Online Mode: Track experiments remotely and store data on SwanLab's cloud platform.
  • Offline Mode: Use a local dashboard to visualize training logs without an internet connection.

2. Hardware Monitoring:

  • Automatically tracks GPU usage, power consumption, temperature, and other hardware metrics.
  • Supports NVIDIA GPUs and Huawei Ascend NPUs.

3. Remote Access:

  • View training progress remotely via the SwanLab web interface or mobile app.

4. Local Dashboard:

  • Includes an open-source local dashboard for offline visualization of training logs.

Usage guidline

Step 0: Set Up code and environment

Following the transformers official text classification example:

# prepare code and environments
git clone https://github.com/huggingface/transformers
cd transformers
pip install -e .
cd examples/pytorch/text-classification
pip install -r requirements.txt
# 

Step 1: Set Up SwanLab Online Tracking

Install:

pip install swanlab

To use SwanLab's online tracking, log in to the SwanLab website and obtain your API key from the Settings page. Then, authenticate using the following command:

swanlab login

If you prefer offline mode, skip this step.

Step 2: Configure SwanLab as the Logger and run example

To enable SwanLab as the experiment tracker, add --use_swanlab to your training command. For example, using the workflow:

python run_glue.py \
  --model_name_or_path google-bert/bert-base-cased \
  --dataset_name imdb  \
  --do_train \
  --do_predict \
  --max_seq_length 128 \
  --per_device_train_batch_size 32 \
  --learning_rate 2e-5 \
  --num_train_epochs 3 \
  --output_dir /tmp/imdb/
swanlab-terminal

visualization demo

swanlab-web

If you want to use local tracking, you simply set environment variable following:

# Linux & Mac
export SWANLAB_MODE = "local"
# Win
$env:SWANLAB_MODE = "local"

Alternatively, you can configure SwanLab using environment variables:

export SWANLAB_API_KEY=<your_api_key>          # Set API key for online tracking
export SWANLAB_LOG_DIR=<local_log_path>        # Set local log directory
export SWANLAB_MODE=<mode>                    # Set tracking mode: cloud (default), cloud-only, local, or disabled

Step 3: View Training Logs

After logging in, you will see a confirmation message:

swanlab-web swanlab-config swanlab-gpu

For more details, refer to the SwanLab Cloud Documentation.

  • Offline Tracking: Use the local dashboard to visualize logs:

here for more information.

swanlab watch
swanlab-local-terminal swanlab-local-web

For advanced configurations, such as setting a custom port, refer to the Offline Dashboard Documentation and CLI Documentation.

…in transformers

- Integrated SwanLab into the transformers library as an alternative for experiment tracking.
- Users can now log training metrics, hyperparameters, and other experiment details to SwanLab by setting `report_to="swanlab"` in the `TrainingArguments`.
- Added necessary dependencies and documentation for SwanLab integration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant