Skip to content

Commit 43bd101

Browse files
anttikupsvekars
andauthored
Fix calculation of current item number in optimization_tutorial.py (#2743)
Current item calculation gave the wrong number when dataset doesn't split to batches equally. Co-authored-by: Svetlana Karslioglu <[email protected]>
1 parent 49c1494 commit 43bd101

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

beginner_source/basics/optimization_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def train_loop(dataloader, model, loss_fn, optimizer):
163163
optimizer.zero_grad()
164164

165165
if batch % 100 == 0:
166-
loss, current = loss.item(), (batch + 1) * len(X)
166+
loss, current = loss.item(), batch * batch_size + len(X)
167167
print(f"loss: {loss:>7f} [{current:>5d}/{size:>5d}]")
168168

169169

0 commit comments

Comments
 (0)