transformer_discord_notifier.transformers

class transformer_discord_notifier.transformers.DiscordProgressCallback(token: Optional[str] = None, channel: Optional[Union[str, int]] = None)[source]

Bases: transformers.trainer_callback.ProgressCallback

An extended transformers.trainer_callback.ProgressCallback that logs training and evaluation progress and statistics to a Discord channel.

Variables
  • client (DiscordClient) – a blocking Discord client

  • disabled (bool) – True if Discord client couldn’t not be initialized successfully, all callback methods are disabled silently

Parameters
  • token (Optional[str], optional) – Discord bot token, by default None

  • channel (Optional[Union[str, int]], optional) – Discord channel name or numeric id, by default None

start() → None[source]

Start the Discord bot.

end() → None[source]

Stop the Discord bot. Cleans up resources.

on_init_end(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, **kwargs)[source]

Event called at the end of the initialization of the Trainer.

_new_tqdm_bar(desc: str, msg_fmt: str, delete_after: bool = True, **kwargs) → Tuple[tqdm.std.tqdm, transformer_discord_notifier.transformers.MessageWrapperTQDMWriter][source]

Builds an internal tqdm wrapper for progress tracking.

Patches its file.write method to forward it to Discord. Tries to update existing messages to avoid spamming the channel.

on_train_begin(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, **kwargs)[source]

Event called at the beginning of training.

on_prediction_step(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, eval_dataloader=None, **kwargs)[source]

Event called after a prediction step.

on_step_end(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, **kwargs)[source]

Event called at the end of a training step. If using gradient accumulation, one training step might take several inputs.

on_epoch_begin(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, **kwargs)[source]

Event called at the beginning of an epoch.

on_epoch_end(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, **kwargs)[source]

Event called at the end of an epoch.

on_train_end(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, **kwargs)[source]

Event called at the end of training.

on_evaluate(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, **kwargs)[source]

Event called after an evaluation phase.

_send_log_results(logs: Dict[str, Any], state: transformers.trainer_callback.TrainerState, args: transformers.training_args.TrainingArguments, is_train: bool) → int[source]

Formats current log metrics as Embed message.

Given a huggingface transformers Trainer callback parameters, we create an discord.Embed with the metrics as key-values. Send the message and returns the message id.

on_log(args: transformers.training_args.TrainingArguments, state: transformers.trainer_callback.TrainerState, control: transformers.trainer_callback.TrainerControl, logs: Optional[Dict[str, Any]] = None, **kwargs)[source]

Event called after logging the last logs.