Lark Notification
If you wish to receive immediate Lark notifications upon training completion or errors, the Lark 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
Reference Documentation
- In a Lark group, click the "···" - "Settings" in the top-right corner.

- Click "Group Bots".

- Click "Add Bot".

- Add a "Custom Bot".


- Copy the "Webhook URL" and "Signature".

At this point, your preparation is complete.
Basic Usage
Using the Lark notification plugin is straightforward. Simply initialize a LarkCallback
object:
from swanlab.plugin.notification import LarkCallback
lark_callback = LarkCallback(
webhook_url="https://open.larkoffice.com/open-apis/bot/v2/hook/xxxx",
secrets="xxxx",
)
Then pass the lark_callback
object into the callbacks
parameter of swanlab.init
:
swanlab.init(callbacks=[lark_callback])
This way, when training completes or an error occurs (triggering swanlab.finish()
), you will receive a Lark notification.

Custom Notifications
You can also use the send_msg
method of the LarkCallback
object to send custom Lark messages.
This is particularly useful for notifying you when certain metrics reach specific thresholds!
if accuracy > 0.95:
# Send a custom notification
lark_callback.send_msg(
content=f"Current Accuracy: {accuracy}", # Notification content
)
Limitations
• The training completion/error notification of the Lark 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 Lark notification will be sent.
• A more robust solution will be available with the launch of SwanLab
's Platform Open API
. Stay tuned!