Currently I am getting this error when trying to run my function forwards and backwards to evaluate loss and gradient.
The full error message is:
Running optimization with L-BFGS
Traceback (most recent call last):
File "test2.py", line 309, in <module>
x, losses = optim.lbfgs(feval, img, optim_state)
File "/usr/local/lib/python2.7/dist-packages/torch/legacy/optim/lbfgs.py", line 66, in lbfgs
f, g = opfunc(x)
File "test2.py", line 264, in feval
grad = model.updateGradInput(x, dy)
File "/usr/local/lib/python2.7/dist-packages/torch/legacy/nn/Sequential.py", line 47, in updateGradInput
self.gradInput = self.modules[0].updateGradInput(input, currentGradOutput)
IndexError: list index out of range
Specifically, the issue is with:
grad = model.updateGradInput(x, dy)
This is the function used to evaluate the loss and gradient:
num_calls = [0]
def feval(x):
num_calls[0] += 1
model.updateOutput(x)
grad = model.updateGradInput(x, dy)
return loss, grad.view(grad.nelement())
This is what I use to run the function:
if params.optimizer == 'lbfgs':
optim_state = {
"maxIter": params.num_iterations,
"verbose": True,
"tolX":-1,
"tolFun":-1,
}
x, losses = optim.lbfgs(feval, img, optim_state)
The y
and dy
variables come from:
y = model.updateOutput(img)
dy = img.clone().zero_()
I don’t understand why the updateOutput
function works, but the updateGradInput
is giving me issues?
This is the Sequential.py code which is referenced in the error message:
https://github.com/pytorch/pytorch/blob/master/torch/legacy/nn/Sequential.py#L43-L48