class_docstr: Class that manages the training loop. See speechbrain.core.Brain.
class_docstr_tok: ["Class","that","manages","the","training","loop",".","See","speechbrain.core.Brain","."]
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.
      """
  
      # Store the train loss until the validation stage.
      stage_stats = {"loss": stage_loss}
      if stage == sb.Stage.TRAIN:
          self.train_stats = stage_stats
  
      # Summarize the statistics from the stage for record-keeping.
      else:
          stage_stats["CER"] = self.cer_metric.summarize("error_rate")
          stage_stats["WER"] = self.wer_metric.summarize("error_rate")
  
      # Perform end-of-iteration things, like annealing, logging, etc.
      if stage == sb.Stage.VALID:
          # Update learning rate
          old_lr, new_lr = self.hparams.lr_annealing(stage_stats["WER"])
          sb.nnet.schedulers.update_learning_rate(
              self.optimizer, new_lr
          )
  
          # The train_logger writes a summary to stdout and to the logfile.
          self.hparams.train_logger.log_stats(
              stats_meta={"epoch": epoch, "lr": old_lr},
              train_stats=self.train_stats,
              valid_stats=stage_stats,
          )
  
          # Save the current checkpoint and delete previous checkpoints.
          self.checkpointer.save_and_keep_only(
              meta={"WER": stage_stats["WER"]},
              min_keys=["WER"],
          )
  
      # We also write statistics about test data to stdout and to the logfile.
      elif stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "Epoch loaded": self.hparams.epoch_counter.current
              },
              test_stats=stage_stats,
          )
          with open(self.hparams.wer_file, "w") as w:
              self.wer_metric.write_stats(w)
  
file_path: orion/examples/speechbrain_tutorial/train.py
imports: import logging
  import sys
  import speechbrain
  import torch
  from hyperpyyaml import load_hyperpyyaml
  from mini_librispeech_prepare import prepare_mini_librispeech
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 7 for calling the ASR obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types