Skip to content

Conversation

Copy link

Copilot AI commented Jul 22, 2025

🎯 Overview

This PR migrates the entire KnowRL codebase from WandB to SwanLab for experiment tracking, as requested in the issue. The migration maintains full backward compatibility to ensure existing user setups continue working without interruption.

🚀 What Changed

Core Migration

  • Initialization: initialize_wandb_from_yaml()initialize_swanlab_from_yaml()
  • Logging: All wandb.log() calls → swanlab.log()
  • URLs: wandb.run.get_url()swanlab.run.url
  • Imports: Added is_swanlab_available() utility function
  • Configuration: Updated default configs to use SwanLab parameters

Files Modified

  • Core files: utils.py, main.py, configuration files
  • 19 trainer files: All trainers in train/trl/trainer/ updated
  • Configuration: grpo.yaml, environment variable examples
  • Documentation: README.md updated with SwanLab instructions
  • Scripts: Example scripts now use SwanLab

🔄 Backward Compatibility

The migration is designed to be zero-breaking-change:

Configuration Parameters

# NEW format (recommended)
report_to: swanlab
swanlab_project: "my_project"
swanlab_entity: "my_team"

# OLD format (still works!)
report_to: wandb
wandb_project: "my_project" 
wandb_entity: "my_team"

Environment Variables

# NEW (recommended)
export SWANLAB_API_KEY="your_key"
export SWANLAB_MODE="offline"

# OLD (still supported)
export WANDB_API_KEY="your_key"
export WANDB_MODE="offline"

Trainer Compatibility

  • Accepts both "swanlab" and "wandb" in report_to parameter
  • Automatic parameter fallback: swanlab_projectwandb_project
  • All existing training scripts work without modification

📋 Migration Benefits

  1. Better Performance: SwanLab offers faster logging and visualization
  2. Enhanced UI: More visualization types and improved interface
  3. Easy Transition: Drop-in replacement with similar API
  4. Gradual Migration: Users can migrate at their own pace

🧪 Testing

  • ✅ All Python files pass syntax checks
  • ✅ Configuration files are valid YAML
  • ✅ Both old and new config formats work
  • ✅ Backward compatibility verified
  • ✅ Import statements and function calls validated

📚 Documentation

Added comprehensive migration guide (MIGRATION_GUIDE.md) covering:

  • Quick start for new users
  • Gradual migration path for existing users
  • Configuration parameter mapping
  • Troubleshooting common issues

🎉 Migration Example

Before:

import wandb
wandb.init(project="my_project")
wandb.log({"loss": 0.5})

After:

import swanlab
swanlab.init(project="my_project") 
swanlab.log({"loss": 0.5})

Existing configs continue to work while users transition!


This migration ensures KnowRL users get the benefits of SwanLab's enhanced experiment tracking while maintaining complete compatibility with existing WandB-based setups. Users can migrate gradually without any disruption to their workflows.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@BaochangRen BaochangRen deleted the copilot/fix-a5566916-7081-416e-bf2c-5f23194aaeea branch July 22, 2025 15:59
Copilot AI restored the copilot/fix-a5566916-7081-416e-bf2c-5f23194aaeea branch July 22, 2025 16:00
@BaochangRen BaochangRen deleted the copilot/fix-a5566916-7081-416e-bf2c-5f23194aaeea branch July 22, 2025 16:01
Copilot AI changed the title [WIP] 请你将这个代码的wandb都换成swanlab Replace wandb with swanlab for experiment tracking with backward compatibility Jul 22, 2025
Copilot AI requested a review from BaochangRen July 22, 2025 16:25
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.

2 participants