Skip to content

WXWork Notification

If you wish to receive immediate WXWork notifications upon training completion or errors, the WXWork 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

  1. In a WXWork group,click the 「···」-「Add Group Robot」
  1. Click 「Add Bot」 in the poped up card
  1. Continue to click 「New Robot」
  1. Click 「Add Robot」 after naming your robot
  1. Just need to copy the 「Webhook Url」 of your WXWork robot

Basic Usage

Using the WXWork notification plugin is straightforward. Simply initialize a WXWorkCallback object:

python
from swanlab.plugin.notification import WXWorkCallback

wxwork_callback = WXWorkCallback(
    webhook_url="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxx",
)

Then pass the wxwork_callback object into the callbacks list parameter of swanlab.init:

python
swanlab.init(callbacks=[wxwork_callback])

This way, when training completes or an error occurs (triggering swanlab.finish()), you will receive a WXWork notification.

Custom Notifications

You can also use the send_msg method of the WXWorkCallback object to send custom WXWork messages.

This is particularly useful for notifying you when certain metrics reach specific thresholds!

python
if accuracy > 0.95:
    # custom messages
    wxwork_callback.send_msg(
        content=f"Current Accuracy: {accuracy}",  
    )

Register plugins externally

If you are using the integration of SwanLab with other frameworks and thus find it difficult to locate swanlab.init, you can use the swanlab.register_callbacks method to pass in plugins externally:

python
import swanlab

# Equivalent to swanlab.init(callbacks=[...])
swanlab.register_callbacks([...])

Limitations

• The training completion/error notification of the WXWork 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 WXWork notification will be sent.

• A more robust solution will be available with the launch of SwanLab's Platform Open API. Stay tuned!