Weights & Biases 实验跟踪
W&B 用于记录训练指标、超参数、系统资源、模型和数据集版本,支持 Sweeps 超参搜索和多人协作。适合需要可视化对比大量实验的团队。
登录:
wandb login
# 或使用环境变量
export WANDB_API_KEY=***
初始化并记录:
import wandb
wandb.init(project="qwen-lora", config={"lr": 1e-4, "batch_size": 8})
wandb.log({"loss": 1.23, "accuracy": 0.91}, step=1)
wandb.finish()
记录模型 artifact:
artifact = wandb.Artifact("qwen-lora", type="model")
artifact.add_file("adapter_model.safetensors")
wandb.log_artifact(artifact)
超参搜索:
wandb sweep sweep.yaml
wandb agent <SWEEP_ID>
离线模式:
export WANDB_MODE=offline
wandb sync wandb/offline-run-*
wandb.init,run 混乱;每个 rank 只让主进程记录。wandb.finish(),run 长期处于 running。wandb sync,数据没有上传。