docstr: Gets called at the end of an epoch.
  
  Arguments
  ---------
  stage : sb.Stage
      One of sb.Stage.TRAIN, sb.Stage.VALID, sb.Stage.TEST
  stage_loss : float
      The average loss for all of the data processed in this stage.
  epoch : int
      The currently-starting epoch. This is passed
      `None` during the test stage.
docstr_tok: ["Gets","called","at","the","end","of","an","epoch",".","Arguments","--","--","--","--","-","stage",":","sb.Stage","One","of","sb.Stage.TRAIN",",","sb.Stage.VALID",",","sb.Stage.TEST","stage_loss",":","float","The","average","loss","for","all","of","the","data","processed","in","this","stage",".","epoch",":","int","The","currently-starting","epoch",".","This","is","passed","`","None","`","during","the","test","stage","."]
code: def on_stage_end(self, stage, stage_loss, epoch):
      """Gets called at the end of an epoch.
  
      Arguments
      ---------
      stage : sb.Stage
          One of sb.Stage.TRAIN, sb.Stage.VALID, sb.Stage.TEST
      stage_loss : float
          The average loss for all of the data processed in this stage.
      epoch : int
          The currently-starting epoch. This is passed
          `None` during the test stage.
      """
      if stage == sb.Stage.VALID:
          # Update learning rate
          self.scheduler_g.step()
          self.scheduler_d.step()
          lr_g = self.optimizer_g.param_groups[-1]["lr"]
          lr_d = self.optimizer_d.param_groups[-1]["lr"]
  
          self.hparams.train_logger.log_stats(  # 1#2#
              stats_meta={"Epoch": epoch, "lr_g": lr_g, "lr_d": lr_d},
              train_stats=self.last_loss_stats[sb.Stage.TRAIN],
              valid_stats=self.last_loss_stats[sb.Stage.VALID],
          )
          # The tensorboard_logger writes a summary to stdout and to the logfile.
          if self.hparams.use_tensorboard:
              self.tensorboard_logger.log_stats(
                  stats_meta={
                      "Epoch": epoch,
                      "lr_g": lr_g,
                      "lr_d": lr_d,
                  },
                  train_stats=self.last_loss_stats[sb.Stage.TRAIN],
                  valid_stats=self.last_loss_stats[sb.Stage.VALID],
              )
  
          # Save the current checkpoint and delete previous checkpoints.
          epoch_metadata = {
              **{"epoch": epoch},
              **self.last_loss_stats[sb.Stage.VALID],
          }
          if self.checkpointer is not None:
              self.checkpointer.save_and_keep_only(
                  meta=epoch_metadata,
                  end_of_epoch=True,
                  min_keys=["loss"],
                  ckpt_predicate=(
                      lambda ckpt: (
                          ckpt.meta["epoch"]
                          % self.hparams.keep_checkpoint_interval
                          != 0
                      )
                  )
                  if self.hparams.keep_checkpoint_interval is not None
                  else None,
              )
  
          self.run_inference_sample("Valid", epoch)
  
      # We also write statistics about test data to stdout and to the TensorboardLogger.
      if stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(  # 1#2#
              {"Epoch loaded": self.hparams.epoch_counter.current},
              test_stats=self.last_loss_stats[sb.Stage.TEST],
          )
          if self.hparams.use_tensorboard:
              self.tensorboard_logger.log_stats(
                  {"Epoch loaded": self.hparams.epoch_counter.current},
                  test_stats=self.last_loss_stats[sb.Stage.TEST],
              )
          self.run_inference_sample("Test")
  
imports: import sys
  import copy
  import random
  import pathlib
  from hyperpyyaml import load_hyperpyyaml
  import speechbrain
  from speechbrain.utils.data_utils import scalarize
  import torch
  import torchaudio
  import numpy
label_desc: Use image node_id 7 for calling the HifiGanBrain obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types