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."""
      stage_stats = {"loss": stage_loss}
      if stage == sb.Stage.TRAIN:
          self.train_stats = stage_stats
  
      if stage == sb.Stage.VALID:
          if not (
              isinstance(
                  self.hparams.lr_annealing,
                  sb.nnet.schedulers.NoamScheduler,
              )
              or isinstance(
                  self.hparams.lr_annealing,
                  sb.nnet.schedulers.CyclicCosineScheduler,
              )
          ):
              old_lr, new_lr = self.hparams.lr_annealing(stage_loss)
              sb.nnet.schedulers.update_learning_rate(
                  self.optimizer, new_lr
              )
          else:
              old_lr = self.hparams.lr_annealing.current_lr
  
          self.hparams.train_logger.log_stats(
              stats_meta={"epoch": epoch, "lr": old_lr},
              train_stats=self.train_stats,
              valid_stats=stage_stats,
          )
          self.checkpointer.save_and_keep_only(
              meta=stage_stats,
              min_keys=["loss"],
          )
  
      elif stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "Epoch loaded": self.hparams.epoch_counter.current
              },
              test_stats=stage_stats,
          )
  
file_path: speechbrain/recipes/KsponSpeech/LM/train.py
imports: import sys
  import logging
  from pathlib import Path
  import torch
  from hyperpyyaml import load_hyperpyyaml
  import speechbrain
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 4 for calling the LM obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types