开始使用免费开始使用

AdamW with Trainer

You're beginning to train a Transformer model to simplify language translations. As a first step, you decide to use the AdamW optimizer as a benchmark and the Trainer interface for quick setup. Set up Trainer to use the AdamW optimizer.

AdamW has been pre-imported from torch.optim. Some training objects have been pre-loaded: model, training_args, train_dataset, validation_dataset, compute_metrics.

本练习是课程的一部分

Efficient AI Model Training with PyTorch

查看课程

练习说明

  • Pass the model parameters to the AdamW optimizer.
  • Pass the optimizer to Trainer.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Pass the model parameters to the AdamW optimizer
optimizer = ____(params=____.____())

# Pass the optimizer to Trainer
trainer = Trainer(model=model,
                  args=training_args,
                  train_dataset=train_dataset,
                  eval_dataset=validation_dataset,
                  optimizers=(____, None),
                  compute_metrics=compute_metrics)

trainer.train()
编辑并运行代码