You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an error when using Adam optimizer and resuming training from checkpoint, which states that state in Adam optimizer is not found. I found that the line optim.set_parameters(model.parameters()) wipe out states in optim.optimizer.state_dict.state.
if not opt.train_from_state_dict and not opt.train_from:
for p in model.parameters():
p.data.uniform_(-opt.param_init, opt.param_init)
encoder.load_pretrained_vectors(opt)
decoder.load_pretrained_vectors(opt)
optim = onmt.Optim(
opt.optim, opt.learning_rate, opt.max_grad_norm,
lr_decay=opt.learning_rate_decay,
start_decay_at=opt.start_decay_at
)
else:
print('Loading optimizer from checkpoint:')
optim = checkpoint['optim']
print(optim)
optim.set_parameters(model.parameters())
after I move the line optim.set_parameters(model.parameters()) into the block under if statement, the code works fine:
if not opt.train_from_state_dict and not opt.train_from:
for p in model.parameters():
p.data.uniform_(-opt.param_init, opt.param_init)
encoder.load_pretrained_vectors(opt)
decoder.load_pretrained_vectors(opt)
optim = onmt.Optim(
opt.optim, opt.learning_rate, opt.max_grad_norm,
lr_decay=opt.learning_rate_decay,
start_decay_at=opt.start_decay_at
)
optim.set_parameters(model.parameters())
else:
print('Loading optimizer from checkpoint:')
optim = checkpoint['optim']
print(optim)
The text was updated successfully, but these errors were encountered:
@ylhsieh But I later found that the code above is just silencing the error rather than fixing it ...... Adam stop updating parameters when reading from a checkpoint.
I encountered an error when using Adam optimizer and resuming training from checkpoint, which states that state in Adam optimizer is not found. I found that the line
optim.set_parameters(model.parameters())
wipe out states inoptim.optimizer.state_dict.state
.after I move the line
optim.set_parameters(model.parameters())
into the block under if statement, the code works fine:The text was updated successfully, but these errors were encountered: