Skip to content

Commit 4850dd4

Browse files
authored
Replace model.forward with model
As per pytorch documentation use of model.forward is discouraged. https://discuss.pytorch.org/t/any-different-between-model-input-and-model-forward-input/3690
1 parent 0acb97a commit 4850dd4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

intro-to-pytorch/Part 3 - Training Neural Networks (Exercises).ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
"optimizer.zero_grad()\n",
381381
"\n",
382382
"# Forward pass, then backward pass, then update weights\n",
383-
"output = model.forward(images)\n",
383+
"output = model(images)\n",
384384
"loss = criterion(output, labels)\n",
385385
"loss.backward()\n",
386386
"print('Gradient -', model[0].weight.grad)"
@@ -463,7 +463,7 @@
463463
"img = images[0].view(1, 784)\n",
464464
"# Turn off gradients to speed up this part\n",
465465
"with torch.no_grad():\n",
466-
" logits = model.forward(img)\n",
466+
" logits = model(img)\n",
467467
"\n",
468468
"# Output of the network are logits, need to take softmax for probabilities\n",
469469
"ps = F.softmax(logits, dim=1)\n",

0 commit comments

Comments
 (0)