def save_checkpoint(params: AttributeDict, model: nn.Module, optimizer: torch.optim.Optimizer, scheduler: torch.optim.lr_scheduler._LRScheduler, rank: int=0) -> None:
    'Save model, optimizer, scheduler and training stats to file.\n\n    Args:\n      params:\n        It is returned by :func:`get_params`.\n      model:\n        The training model.\n    '
    if (rank != 0):
        return
    filename = (params.exp_dir / f'epoch-{params.cur_epoch}.pt')
    save_checkpoint_impl(filename=filename, model=model, params=params, optimizer=optimizer, scheduler=scheduler, rank=rank)
    if (params.best_train_epoch == params.cur_epoch):
        best_train_filename = (params.exp_dir / 'best-train-loss.pt')
        copyfile(src=filename, dst=best_train_filename)
    if (params.best_valid_epoch == params.cur_epoch):
        best_valid_filename = (params.exp_dir / 'best-valid-loss.pt')
        copyfile(src=filename, dst=best_valid_filename)
Save model, optimizer, scheduler and training stats to file.

Args:
  params:
    It is returned by :func:`get_params`.
  model:
    The training model.
def save_checkpoint(params: AttributeDict, model: nn.Module, optimizer: torch.optim.Optimizer, scheduler: torch.optim.lr_scheduler._LRScheduler, rank: int=0) -> None:
    'Save model, optimizer, scheduler and training stats to file.\n\n    Args:\n      params:\n        It is returned by :func:`get_params`.\n      model:\n        The training model.\n    '
    if (rank != 0):
        return
    filename = (params.exp_dir / f'epoch-{params.cur_epoch}.pt')
    save_checkpoint_impl(filename=filename, model=model, params=params, optimizer=optimizer, scheduler=scheduler, rank=rank)
    if (params.best_train_epoch == params.cur_epoch):
        best_train_filename = (params.exp_dir / 'best-train-loss.pt')
        copyfile(src=filename, dst=best_train_filename)
    if (params.best_valid_epoch == params.cur_epoch):
        best_valid_filename = (params.exp_dir / 'best-valid-loss.pt')
        copyfile(src=filename, dst=best_valid_filename)