AttributeError: 'MultiStepLR' object has no attribute 'state_dict'

How can I save the scheduler state ?
I tried :

    temp = scheduler.state_dict()
    temp['last_epoch']=36

but got the error

AttributeError: ‘MultiStepLR’ object has no attribute ‘state_dict’

The reason I’m trying this is , I forgot to save the scheduler setting along with other needed info when saving the checkpoint! so now that I need to resume tarining, I need to choose the correct epoch. I thought the best way would be to manually create a new dictionary for it and then use load_state_dict() with the new information and carry on.
I dont know why I’m facing this error, I saw for saving, people simply do :

save_checkpoint({
            'epoch': epoch + 1,
            'arch': args.arch,
            'state_dict': model.state_dict(),
            'best_prec1': best_prec1,
            'best_prec5': best_prec5,
            'optimizer' : optimizer.state_dict(),
            'scheduler' : scheduler.state_dict()
        }, is_best, filename, bestname)


def save_checkpoint(state, is_best, filename, bestname):
    torch.save(state, filename)
    if is_best:
        shutil.copyfile(filename, bestname)

so as you can see the scheduler has a state_dict(). Can anyone tell me where the problem is and how I can fix it?

This code works for PyTorch 0.4.0:

optimizer = optim.SGD([torch.randn(10, requires_grad=True)], lr=1e-1)
scheduler = optim.MultiStepLR(optimizer, [5, 10], 0.1)
print(scheduler.state_dict())

Which version are you using?

1 Like

Oh, so thats it! Thank you very much. I checked and found out on my current system the version is 3.01!

my torch version is 0.4.0
yet I get
AttributeError: ‘ReduceLROnPlateau’ object has no attribute ‘state_dict’
Here is a list of its attributes:
lrs.ReduceLROnPlateau.dict.keys():
dict_keys([‘module’, ‘doc’, ‘init’, ‘_reset’, ‘step’, ‘_reduce_lr’, ‘in_cooldown’, ‘_cmp’, ‘_init_is_better’, ‘dict’, ‘weakref’])