Slack
If you wish to receive immediate Slack notifications upon training completion or errors, the Slack Notification plugin is highly recommended.
Improve the Plugin
SwanLab plugins are open-source. You can view the Github source code. Suggestions and PRs are welcome!
Preparation
References
- Turn into the page of Slack-API,click 「Create an App」

- Click 「From scratch」 in the pop up window

- Input 「App Name」 ,and select the workspace you want to send notification,then click 「Create App」

- Once into the App configuration menu,click 「Incoming Webhooks」,and turn on the button 「Activate Incoming Webhooks」 ;

- At the bottom of the page,click 「Add New Webhook to Workspace」 to add the APP into your workspace;

- In the redirect page,select a channel the app needs to send notification,click 「Accept」

7.Back to the APP configuration page,copy the Webhook URL of your app

Basic Usage
Using the Discord notification plugin is straightforward. Simply initialize a SlackCallback
object:
from swanlab.plugin.notification import SlackCallback
slack_callback = SlackCallback(
webhook_url='https://hooks.slack.com/services/xxxx/xxxx/xxxx',
language='en'
)
Then pass the slack_callback
object into the callbacks
list parameter of swanlab.init
:
swanlab.init(callbacks=[slack_callback])
This way, when training completes or an error occurs (triggering swanlab.finish()
), you will receive a Slack notification.

Custom Notifications
You can also use the send_msg
method of the SlackCallback
object to send custom Slack messages.
This is particularly useful for notifying you when certain metrics reach specific thresholds!
if accuracy > 0.95:
# custom messages
slack_callback.send_msg(
content=f"Current Accuracy: {accuracy}",
)
Limitations
• The training completion/error notification of the Slack notification plugin relies on the on_stop
lifecycle callback of SwanKitCallback
. Therefore, if your process is abruptly killed
or the training machine shuts down unexpectedly, the on_stop
callback will not be triggered, and no Slack notification will be sent.
• A more robust solution will be available with the launch of SwanLab
's Platform Open API
. Stay tuned!