開始使用免費開始

使用 Trainer 進行混合精度訓練

你想簡化混合精度訓練的介面。作為 Accelerator 訓練迴圈的替代方案,由於你的模型不需要自訂訓練迴圈,你決定改用 Trainer。請將 Trainer 設定為使用混合精度訓練!由於會呼叫 trainer.train(),此練習執行時間會稍長。

本練習屬於課程

使用 PyTorch 高效訓練 AI 模型

檢視課程

練習說明

  • Trainer 啟用混合精度訓練。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

training_args = TrainingArguments(
    output_dir="./results",
    evaluation_strategy="epoch",
    # Enable mixed precision training
    ____=____
)
trainer = Trainer(model=model,
                  args=training_args,
                  train_dataset=dataset["train"],
                  eval_dataset=dataset["validation"],
                  compute_metrics=compute_metrics)
trainer.train()
編輯並執行程式碼