Model Pipeline - Why the training loop is explicit in PyTorch
This pipeline shows why PyTorch uses an explicit training loop. It helps you control every step of learning your model, like a recipe you follow carefully.
This pipeline shows why PyTorch uses an explicit training loop. It helps you control every step of learning your model, like a recipe you follow carefully.
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.60 | Loss starts high, accuracy low as model begins learning |
| 2 | 0.45 | 0.75 | Loss decreases, accuracy improves with training |
| 3 | 0.30 | 0.85 | Model learns patterns, loss lowers further |
| 4 | 0.20 | 0.90 | Training converges, accuracy nears target |
| 5 | 0.15 | 0.93 | Final epoch shows good performance |
for epoch in range(2):
print(f"Epoch {epoch+1} start")
for batch in range(3):
print(f" Batch {batch+1} processed")
for epoch in range(3):
optimizer.zero_grad()
output = model(data)
loss = loss_fn(output, target)
loss.backward
optimizer.step()
Pass the test and this pattern moves unknown