Hello Barber!



 blackbirdbarber:

# before we learn
p1 = model.fc.weight
od1 = model.state_dict()
...
p2 = model.fc.weight
od2 = model.state_dict()

print(torch.equal(p1,p2))

print(torch.equal(p1,p2)) will return True.
Can anyone tell why the parameters haven’t been updated.


p1 is a reference to model.fc.weight.  (In python (essentially)
all variables are references to objects.)  So when your optimizer
updates model.fc.weight, p1 also “changes” in that the object
p1 refers to has changed.
Try setting p1 = model.fc.weight.clone().  Now p1 will refer
to a new copy of the data in model.fc.weight that won’t be
changed when model.fc.weight itself is changed.
Or you could print out (with enough precision to see a small
change) a couple of elements of model.fc.weight before and
after the optimization step and note that they change.
Good luck.
K. Frank