code: def save_best_model(
      model, optimizer, model_loss, best_loss, out_path, current_step
  ):
      if model_loss < best_loss:
          new_state_dict = model.state_dict()
          state = {
              "model": new_state_dict,
              "optimizer": optimizer.state_dict(),
              "step": current_step,
              "loss": model_loss,
              "date": datetime.date.today().strftime("%B %d, %Y"),
          }
          best_loss = model_loss
          bestmodel_path = "best_model.pth.tar"
          bestmodel_path = os.path.join(out_path, bestmodel_path)
          print(
              "\n > BEST MODEL ({0:.5f}) : {1:}".format(
                  model_loss, bestmodel_path
              )
          )
          torch.save(state, bestmodel_path)
      return best_loss
  
file_path: TTS/TTS/speaker_encoder/utils/generic_utils.py
imports: import datetime
  import os
  import re
  import torch
  from TTS.speaker_encoder.model import SpeakerEncoder
  from TTS.utils.generic_utils import check_argument
label_desc: Use image node_id 4 for calling a global function with example usage: save_best_model(model, optimizer, model_loss, best_loss, out_path, current_step) and returns: best_loss