Gradient Accumulation ด้วย Trainer
กำลังตั้งค่า Trainer สำหรับโมเดลแปลภาษา โดยใช้ gradient accumulation เพื่อให้เทรนกับ batch ขนาดใหญ่ขึ้นได้อย่างมีประสิทธิภาพ โมเดลจะเรียนรู้การแปลอย่างกระชับโดยเทรนกับ paraphrase จากชุดข้อมูล MRPC ลองกำหนดค่า training arguments เพื่อสะสม gradient กัน! การรันแบบฝึกหัดนี้จะใช้เวลาสักครู่เนื่องจากมีการเรียก trainer.train()
model, dataset และฟังก์ชัน compute_metrics() ถูกกำหนดไว้ล่วงหน้าแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การเทรน AI Model อย่างมีประสิทธิภาพด้วย PyTorch
คำแนะนำการฝึกหัด
- กำหนดจำนวน gradient accumulation steps เป็นสอง
- ส่ง training arguments ให้กับ
Trainer
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
training_args = TrainingArguments(
output_dir="./results",
evaluation_strategy="epoch",
# Set the number of gradient accumulation steps to two
____=____
)
trainer = Trainer(
model=model,
# Pass in the training arguments to Trainer
____=____,
train_dataset=dataset["train"],
eval_dataset=dataset["validation"],
compute_metrics=compute_metrics,
)
trainer.train()