Automatic device placement with Accelerator
Your conversational AI model needs to train on a massive dataset, so you've decided to move the model to a GPU. You're leveraging Accelerator for automatic device placement. Note this exercise actually runs on the CPU, but the code remains the same for running on the GPU.
A BERT-based model has been preloaded as model.
本练习是课程的一部分
Efficient AI Model Training with PyTorch
练习说明
- Declare an
acceleratorobject by instantiating the appropriate class. - Use the
acceleratorobject to prepare the model for distributed training with GPU.
交互式实操练习
通过完成这段示例代码来试试这个练习。
from accelerate import Accelerator
# Declare an accelerator object
accelerator = ____()
# Prepare the model for distributed training
model = accelerator.____(model)
print(accelerator.device)