Skip to content

Commit a2a954d

Browse files
Merge pull request #117 from InvolutionHell/Mira190-patch-3
Create swanlab.mdx
2 parents ac68308 + 3dc0c5a commit a2a954d

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: 'swanlab快速上手指南'
3+
description: ""
4+
date: "2025-09-23"
5+
tags:
6+
- tag-one
7+
---
8+
9+
最近在做实验,发现实验次数多了之后特别容易乱,而且实验结果也很难记录,甚至我都准备用最麻烦的excel来记录。
10+
突然想起了9444的大佬组员纳神之前有讲过,可以用swanlab进行实验结果的记录和可视化,于是马上整理了一份swanlab操作指南,也算是我后面实验pipeline的一环了。
11+
其他科研大佬有更好的实验记录方法也欢迎分享。
12+
那么话不多说,今天先看swanlab。下面是使用 SwanLab 做实验追踪的快速上手流程。
13+
14+
## 1. 注册账号 & 获取 API Key
15+
16+
首先打开 SwanLab 官网:[https://swanlab.cn/](https://swanlab.cn/)
17+
如果还没有账号,需要先在官网注册。
18+
19+
完成注册并登录后,新建项目,然后就能看到快速开始,照着指南一步一步走就可以,你的api key都会在里面!为了方便我把指南的内容都搬到这了
20+
21+
## 2. 安装 SwanLab 库
22+
23+
在有 Python3 的环境中,通过 pip 安装 SwanLab 客户端库:
24+
25+
```bash
26+
pip install swanlab
27+
````
28+
29+
## 3. 登录 SwanLab
30+
31+
在命令行执行以下命令进行登录:
32+
33+
```bash
34+
swanlab login
35+
```
36+
37+
系统会提示:
38+
39+
```
40+
swanlab: Logging into swanlab cloud.
41+
swanlab: You can find your API key at: https://swanlab.cn/settings
42+
swanlab: Paste an API key from your profile and hit enter, or press 'CTRL-C' to quit:
43+
```
44+
45+
将你从官网用户设置页面复制的 API Key 粘贴进去即可完成登录。([docs.swanlab.cn](https://docs.swanlab.cn/en/guide_cloud/general/quick-start.html))
46+
47+
48+
## 4. 提交实验
49+
50+
```python
51+
import swanlab
52+
import random
53+
54+
# 初始化一个新的swanlab run类来跟踪这个脚本
55+
swanlab.init(
56+
# 设置将记录此次运行的项目信息
57+
project="mteb-ailastatue",
58+
workspace="mira",
59+
# 跟踪超参数和运行元数据
60+
config={
61+
"learning_rate": 0.02,
62+
"architecture": "CNN",
63+
"dataset": "CIFAR-100",
64+
"epochs": 10
65+
}
66+
)
67+
68+
# 模拟训练
69+
epochs = 10
70+
offset = random.random() / 5
71+
for epoch in range(2, epochs):
72+
acc = 1 - 2 ** -epoch - random.random() / epoch - offset
73+
loss = 2 ** -epoch + random.random() / epoch + offset
74+
75+
# 向swanlab上传训练指标
76+
swanlab.log({"acc": acc, "loss": loss})
77+
78+
# [可选] 完成训练,这在notebook环境中是必要的
79+
swanlab.finish()
80+
81+
82+
```
83+
84+
---
85+
86+
## 5. 查看结果!
87+
运行了代码之后,可以导航到新创建的项目,比较不同的实验和它们的指标。
88+
89+
90+
## 参考文献
91+
官方文档:[Quick Start 指南](https://docs.swanlab.cn/en/guide_cloud/general/quick-start.html)
92+

0 commit comments

Comments
 (0)