Mrpatekful / swats

Unofficial implementation of Switching from Adam to SGD optimization in PyTorch.
MIT License
65 stars 18 forks source link

Training After Switch to SGD is Flat #2

Open noiran78 opened 4 years ago

noiran78 commented 4 years ago

Hi,

Thanks for the implementation of SWATS in this repository. However, when I used it on VGG-16 running for 100 epochs with initial learning rate 0.001, after switching to SGD on epoch 15, the learning curve fell significantly and it stays flat. The updated learning rate is 0.34.

Is this an expected behavior or is there any problem here?

Looking to hear from you.

Best Regards

Mrpatekful commented 4 years ago

Sorry for the late response, I haven't received notification of this issue. SGD generally requires some kind of lr scheduling, which is not included in this implementation. I tried adding it, however I couldnt find a nice solution to handle the SGD and Adam phase differently, which is desirable for any kind of scheduling.

jonathan016 commented 4 years ago

Oh I see. So in my case, what do you think should be done?

I'm facing similar issue (flat accuracy after switching)

Mrpatekful commented 4 years ago

You could try writing some kind of custom lr scheduling, since the optimizer stores the current phase in the param group with the key phase and apply different behavior based on that.

def custom_schedule(optimizer, compute_adam_lr, compute_sgd_lr):
    for param_group in optimizer.param_groups:
        if param_group['phase'] == 'SGD':
            param_group['lr'] = compute_sgd_lr()
        elif param_group['phase'] == 'ADAM':
            param_group['lr'] = compute_adam_lr()
jonathan016 commented 4 years ago

I see. Thanks a lot, will try that and hopefully the problem does not occur again. Thank you @Mrpatekful