How to use the lbfgs optimizer with pytorch-lightning?
I have a problem in using the LBFGS optimizer from pytorch with lightning.
I use the template from here to start a new project and here is the code that I tried (only the training portion):

def training_step(self, batch, batch_nb):
    x, y = batch
    x = x.float()
    y = y.float()
    y_hat = self.forward(x)
    return {'loss': F.mse_loss(y_hat, y)}

def configure_optimizers(self):
    optimizer = torch.optim.LBFGS(self.parameters())
    return optimizer

def optimizer_step(self, epoch_nb, batch_nb, optimizer, optimizer_i):
    def closure():
        optimizer.zero_grad()
        l = self.training_step(batch, batch_nb)
        loss = l['loss']
        loss.backward()
        return loss

    optimizer.step(closure)


The LBFGS optimizer from pytorch requires a closure function (see here and here), but I don't know how to define it inside the template, specially I don't know how the batch data is passed to the optimizer. I tried to define a custom optimizer_step function but I have some problems to passing the batch inside the closure function.

I will be very thankful of any advise that helps me to solve this problem or points me to the right direction.

Environment:


PyTorch version:  1.2.0+cpu
Lightning version: 0.4.9   
Test-tube version: 0.7.1


The support for lbfgs optimizer was added on #310, now it is not required to define a closure function.
