Running pytorch 0.4.1 with python 3.6 I encountered this problem:
I cannot torch.save
my learning rate scheduler because python won't pickle a lambda function:
lambda1 = lambda epoch: epoch // 30
scheduler = LambdaLR(optimizer, lr_lambda=lambda1)
torch.save(scheduler.state_dict(), 'scheduler.pth.tar')
results with an error
PicklingError: Can't pickle <function <lambda> at 0x7f7583fe92f0>: attribute lookup <lambda> on __main__ failed
How can I save my scheduler?
I know that using a proper function instead of a lambda function for lambda1
can be saved, but I need a lambda function because I want to be able to control this function when it is defined (for instance I want to be able to change the fixed 30 in the denominator).
How can this be done and still allows me to save the scheduler?