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."""
      if stage == sb.Stage.TRAIN:
          self.train_loss = stage_loss
      else:
          per = self.per_metrics.summarize("error_rate")
  
      if stage == sb.Stage.VALID:
          old_lr_adam, new_lr_adam = self.hparams.lr_annealing_adam(per)
          (
              old_lr_wav2vec,
              new_lr_wav2vec,
          ) = self.hparams.lr_annealing_wav2vec(per)
          sb.nnet.schedulers.update_learning_rate(
              self.adam_optimizer, new_lr_adam
          )
          sb.nnet.schedulers.update_learning_rate(
              self.wav2vec_optimizer, new_lr_wav2vec
          )
  
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "epoch": epoch,
                  "lr_adam": old_lr_adam,
                  "lr_wav2vec": old_lr_wav2vec,
              },
              train_stats={"loss": self.train_loss},
              valid_stats={"loss": stage_loss, "PER": per},
          )
          self.checkpointer.save_and_keep_only(
              meta={"PER": per}, min_keys=["PER"]
          )
  
      if stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "Epoch loaded": self.hparams.epoch_counter.current
              },
              test_stats={"loss": stage_loss, "PER": per},
          )
          if if_main_process():
              with open(self.hparams.test_wer_file, "w") as w:
                  w.write("Transducer loss stats:\n")
                  self.transducer_metrics.write_stats(w)
                  w.write("\nPER stats:\n")
                  self.per_metrics.write_stats(w)
                  print(
                      "Transducer and PER stats written to file",
                      self.hparams.test_wer_file,
                  )
  
file_path: speechbrain/recipes/TIMIT/ASR/transducer/train_wav2vec.py
imports: import os
  import sys
  import logging
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main, if_main_process
label_desc: Use image node_id 4 for calling the ASR_Brain obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types