diff --git "a/docs/source/Instruction/\345\221\275\344\273\244\350\241\214\345\217\202\346\225\260.md" "b/docs/source/Instruction/\345\221\275\344\273\244\350\241\214\345\217\202\346\225\260.md" index 5e0157840e..93b2bf33c6 100644 --- "a/docs/source/Instruction/\345\221\275\344\273\244\350\241\214\345\217\202\346\225\260.md" +++ "b/docs/source/Instruction/\345\221\275\344\273\244\350\241\214\345\217\202\346\225\260.md" @@ -516,8 +516,10 @@ soft overlong 奖励参数 - swanlab_project: swanlab的project,需要在页面中预先创建好:[https://swanlab.cn/space/~](https://swanlab.cn/space/~)。 - swanlab_workspace: 默认为None,会使用api-key对应的username。 - swanlab_exp_name: 实验名,可以为空,为空时默认传入--output_dir的值。 +- swanlab_notification_methods: 推送方式。可以为空,可以为多个值,可选值为`['slack', 'lark']`。 - swanlab_lark_webhook_url: 默认为None。swanlab的lark webhook url,用于推送实验结果到飞书。 - swanlab_lark_secret: 默认为None。swanlab的lark secret,用于推送实验结果到飞书。 +- swanlab_slack_webhook_url: 默认为None。swanlab的slack webhook url,用于推送实验结果到slack。 - swanlab_mode: 可选cloud和local,云模式或者本地模式。 ### 推理参数 diff --git a/docs/source_en/Instruction/Command-line-parameters.md b/docs/source_en/Instruction/Command-line-parameters.md index 221cec01cd..f31bfaa3a4 100644 --- a/docs/source_en/Instruction/Command-line-parameters.md +++ b/docs/source_en/Instruction/Command-line-parameters.md @@ -536,8 +536,10 @@ Soft overlong reward parameters: - **swanlab_project**: SwanLab's project, which needs to be created in advance on the page: [https://swanlab.cn/space/~](https://swanlab.cn/space/~) - **swanlab_workspace**: Defaults to `None`, will use the username associated with the API key - **swanlab_exp_name**: Experiment name, can be left empty. If empty, the value of `--output_dir` will be used by default +- swanlab_notification_methods: Ways to send notifications by SwanLab, can be left empty or multiple values from `slack` or `lark`. - swanlab_lark_webhook_url: Defaults to None. SwanLab's Lark webhook URL, used for pushing experiment results to Lark. - swanlab_lark_secret: Defaults to None. SwanLab's Lark secret, used for pushing experiment results to Lark. +- swanlab_slack_webhook_url: Defaults to None. SwanLab's Slack webhook URL, used for pushing experiment results to Slack. - **swanlab_mode**: Optional values are `cloud` and `local`, representing cloud mode or local mode diff --git a/swift/llm/argument/train_args.py b/swift/llm/argument/train_args.py index 343281b184..9fd4232d29 100644 --- a/swift/llm/argument/train_args.py +++ b/swift/llm/argument/train_args.py @@ -1,7 +1,7 @@ # Copyright (c) Alibaba, Inc. and its affiliates. import os from dataclasses import dataclass, field -from typing import Literal, Optional +from typing import List, Literal, Optional from transformers import Seq2SeqTrainingArguments from transformers.utils.versions import require_version @@ -68,9 +68,15 @@ class SwanlabArguments: swanlab_project: Optional[str] = None swanlab_workspace: Optional[str] = None swanlab_exp_name: Optional[str] = None + swanlab_mode: Literal['cloud', 'local'] = 'cloud' + + swanlab_notification_methods: Optional[List[str]] = None + # lark https://docs.swanlab.cn/plugin/notification-lark.html swanlab_lark_webhook_url: Optional[str] = None swanlab_lark_secret: Optional[str] = None - swanlab_mode: Literal['cloud', 'local'] = 'cloud' + + # slack https://docs.swanlab.cn/plugin/notification-slack.html + swanlab_slack_webhook_url: Optional[str] = None def _init_swanlab(self): if not is_swanlab_available(): @@ -83,7 +89,7 @@ def _init_swanlab(self): if self.swanlab_token: swanlab.login(self.swanlab_token) - if self.swanlab_lark_webhook_url is not None: + if 'lark' in self.swanlab_notification_methods and self.swanlab_lark_webhook_url is not None: from swanlab.plugin.notification import LarkCallback lark_callback = LarkCallback( webhook_url=self.swanlab_lark_webhook_url, @@ -91,6 +97,12 @@ def _init_swanlab(self): ) swanlab.register_callbacks([lark_callback]) + if 'slack' in self.swanlab_notification_methods and self.swanlab_slack_webhook_url is not None: + from swanlab.plugin.notification import SlackCallback + + slack_callback = SlackCallback(webhook_url=self.swanlab_slack_webhook_url, language='zh') + swanlab.register_callbacks([slack_callback]) + INTEGRATION_TO_CALLBACK['swanlab'] = SwanLabCallback( project=self.swanlab_project, workspace=self.swanlab_workspace, diff --git a/swift/ui/llm_train/report_to.py b/swift/ui/llm_train/report_to.py index c64ddc2af4..560523f007 100644 --- a/swift/ui/llm_train/report_to.py +++ b/swift/ui/llm_train/report_to.py @@ -47,6 +47,12 @@ class ReportTo(BaseUI): 'en': 'Experiment of SwanLab' }, }, + 'swanlab_notification_methods': { + 'label': { + 'zh': 'SwanLab通知方式', + 'en': 'Notification methods of SwanLab' + }, + }, 'swanlab_lark_webhook_url': { 'label': { 'zh': 'SwanLab飞书Webhook地址', @@ -59,6 +65,12 @@ class ReportTo(BaseUI): 'en': 'Secret of SwanLab Lark Callback' }, }, + 'swanlab_slack_webhook_url': { + 'label': { + 'zh': 'SwanLab Slack Webhook地址', + 'en': 'Webhook URL of SwanLab Slack Callback' + }, + }, 'swanlab_mode': { 'label': { 'zh': 'SwanLab工作模式', @@ -81,9 +93,20 @@ def do_build_ui(cls, base_tab: Type['BaseUI']): scale=20) gr.Textbox(elem_id='swanlab_token', lines=1, scale=20) gr.Textbox(elem_id='swanlab_project', lines=1, scale=20) + + with gr.Row(): + gr.Dropdown( + elem_id='swanlab_notification_methods', + multiselect=True, + is_list=True, + choices=['lark', 'slack'], + allow_custom_value=True, + scale=20) with gr.Row(): gr.Textbox(elem_id='swanlab_lark_webhook_url', lines=1, scale=20) gr.Textbox(elem_id='swanlab_lark_secret', lines=1, scale=20) + with gr.Row(): + gr.Textbox(elem_id='swanlab_slack_webhook_url', lines=1, scale=20) with gr.Row(): gr.Textbox(elem_id='swanlab_workspace', lines=1, scale=20) gr.Textbox(elem_id='swanlab_exp_name', lines=1, scale=20)