(opt, device_id, model, fields,
                  optim, data_type, model_saver=None)
return trainer
Simplify `Trainer` creation based on user `opt`s*

    Args:
        opt (:obj:`Namespace`): user options (usually from argument parsing)
        model (:obj:`onmt.models.NMTModel`): the model to train
        fields (dict): dict of fields
        optim (:obj:`onmt.utils.Optimizer`): optimizer used during training
        data_type (str): string describing the type of data
            e.g. "text", "img", "audio"
        model_saver(:obj:`onmt.models.ModelSaverBase`): the utility object
            used to save the model
Simplify `Trainer` creation based on user `opt`s*
Simplify Trainer creation based on user opt s *
def build_trainer(opt, device_id, model, fields,
                  optim, data_type, model_saver=None):
    """
    Simplify `Trainer` creation based on user `opt`s*

    Args:
        opt (:obj:`Namespace`): user options (usually from argument parsing)
        model (:obj:`onmt.models.NMTModel`): the model to train
        fields (dict): dict of fields
        optim (:obj:`onmt.utils.Optimizer`): optimizer used during training
        data_type (str): string describing the type of data
            e.g. "text", "img", "audio"
        model_saver(:obj:`onmt.models.ModelSaverBase`): the utility object
            used to save the model
    """
    # fine

    train_loss = onmt.utils.loss.build_loss_compute(
        model, fields["tgt"].vocab, opt)
    valid_loss = onmt.utils.loss.build_loss_compute(
        model, fields["tgt"].vocab, opt, train=False)

    trunc_size = opt.truncated_decoder  # Badly named...
    shard_size = opt.max_generator_batches
    norm_method = opt.normalization
    grad_accum_count = opt.accum_count
    n_gpu = opt.world_size
    if device_id >= 0:
        gpu_rank = opt.gpu_ranks[device_id]
    else:
        gpu_rank = 0
        n_gpu = 0
    gpu_verbose_level = opt.gpu_verbose_level

    report_manager = onmt.utils.build_report_manager(opt)
    trainer = onmt.Trainer(model, train_loss, valid_loss, optim, trunc_size,
                           shard_size, data_type, norm_method,
                           grad_accum_count, n_gpu, gpu_rank,
                           gpu_verbose_level, report_manager,
                           model_saver=model_saver)
    return trainer
def build_trainer ( opt , device_id , model , fields , optim , data_type , model_saver = None ) : # fine train_loss = onmt . utils . loss . build_loss_compute ( model , fields [ "tgt" ] . vocab , opt ) valid_loss = onmt . utils . loss . build_loss_compute ( model , fields [ "tgt" ] . vocab , opt , train = False ) trunc_size = opt . truncated_decoder # Badly named... shard_size = opt . max_generator_batches norm_method = opt . normalization grad_accum_count = opt . accum_count n_gpu = opt . world_size if device_id >= 0 : gpu_rank = opt . gpu_ranks [ device_id ] else : gpu_rank = 0 n_gpu = 0 gpu_verbose_level = opt . gpu_verbose_level report_manager = onmt . utils . build_report_manager ( opt ) trainer = onmt . Trainer ( model , train_loss , valid_loss , optim , trunc_size , shard_size , data_type , norm_method , grad_accum_count , n_gpu , gpu_rank , gpu_verbose_level , report_manager , model_saver = model_saver ) return trainer