How optimizer changes weights

take look at my code:

optimizer=optim.Adam(net.parameters(),lr=0.001)
 optimizer.step()

how does optimizer changes net parameters? it is passed once and then they don’t have any connection.is there any pointer stuff there?or i missed something while learning pytorch\python.

The optimizer will use the references to all passed parameters and update them in the step function.
You could check the id of each parameter in e.g. optimizer.param_groups[0]['params'] and will see that the ids match the parameter ids in the model.

1 Like