Skip to content

Commit 77ad540

Browse files
authored
[Feature] SwanLab Lark callback (#4830)
1 parent 43dab1a commit 77ad540

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

docs/source/Instruction/命令行参数.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ soft overlong 奖励参数
515515
- swanlab_project: swanlab的project,需要在页面中预先创建好:[https://swanlab.cn/space/~](https://swanlab.cn/space/~)
516516
- swanlab_workspace: 默认为None,会使用api-key对应的username。
517517
- swanlab_exp_name: 实验名,可以为空,为空时默认传入--output_dir的值。
518+
- swanlab_lark_webhook_url: 默认为None。swanlab的lark webhook url,用于推送实验结果到飞书。
519+
- swanlab_lark_secret: 默认为None。swanlab的lark secret,用于推送实验结果到飞书。
518520
- swanlab_mode: 可选cloud和local,云模式或者本地模式。
519521

520522
### 推理参数

docs/source_en/Instruction/Command-line-parameters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ Soft overlong reward parameters:
535535
- **swanlab_project**: SwanLab's project, which needs to be created in advance on the page: [https://swanlab.cn/space/~](https://swanlab.cn/space/~)
536536
- **swanlab_workspace**: Defaults to `None`, will use the username associated with the API key
537537
- **swanlab_exp_name**: Experiment name, can be left empty. If empty, the value of `--output_dir` will be used by default
538+
- swanlab_lark_webhook_url: Defaults to None. SwanLab's Lark webhook URL, used for pushing experiment results to Lark.
539+
- swanlab_lark_secret: Defaults to None. SwanLab's Lark secret, used for pushing experiment results to Lark.
538540
- **swanlab_mode**: Optional values are `cloud` and `local`, representing cloud mode or local mode
539541

540542

swift/llm/argument/train_args.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class SwanlabArguments:
6868
swanlab_project: Optional[str] = None
6969
swanlab_workspace: Optional[str] = None
7070
swanlab_exp_name: Optional[str] = None
71+
swanlab_lark_webhook_url: Optional[str] = None
72+
swanlab_lark_secret: Optional[str] = None
7173
swanlab_mode: Literal['cloud', 'local'] = 'cloud'
7274

7375
def _init_swanlab(self):
@@ -80,6 +82,15 @@ def _init_swanlab(self):
8082
from swanlab.integration.transformers import SwanLabCallback
8183
if self.swanlab_token:
8284
swanlab.login(self.swanlab_token)
85+
86+
if self.swanlab_lark_webhook_url is not None:
87+
from swanlab.plugin.notification import LarkCallback
88+
lark_callback = LarkCallback(
89+
webhook_url=self.swanlab_lark_webhook_url,
90+
secret=self.swanlab_lark_secret,
91+
)
92+
swanlab.register_callbacks([lark_callback])
93+
8394
INTEGRATION_TO_CALLBACK['swanlab'] = SwanLabCallback(
8495
project=self.swanlab_project,
8596
workspace=self.swanlab_workspace,

swift/ui/llm_train/report_to.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ class ReportTo(BaseUI):
4747
'en': 'Experiment of SwanLab'
4848
},
4949
},
50+
'swanlab_lark_webhook_url': {
51+
'label': {
52+
'zh': 'SwanLab飞书Webhook地址',
53+
'en': 'Webhook URL of SwanLab Lark Callback'
54+
},
55+
},
56+
'swanlab_lark_secret': {
57+
'label': {
58+
'zh': 'SwanLab飞书Secret',
59+
'en': 'Secret of SwanLab Lark Callback'
60+
},
61+
},
5062
'swanlab_mode': {
5163
'label': {
5264
'zh': 'SwanLab工作模式',
@@ -69,6 +81,9 @@ def do_build_ui(cls, base_tab: Type['BaseUI']):
6981
scale=20)
7082
gr.Textbox(elem_id='swanlab_token', lines=1, scale=20)
7183
gr.Textbox(elem_id='swanlab_project', lines=1, scale=20)
84+
with gr.Row():
85+
gr.Textbox(elem_id='swanlab_lark_webhook_url', lines=1, scale=20)
86+
gr.Textbox(elem_id='swanlab_lark_secret', lines=1, scale=20)
7287
with gr.Row():
7388
gr.Textbox(elem_id='swanlab_workspace', lines=1, scale=20)
7489
gr.Textbox(elem_id='swanlab_exp_name', lines=1, scale=20)

0 commit comments

Comments
 (0)