22.02.2024 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Output

[Parameter containing:

tensor([0.3367], requires_grad=True), Parameter containing:

tensor([0.1288], requires_grad=True)]

state_dict

Moreover, we can get the current values of all parameters using our model’s

state_dict() method.

dummy.state_dict()

Output

OrderedDict([('b', tensor([0.3367])), ('w', tensor([0.1288]))])

The state_dict() of a given model is simply a Python dictionary that maps each

attribute / parameter to its corresponding tensor. But only learnable parameters

are included, as its purpose is to keep track of parameters that are going to be

updated by the optimizer.

By the way, the optimizer itself has a state_dict() too, which contains its internal

state, as well as other hyper-parameters. Let’s take a quick look at it:

optimizer.state_dict()

Output

{'state': {},

'param_groups': [{'lr': 0.1,

'momentum': 0,

'dampening': 0,

'weight_decay': 0,

'nesterov': False,

'params': [140535747664704, 140535747688560]}]}

106 | Chapter 1: A Simple Regression Problem

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

Saved successfully!

Ooh no, something went wrong!