What else does using load_state_dict change besides the parameters of model?

Viewed 22
model.train()
optimizer.zero_grad()
output = model(input)
loss = loss_fn(output, label)

model.load_state_dict(weight3, strict=False)  # weight3 is a OrderedDict

torch.autograd.backward(loss)
optimizer.step()

the code above is wrong. but we change the code, it will work.

model.train()
optimizer.zero_grad()
output = model(input)
loss = loss_fn(output, label)

for name, para in model.named_parameters():
    para.data = weight3[name]

torch.autograd.backward(loss)
optimizer.step()

so what's the difference between model.load_state_dict(weight3, strict=False) and for name, para in model.named_parameters(): para.data = weight3[name].

0 Answers
Related