Model Pipeline - Mixed precision training (AMP)
This pipeline shows how mixed precision training uses both 16-bit and 32-bit numbers to speed up training while keeping accuracy. It helps the model learn faster and use less memory.
This pipeline shows how mixed precision training uses both 16-bit and 32-bit numbers to speed up training while keeping accuracy. It helps the model learn faster and use less memory.
Loss
0.7 |*
0.6 | *
0.5 | *
0.4 | *
0.3 | *
0.2 | *
0.1 | *
--------
1 2 3 4 5 Epochs| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 0.65 | 0.75 | Loss starts high, accuracy moderate as model begins learning |
| 2 | 0.48 | 0.83 | Loss decreases, accuracy improves with mixed precision speeding training |
| 3 | 0.35 | 0.89 | Model converges faster due to AMP, loss lowers steadily |
| 4 | 0.28 | 0.92 | Stable training, accuracy nearing high performance |
| 5 | 0.22 | 0.94 | Final epoch shows good convergence with low loss and high accuracy |
scaler = torch.cuda.amp.GradScaler()
for input, target in dataloader:
optimizer.zero_grad()
with torch.cuda.amp.autocast():
output = model(input)
loss = loss_fn(output, target)
scaler.scale(loss).backward()
scaler.step(optimizer)
scaler.update()
What is the role of scaler.scale(loss).backward() here?scaler = torch.cuda.amp.GradScaler()
for input, target in dataloader:
optimizer.zero_grad()
with torch.cuda.amp.autocast():
output = model(input)
loss = loss_fn(output, target)
loss.backward()
scaler.step(optimizer)
scaler.update()
What is the error and how to fix it?Pass the test and this pattern moves unknown