Error implementing torch.optim.lr_scheduler.LambdaLR in Pytorch
I'm working on an Image classifier and trying to implement Cyclical Learning Rates to have a better results. I'm using lr_scheduler.LambdaLR to adjust the learning rate during training, but I'm having an error that I'm not sure what is the cause of it.
this is my code:

lr_find_epochs = 2
start_lr = 1e-7
end_lr = 0.1
# Set up the model, optimizer and loss function for the experiment

optimizer = torch.optim.SGD(model.parameters(), start_lr)
criterion = nn.NLLLoss()
# LR function lambda

lr_lambda = lambda x: math.exp(x * math.log(end_lr / start_lr) / (lr_find_epochs * len( train_loader)))
scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda=lr_lambda)


and this is the error I'm having:


The error in lr_scheduler.py.

The issue is caused by this line here

scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda=lr_lambda)


As the error suggests you are trying to reference value before it has been assigned,i.e. the lambda function is called with itself as the argument which is currently not assigned to anything. As a result of this, an error is raised in lr_scheduler.py

Maybe you want to pass something else to the lambda function.
