def train_one_epoch(params: AttributeDict, model: nn.Module, optimizer: torch.optim.Optimizer, graph_compiler: CtcTrainingGraphCompiler, train_dl: torch.utils.data.DataLoader, valid_dl: torch.utils.data.DataLoader, tb_writer: Optional[SummaryWriter]=None, world_size: int=1) -> None:
    'Train the model for one epoch.\n\n    The training loss from the mean of all frames is saved in\n    `params.train_loss`. It runs the validation process every\n    `params.valid_interval` batches.\n\n    Args:\n      params:\n        It is returned by :func:`get_params`.\n      model:\n        The model for training.\n      optimizer:\n        The optimizer we are using.\n      graph_compiler:\n        It is used to convert transcripts to FSAs.\n      train_dl:\n        Dataloader for the training dataset.\n      valid_dl:\n        Dataloader for the validation dataset.\n      tb_writer:\n        Writer to write log messages to tensorboard.\n      world_size:\n        Number of nodes in DDP training. If it is 1, DDP is disabled.\n    '
    model.train()
    tot_loss = MetricsTracker()
    for (batch_idx, batch) in enumerate(train_dl):
        params.batch_idx_train += 1
        batch_size = len(batch['supervisions']['text'])
        (loss, loss_info) = compute_loss(params=params, model=model, batch=batch, graph_compiler=graph_compiler, is_training=True)
        tot_loss = ((tot_loss * (1 - (1 / params.reset_interval))) + loss_info)
        optimizer.zero_grad()
        loss.backward()
        clip_grad_norm_(model.parameters(), 5.0, 2.0)
        optimizer.step()
        if ((batch_idx % params.log_interval) == 0):
            logging.info(f'Epoch {params.cur_epoch}, batch {batch_idx}, loss[{loss_info}], tot_loss[{tot_loss}], batch size: {batch_size}')
        if ((batch_idx % params.log_interval) == 0):
            if (tb_writer is not None):
                loss_info.write_summary(tb_writer, 'train/current_', params.batch_idx_train)
                tot_loss.write_summary(tb_writer, 'train/tot_', params.batch_idx_train)
        if ((batch_idx > 0) and ((batch_idx % params.valid_interval) == 0)):
            valid_info = compute_validation_loss(params=params, model=model, graph_compiler=graph_compiler, valid_dl=valid_dl, world_size=world_size)
            model.train()
            logging.info(f'Epoch {params.cur_epoch}, validation {valid_info}')
            if (tb_writer is not None):
                valid_info.write_summary(tb_writer, 'train/valid_', params.batch_idx_train)
    loss_value = (tot_loss['loss'] / tot_loss['frames'])
    params.train_loss = loss_value
    if (params.train_loss < params.best_train_loss):
        params.best_train_epoch = params.cur_epoch
        params.best_train_loss = params.train_loss
Train the model for one epoch.

The training loss from the mean of all frames is saved in
`params.train_loss`. It runs the validation process every
`params.valid_interval` batches.

Args:
  params:
    It is returned by :func:`get_params`.
  model:
    The model for training.
  optimizer:
    The optimizer we are using.
  graph_compiler:
    It is used to convert transcripts to FSAs.
  train_dl:
    Dataloader for the training dataset.
  valid_dl:
    Dataloader for the validation dataset.
  tb_writer:
    Writer to write log messages to tensorboard.
  world_size:
    Number of nodes in DDP training. If it is 1, DDP is disabled.
def train_one_epoch(params: AttributeDict, model: nn.Module, optimizer: torch.optim.Optimizer, graph_compiler: CtcTrainingGraphCompiler, train_dl: torch.utils.data.DataLoader, valid_dl: torch.utils.data.DataLoader, tb_writer: Optional[SummaryWriter]=None, world_size: int=1) -> None:
    'Train the model for one epoch.\n\n    The training loss from the mean of all frames is saved in\n    `params.train_loss`. It runs the validation process every\n    `params.valid_interval` batches.\n\n    Args:\n      params:\n        It is returned by :func:`get_params`.\n      model:\n        The model for training.\n      optimizer:\n        The optimizer we are using.\n      graph_compiler:\n        It is used to convert transcripts to FSAs.\n      train_dl:\n        Dataloader for the training dataset.\n      valid_dl:\n        Dataloader for the validation dataset.\n      tb_writer:\n        Writer to write log messages to tensorboard.\n      world_size:\n        Number of nodes in DDP training. If it is 1, DDP is disabled.\n    '
    model.train()
    tot_loss = MetricsTracker()
    for (batch_idx, batch) in enumerate(train_dl):
        params.batch_idx_train += 1
        batch_size = len(batch['supervisions']['text'])
        (loss, loss_info) = compute_loss(params=params, model=model, batch=batch, graph_compiler=graph_compiler, is_training=True)
        tot_loss = ((tot_loss * (1 - (1 / params.reset_interval))) + loss_info)
        optimizer.zero_grad()
        loss.backward()
        clip_grad_norm_(model.parameters(), 5.0, 2.0)
        optimizer.step()
        if ((batch_idx % params.log_interval) == 0):
            logging.info(f'Epoch {params.cur_epoch}, batch {batch_idx}, loss[{loss_info}], tot_loss[{tot_loss}], batch size: {batch_size}')
        if ((batch_idx % params.log_interval) == 0):
            if (tb_writer is not None):
                loss_info.write_summary(tb_writer, 'train/current_', params.batch_idx_train)
                tot_loss.write_summary(tb_writer, 'train/tot_', params.batch_idx_train)
        if ((batch_idx > 0) and ((batch_idx % params.valid_interval) == 0)):
            valid_info = compute_validation_loss(params=params, model=model, graph_compiler=graph_compiler, valid_dl=valid_dl, world_size=world_size)
            model.train()
            logging.info(f'Epoch {params.cur_epoch}, validation {valid_info}')
            if (tb_writer is not None):
                valid_info.write_summary(tb_writer, 'train/valid_', params.batch_idx_train)
    loss_value = (tot_loss['loss'] / tot_loss['frames'])
    params.train_loss = loss_value
    if (params.train_loss < params.best_train_loss):
        params.best_train_epoch = params.cur_epoch
        params.best_train_loss = params.train_loss