pytorch_pfn_extras.training.extensions.Slack#
- class pytorch_pfn_extras.training.extensions.Slack(channel, msg=None, *, start_msg='{default}', end_msg='{default}', error_msg='{default}', thread=True, filenames=None, upload_trigger=None, context=None, token=None)#
Bases:
_SlackBase
An extension to communicate with Slack.
Example
>>> ppe.training.extensions.Slack( ... channel="experiment-progress", ... msg="Epoch #{manager.epoch}: loss = {val/loss}", ... end_msg="{default} \n <@username> Check out the result!", ... ... # Upload files at the end of the experiment. ... filenames=["result/statistics.png"], ... upload_trigger=(max_epoch, 'epoch'), ... )
This extension posts a message when:
start_msg
: The training has startedmsg
: The extension is triggered, usually at the end of each epochend_msg
: The training has finishederror_msg
: An exception has raised during the training
These messages can be specified as a format string, a callable that returns a string, or None to disable posting on that event.
When using a format string, the following variables are available for use:
manager
: an ExtensionsManager objectdefault
: the default message stringcontext
: an arbitrary object passed to this extensionerror
: an Exception object (forerror_msg
only)All reported values (
manager.observations
)
When using a callable, it should take (ExtensionsManager, context) or (ExtensionsManager, Exception, context) (for
error_msg
) and return a string.This extension can upload files along with the message when triggered.
filenames
can be a list of filenames (the same formatting rule asmsg
apply), or a callable taking (ExtensionsManager, context) and returning a list of filenames.To use this extension, you must create a Slack app, then specify the token via an environment variable
SLACK_BOT_TOKEN
ortoken
option.- Parameters:
channel (str) – The channel where messages and files will be sent. This can be a channel name or a channel ID.
msg (str, callable, or None) – A message to be sent when triggered. It can be a string to be formatted using
.format
or a callable that returns a string.start_msg (str, callable, or None) – A message to be sent at the beginning of the experiment.
end_msg (str, callable, or None) – A message to be sent at the completion of the experiment.
error_msg (str, callable, or None) – A message to be sent when an exception is raised during the experiment.
thread (bool) – When True, subsequent messages will be posted as a thread of the original message. Default is
True
.filenames (list of str or callable) – A list of files that will be uploaded. These are string templates that can take values in the same way as
msg
, or a callable that returns a list of filenames.upload_trigger (trigger or None) – Used to upload files at certain events. If not specified, files will be uploaded in every call.
context (Any) – Any arbitrary user object you will need when generating a message.
token (str) – Slack bot token. If
None
, the environment variableSLACK_BOT_TOKEN
will be used. Optional, default isNone
.
Methods
__init__
(channel[, msg, start_msg, end_msg, ...])default_end_msg
(context)default_error_msg
(exc, context)default_msg
(context)default_start_msg
(context)finalize
(manager)Finalizes the extension.
initialize
(manager)Initializes up the manager state.
load_state_dict
(to_load)on_error
(manager, exc, tb)Handles the error raised during training before finalization.
state_dict
()Serializes the extension state.
Attributes
default_name
Default name of the extension.
is_async
name
needs_model_state
priority
- __init__(channel, msg=None, *, start_msg='{default}', end_msg='{default}', error_msg='{default}', thread=True, filenames=None, upload_trigger=None, context=None, token=None)#
- Parameters:
channel (str) –
msg (Optional[Union[str, Callable[[ExtensionsManagerProtocol, Any], str]]]) –
start_msg (Optional[Union[str, Callable[[ExtensionsManagerProtocol, Any], str]]]) –
end_msg (Optional[Union[str, Callable[[ExtensionsManagerProtocol, Any], str]]]) –
error_msg (Optional[Union[str, Callable[[ExtensionsManagerProtocol, Any, Exception], str]]]) –
thread (bool) –
filenames (Optional[Union[Sequence[str], Callable[[ExtensionsManagerProtocol, Any], Sequence[str]]]]) –
upload_trigger (Optional[Union[Trigger, Callable[[ExtensionsManagerProtocol], bool], Tuple[float, str]]]) –
context (Optional[Any]) –
token (Optional[str]) –
- Return type:
None
- trigger: Optional[Union[Trigger, Callable[[ExtensionsManagerProtocol], bool], Tuple[float, str]]] = (1, 'epoch')#