Skip to content

Commit d90718d

Browse files
SAKURA-CATFeudalmanZeyi-Lin
authored
feat/v0.1.5 (#253)
- [x] Users can turn on the service even if runs.swanlab does not exist. - [x] version update, and limit - [x] UI adjust - [x] Close #205 - [x] Close #81 - [x] ... --------- Co-authored-by: Zirui Cai <[email protected]> Co-authored-by: Ze-Yi LIN <[email protected]> Co-authored-by: ZeYi Lin <[email protected]>
1 parent 25d8cd1 commit d90718d

File tree

24 files changed

+257
-155
lines changed

24 files changed

+257
-155
lines changed

README.md

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ English | <a href="README_zh-hans.md">中文</a>
2828

2929
- [Key Function](#key-function)
3030
- [Changelog](#changelog)
31-
- [Use Case](#use-case)
31+
- [Installation](#installation)
3232
- [Getting Started](#getting-started)
33+
- [Use Case](#use-case)
3334
- [More Tips](#more-tips)
3435
- [LICENSE](#license)
3536

@@ -63,26 +64,33 @@ English | <a href="README_zh-hans.md">中文</a>
6364

6465
## Changelog
6566

67+
[24/01/23] 🚨 We use SQLite database and Peewee to replace the previous basic configuration information reading and writing solution by [#114](https://github.com/SwanHubX/SwanLab/issues/114). It's a major change that is highly beneficial for the future of the project, but the drawback is that it's not compatible with old versions (swanlab<=v0.1.4) of log data files. Therefore, if you need to visualize log files generated by older versions, please install version `<=0.1.4`.
68+
69+
Additionally, we supported export the experiment list as `CSV`, new environment record items `Run path` and `logdir`, added interactive quick copy function, and new API `swanlab.config`.
70+
6671
[24/01/14] 🔥 We supported a new UI, tracking additional environment information, including command, git commit/branch and memory. Additionally, we've added a `logdir` API, allowing developers to set the directory for log files.
6772

6873
[24/01/07] ✨ We supported delete experiment and edit experiment inforamation on Dashboard.
6974

70-
[24/01/01] We fixed some bugs to make SwanLab more stable.
71-
7275
[Full Changelog](https://github.com/SwanHubX/SwanLab/releases)
7376

7477
<br>
7578

76-
## Use Case
79+
## Installation
7780

78-
Learn how to use SwanLab more effectively by following these use cases:
81+
### with pip
7982

80-
| Code Cases | Description |
81-
| ------- | ------- |
82-
| [Hello World](https://github.com/SwanHubX/SwanLab-examples/tree/main/Hello_World) | Getting Started |
83-
| [MNIST](https://github.com/SwanHubX/SwanLab-examples/tree/main/MNIST) | Handwriting recognition based on a plain net and MNIST dataset with pytroch, swanlab. |
84-
| [Image Classification](https://github.com/SwanHubX/SwanLab-examples/blob/main/Resnet50) | Cat and dog classification based on ResNet50 with pytorch, swanlab and gradio. [Tutorial](https://zhuanlan.zhihu.com/p/676430630). |
85-
| [Text Generation](https://github.com/SwanHubX/SwanLab-examples/blob/main/Word_language_model) | Text generation based on Word_language_model (RNN/LSTM/GRU/Transformer) |
83+
Requirement:Python 3.8+.
84+
85+
Use [pip](https://pip.pypa.io/en/stable/) to install our stable release version. The installation command is as follows:
86+
87+
```bash
88+
pip install -U swanlab
89+
```
90+
91+
### with source code
92+
93+
If you need the bleeding edge of the code and can't wait for a new release, you must [install the library from source](https://geektechstudio.feishu.cn/wiki/DvxSweHUKiAe8yksci3cMflbnwh#SMXHdJ1c1o4jzTxcDticHcwvnHd)
8694

8795
<br>
8896

@@ -95,7 +103,7 @@ pip install -U swanlab
95103
```
96104

97105
2. Second, Use the example code snippet below as a template to integrate SwanLab to your Python script:
98-
```Python
106+
```python
99107
import swanlab
100108

101109
# Start a SwanLab Run with swanlab.init
@@ -120,9 +128,28 @@ That's it! Open http://127.0.0.1:5092 to view a dashboard of your first SwanLab
120128

121129
<br>
122130

131+
## Use Case
132+
133+
Learn how to use SwanLab more effectively by following these use cases:
134+
135+
| Code Cases | Description |
136+
| ------- | ------- |
137+
| [Hello World](https://github.com/SwanHubX/SwanLab-examples/tree/main/Hello_World) | Getting Started |
138+
| [MNIST](https://github.com/SwanHubX/SwanLab-examples/tree/main/MNIST) | Handwriting recognition based on a plain net and MNIST dataset with pytroch, swanlab. |
139+
| [Image Classification](https://github.com/SwanHubX/SwanLab-examples/blob/main/Resnet50) | Cat and dog classification based on ResNet50 with pytorch, swanlab and gradio. [Tutorial](https://zhuanlan.zhihu.com/p/676430630). |
140+
| [Text Generation](https://github.com/SwanHubX/SwanLab-examples/blob/main/Word_language_model) | Text generation based on Word_language_model (RNN/LSTM/GRU/Transformer) |
141+
142+
<br>
143+
123144
## More Tips
124145

125-
- Set a log directory save path and run the Dashboard using it:
146+
🏄‍♀️ Experiment Dashboard:
147+
148+
<details>
149+
<summary>Set a log directory save path and run the Dashboard using it</summary>
150+
151+
Set a log directory save path, such as `./logs`:
152+
126153
```python
127154
import swanlab
128155

@@ -131,15 +158,37 @@ swanlab.init(
131158
)
132159
```
133160

161+
Run the Dashboard using it:
162+
134163
```bash
135164
$ swanlab watch --logdir ./logs_path
136165
```
137166

138-
- Set the Host and Port for the Dashboard:
167+
</details>
168+
169+
<details>
170+
<summary>Set the Host and Port for the Dashboard</summary>
171+
139172
```bash
140173
$ swanlab watch --host 0.0.0.0 --port 8080
141174
```
142-
- Use Argparse init swanlab.config:
175+
176+
</details>
177+
178+
<details>
179+
<summary>Remotely access Dashboard</summary>
180+
181+
- Link:[Access the SwanLab Dashboard While Training on a Remote Server](https://zhuanlan.zhihu.com/p/677224865)
182+
183+
</details>
184+
185+
⚙️ Other:
186+
187+
<details>
188+
<summary>argparse init swanlab.config</summary>
189+
190+
`swanlab.config` supports directly passing variables of type `argparse.Namespace`, such as:
191+
143192
```python
144193
import argparse
145194
import swanlab
@@ -150,11 +199,12 @@ args = parser.parse_args()
150199

151200

152201
swanlab.init(
153-
config=vars(args)
202+
config=args
154203
)
155204
```
156205

157-
- [Remotely access Dashboard](https://zhuanlan.zhihu.com/p/677224865): Access the SwanLab Dashboard While Training on a Remote Server.
206+
</details>
207+
158208

159209
<br>
160210

README_zh-hans.md

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828

2929
- [核心功能](#核心功能)
3030
- [更新日志](#更新日志)
31-
- [案例](#案例)
31+
- [安装](#安装)
3232
- [快速开始](#快速开始)
33+
- [案例](#案例)
3334
- [更多技巧](#更多技巧)
3435
- [协议](#协议)
3536

@@ -57,32 +58,37 @@
5758
- **🥔 离线支持**: SwanLab可以完全离线运行,无需任何对互联网的访问。例如,它可以在您的本地计算机上、企业防火墙后面或数据中心中运行。
5859

5960
> [!NOTE]
60-
> See the SwanLab <a href="https://geektechstudio.feishu.cn/wiki/MwXmw9yDeiZWyQkPnNgcixwWnwu">Documentaion</a> and <a href="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/SwanHubX/SwanLab-examples">Examples</a> for a full description of the SwanLab.
61+
> 请查看SwanLab的<a href="https://geektechstudio.feishu.cn/wiki/MwXmw9yDeiZWyQkPnNgcixwWnwu">文档</a><a href="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/SwanHubX/SwanLab-examples">示例</a>,以获取有关SwanLab的完整介绍。
6162
6263
<br>
6364

6465
## 更新日志
6566

67+
[24/01/23] 🚨 我们使用SQLite数据库和Peewee库替代了之前的基础配置信息读写方案([#114](https://github.com/SwanHubX/SwanLab/issues/114)),这是个极大有利于项目未来的改动,但缺陷是不兼容旧版本(swanlab<=v0.1.4)的日志数据文件,所以如需可视化旧版本产生的日志文件请安装<=0.1.4的版本。与此同时,我们增加了支持导出实验列表为CSV,新的环境记录项`Run path``logdir`,增加了快捷复制的交互,以及新的API `swanlab.config`
68+
6669
[24/01/14] 🔥 我们发布了一个新的UI界面,以及跟踪更多环境信息,包括Command、git提交/分支、和机器内存。此外,我们还添加了一个`logdir` API,允许开发人员设置日志文件的目录。
6770

6871
[24/01/07] ✨ 我们支持在仪表板上删除实验和编辑实验信息。
6972

70-
[24/01/01] 我们修复了一些错误,使SwanLab更加稳定。
71-
7273
[完整更新日志](https://github.com/SwanHubX/SwanLab/releases)
7374

7475
<br>
7576

76-
## 案例
77+
## 安装
7778

78-
通过以下用例学习如何更有效地使用SwanLab:
79+
### pip安装
7980

80-
| 案例 | 介绍 |
81-
| ------- | ------- |
82-
| [Hello World](https://github.com/SwanHubX/SwanLab-examples/tree/main/Hello_World) | 简单入门 |
83-
| [MNIST](https://github.com/SwanHubX/SwanLab-examples/tree/main/MNIST) | 基于神经网络的MNIST手写体识别(使用pytorch、swanlab库) |
84-
| [图像分类](https://github.com/SwanHubX/SwanLab-examples/blob/main/Resnet50) | ResNet50猫狗分类(使用pytorch、swanlab、Gradio库) [图文教程](https://zhuanlan.zhihu.com/p/676430630) |
85-
| [文本生成](https://github.com/SwanHubX/SwanLab-examples/blob/main/Word_language_model) | 基于自然语言模型的文本生成 (RNN/LSTM/GRU/Transformer) |
81+
环境要求:Python 3.8+
82+
83+
使用[pip](https://pip.pypa.io/en/stable/)将安装我们稳定发布的版本,安装命令如下所示:
84+
85+
```bash
86+
pip install -U swanlab
87+
```
88+
89+
### 源码安装
90+
91+
如果您等不及发布,想体验最新的代码与特性,那么必须[从源代码安装此库](https://geektechstudio.feishu.cn/wiki/DvxSweHUKiAe8yksci3cMflbnwh#SMXHdJ1c1o4jzTxcDticHcwvnHd)
8692

8793
<br>
8894

@@ -95,7 +101,7 @@ pip install -U swanlab
95101
```
96102

97103
2. 然后,使用下面的示例代码片段作为模板,将SwanLab集成到您的Python脚本中:
98-
```Python
104+
```python
99105
import swanlab
100106

101107
# Start a SwanLab Run with swanlab.init
@@ -120,9 +126,28 @@ $ swanlab watch
120126

121127
<br>
122128

129+
## 案例
130+
131+
通过以下用例学习如何更有效地使用SwanLab:
132+
133+
| 案例 | 介绍 |
134+
| ------- | ------- |
135+
| [Hello World](https://github.com/SwanHubX/SwanLab-examples/tree/main/Hello_World) | 简单入门 |
136+
| [MNIST](https://github.com/SwanHubX/SwanLab-examples/tree/main/MNIST) | 基于神经网络的MNIST手写体识别(使用pytorch、swanlab库) |
137+
| [图像分类](https://github.com/SwanHubX/SwanLab-examples/blob/main/Resnet50) | ResNet50猫狗分类(使用pytorch、swanlab、Gradio库) [图文教程](https://zhuanlan.zhihu.com/p/676430630) |
138+
| [文本生成](https://github.com/SwanHubX/SwanLab-examples/blob/main/Word_language_model) | 基于自然语言模型的文本生成 (RNN/LSTM/GRU/Transformer) |
139+
140+
<br>
141+
123142
## 更多技巧
124143

125-
- 设置1个日志文件保存路径,以及运行基于它的实验看板:
144+
🏄‍♀️ 实验看板相关:
145+
146+
<details>
147+
<summary>设置日志文件保存路径,并运行基于它的实验看板</summary>
148+
149+
设置日志文件保存路径,比如`./logs`:
150+
126151
```python
127152
import swanlab
128153

@@ -131,16 +156,35 @@ swanlab.init(
131156
)
132157
```
133158

159+
运行基于`./logs`的看实验看板:
160+
134161
```bash
135-
$ swanlab watch --logdir ./logs_path
162+
$ swanlab watch --logdir ./logs
136163
```
164+
</details>
165+
166+
167+
<details>
168+
<summary>设置实验看板的主机和端口</summary>
137169

138-
- 设置实验看板的主机和端口:
139170
```bash
140171
$ swanlab watch --host 0.0.0.0 --port 8080
141172
```
173+
</details>
174+
175+
<details>
176+
<summary>远程访问实验看板</summary>
142177

143-
- 使用Argparse初始化swanlab.config:
178+
- 链接:[在远程服务器上进行训练时,访问SwanLab实验看板](https://zhuanlan.zhihu.com/p/677224865)
179+
180+
</details>
181+
182+
⚙️ 其他:
183+
184+
<details>
185+
<summary>argparse与swanlab.config</summary>
186+
187+
swanlab.config支持直接传入argparse.Namespace类型的变量,如:
144188
```python
145189
import argparse
146190
import swanlab
@@ -151,11 +195,10 @@ args = parser.parse_args()
151195

152196

153197
swanlab.init(
154-
config=vars(args)
198+
config=args
155199
)
156200
```
157-
158-
- [远程访问实验看板](https://zhuanlan.zhihu.com/p/677224865): 在远程服务器上进行训练时,访问SwanLab实验看板。
201+
</details>
159202

160203
<br>
161204

swanlab/cli/main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import click
1212
from .utils import is_valid_ip, is_valid_port, is_valid_root_dir, URL
13-
from ..utils import FONT
13+
from ..utils import FONT, version_limit
1414
from ..env import get_server_host, get_server_port, get_swanlog_dir
1515
import time
1616
from ..db import connect
@@ -66,12 +66,16 @@ def watch(log_level: str, **kwargs):
6666
from ..server import app
6767
import uvicorn
6868

69-
# 在此处已经完成了路径的检查,所以可以直接导入
70-
connect()
69+
log_dir = get_swanlog_dir()
70+
print(log_dir)
71+
version_limit(log_dir, mode="watch")
7172

7273
# debug一下当前日志文件夹的位置
73-
swl.debug("Try to explore the swanlab experiment logs in: " + FONT.bold(get_swanlog_dir()))
74-
74+
swl.debug("Try to explore the swanlab experiment logs in: " + FONT.bold(log_dir))
75+
try:
76+
connect()
77+
except FileNotFoundError:
78+
swl.error("Can not find the swanlab db in: " + FONT.bold(log_dir))
7579
# ---------------------------------- 日志等级处理 ----------------------------------
7680
swl.setLevel(log_level)
7781
# ---------------------------------- 服务地址处理 ----------------------------------

swanlab/cli/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import click
1414
from ..utils import FONT, file
1515
from ..env import PORT, HOST, ROOT
16+
import json
1617

1718

1819
def is_valid_ip(ctx, param, ip: str) -> tuple:

swanlab/data/run/exp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def add(self, key: str, data: DataType, step: int = None):
8383
"""
8484
由于添加图表的同时会尝试转换data的类型,但这在注入step之前
8585
所以此处需要手动注入依赖
86-
关于step,如果step格式不正确,会在tag_obj.add的时候被拦截,此处如果格式不正确直接设置为1即可
86+
关于step,如果step格式不正确,会在tag_obj.add的时候被拦截,此处如果格式不正确直接设置为0即可
8787
"""
8888
if isinstance(data, BaseType):
89-
data.step = 1 if step is None or not isinstance(step, int) else step
89+
data.step = 0 if step is None or not isinstance(step, int) else step
9090
data.tag = tag_obj.tag
9191
tag_obj.create_chart(tag, data)
9292
# 检查tag创建时图表是否创建成功,如果失败则也没有写入数据的必要了,直接退出
@@ -154,9 +154,9 @@ def add(self, data: DataType, step: int = None):
154154
if step is not None and not isinstance(step, int):
155155
swanlog.warning(f"Step {step} is not int, SwanLab will set it automatically.")
156156
step = None
157-
# 转换step,如果step为None,则改为合适的长度,目前step从1开始
157+
# 转换step,如果step为None,则改为合适的长度,目前step从0开始
158158
if step is None:
159-
step = len(self.__steps) + 1
159+
step = len(self.__steps)
160160
# 如果step已经存在,打印警告并退出
161161
if step in self.__steps:
162162
return swanlog.warning(f"Step {step} on tag {self.tag} already exists, ignored.")

swanlab/data/sdk.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ..env import init_env, ROOT
1818
from .utils.file import check_dir_and_create, formate_abs_path
1919
from ..db import Project, connect
20+
from ..utils import version_limit
2021

2122

2223
run: Optional["SwanLabRun"] = None
@@ -82,7 +83,7 @@ def init(
8283
except IOError:
8384
raise IOError("logdir must be a path and have Write permission.")
8485
os.environ[ROOT] = logdir
85-
# 如果没有传入logdir,则使用默认的logdir,即当前工作目录,但是需要保证目录存在
86+
# 如果没有传入logdir,则使用默认的logdir, 即当前工作目录,但是需要保证目录存在
8687
else:
8788
logdir = os.path.abspath("swanlog")
8889
try:
@@ -91,7 +92,8 @@ def init(
9192
raise IOError
9293
except:
9394
raise IOError("logdir must have Write permission.")
94-
95+
# 检查logdir内文件的版本,如果<=0.1.4则报错
96+
version_limit(logdir, mode="init")
9597
# 初始化环境变量
9698
init_env()
9799
# 连接数据库,要求路径必须存在,但是如果数据库文件不存在,会自动创建

swanlab/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swanlab",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "",
55
"python": "true"
66
}

0 commit comments

Comments
 (0)