How to fix "list index out of range" error with updateGradInput?

I don’t understand.
Which line gives that error? A stack trace would be helpful.
At first glance that code looks identical to your original code.