docstr: Gets called at the end of a epoch.
docstr_tok: ["Gets","called","at","the","end","of","a","epoch","."]
code: def on_stage_end(self, stage, stage_loss, epoch):
      """Gets called at the end of a epoch."""
      # Compute/store important stats
      stage_stats = {"loss": stage_loss}
      if stage == sb.Stage.TRAIN:
          self.train_stats = stage_stats
      else:
          stage_stats["ACC"] = self.acc_metric.summarize()
          current_epoch = self.hparams.epoch_counter.current
          valid_search_interval = self.hparams.valid_search_interval
          if (
              current_epoch % valid_search_interval == 0
              or stage == sb.Stage.TEST
          ):
              stage_stats["WER"] = self.wer_metric.summarize(
                  "error_rate"
              )
              stage_stats["CER"] = self.cer_metric.summarize(
                  "error_rate"
              )
  
      # log stats and save checkpoint at end-of-epoch
      if stage == sb.Stage.VALID:
          # report different epoch stages according current stage
          current_epoch = self.hparams.epoch_counter.current
          if current_epoch <= self.hparams.stage_one_epochs:
              lr = self.hparams.noam_annealing.current_lr
              steps = self.hparams.noam_annealing.n_steps
              optimizer = self.optimizer.__class__.__name__
          else:
              lr = self.hparams.lr_sgd
              steps = -1
              optimizer = self.optimizer.__class__.__name__
  
          epoch_stats = {
              "epoch": epoch,
              "lr": lr,
              "steps": steps,
              "optimizer": optimizer,
          }
          self.hparams.train_logger.log_stats(
              stats_meta=epoch_stats,
              train_stats=self.train_stats,
              valid_stats=stage_stats,
          )
          self.checkpointer.save_and_keep_only(
              meta={"ACC": stage_stats["ACC"], "epoch": epoch},
              max_keys=["ACC"],
          )
  
      elif stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "Epoch loaded": self.hparams.epoch_counter.current
              },
              test_stats=stage_stats,
          )
          if if_main_process():
              with open(self.hparams.test_wer_file, "w") as w:
                  self.wer_metric.write_stats(w)
  
file_path: speechbrain/recipes/CommonVoice/ASR/transformer/train.py
imports: import sys
  import torch
  import torchaudio
  import logging
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.tokenizers.SentencePiece import SentencePiece
  from speechbrain.utils.distributed import run_on_main, if_main_process
  from speechbrain.utils.data_utils import undo_padding
label_desc: Use image node_id 6 for calling the ASR obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types