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

fix: wandb conver #853

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions swanlab/converter/wb/wb_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def parse_wandb_logs(self, wb_project: str, wb_entity: str, wb_run_id: str = Non
raise TypeError(
"Wandb Converter requires wandb. Install with 'pip install wandb'."
)

try:
import pandas as pd
except ImportError as e:
raise TypeError(
"Wandb Converter requires pandas when process wandb logs. Install with 'pip install pandas'."
)

client = wandb.Api()

Expand All @@ -51,11 +58,16 @@ def parse_wandb_logs(self, wb_project: str, wb_entity: str, wb_run_id: str = Non
workspace=self.workspace,
experiment_name=wb_run.name,
description=wb_run.notes,
mode="cloud" if self.cloud else "local",
cloud=self.cloud,
logdir=self.logdir,
)
else:
swanlab_run = swanlab.get_run()

try:
wb_run_metadata = {"wandb_metadata": wb_run_metadata}
except:
wb_run_metadata = None

wb_config = {
"wandb_run_id": wb_run.id,
Expand All @@ -64,16 +76,22 @@ def parse_wandb_logs(self, wb_project: str, wb_entity: str, wb_run_id: str = Non
"wandb_user": wb_run.user,
"wandb_tags": wb_run.tags,
"wandb_url": wb_run.url,
"wandb_metadata": wb_run.metadata,
}
wb_config.update(wb_run_metadata)

swanlab_run.config.update(wb_config)
swanlab_run.config.update(wb_run.config)

# Get the first history record to extract available keys
history = wb_run.history(stream="default")
if len(history) > 0:
keys = [key for key in history[0].keys() if not key.startswith("_")]
# 检查 history 是否为 DataFrame 类型
if isinstance(history, pd.DataFrame):
# 如果是 DataFrame,直接获取列名
keys = [key for key in history.columns if not key.startswith("_")]
else:
# 原来的逻辑,假设是字典列表
keys = [key for key in history[0].keys() if not key.startswith("_")]
else:
keys = []

Expand Down
Loading