22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

dummy_x = torch.tensor([0.3])

dummy_model.forward(dummy_x)

Output

tensor([-0.7514], grad_fn=<AddBackward0>)

It should add a new tuple to the dummy list, one containing a linear layer, an input

tensor (0.3), and an output tensor (-0.7514). By the way, your values are going to be

different than mine, since we didn’t bother to use a seed here.

dummy_list

Output

[]

"Empty?! So it is not working?"

GOTCHA! I deliberately used the model’s forward() method here to illustrate

something we’ve discussed much earlier, in Chapter 1:

You should NOT call the forward(x) method! You should call the

whole model instead, as in model(x), to perform a forward pass.

Otherwise, your hooks won’t work.

Let’s do it right this time:

dummy_model(dummy_x)

Output

tensor([-0.7514], grad_fn=<AddBackward0>)

396 | Chapter 5: Convolutions

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!