You are right. I changed indices to Variable and got the following error:
Traceback (most recent call last):
File “/usr/share/java/pycharm-community/helpers/pydev/pydevd.py”, line 1599, in 
globals = debugger.run(setup[‘file’], None, None, is_module)
File “/usr/share/java/pycharm-community/helpers/pydev/pydevd.py”, line 1026, in run
pydev_imports.execfile(file, globals, locals)  # execute the script
File “/usr/share/java/pycharm-community/helpers/pydev/_pydev_imps/_pydev_execfile.py”, line 18, in execfile
exec(compile(contents+"\n", file, ‘exec’), glob, loc)
File “/home/usama/PycharmProjects/test/Maxout_test.py”, line 128, in 
loss.backward()
File “/home/usama/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py”, line 156, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables)
File “/home/usama/anaconda3/lib/python3.6/site-packages/torch/autograd/init.py”, line 98, in backward
variables, grad_variables, retain_graph)
File “/home/usama/anaconda3/lib/python3.6/site-packages/torch/autograd/function.py”, line 91, in apply
return self._forward_cls.backward(self, *args)
File “/home/usama/PycharmProjects/test/Maxout_test.py”, line 42, in backward
input[:, i * 4] = a0 * grad_output
File “/home/usama/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py”, line 829, in mul
return self.mul(other)
File “/home/usama/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py”, line 339, in mul
return Mul.apply(self, other)
File “/home/usama/anaconda3/lib/python3.6/site-packages/torch/autograd/_functions/basic_ops.py”, line 48, in forward
return a.mul(b)
TypeError: mul received an invalid combination of arguments - got (torch.cuda.FloatTensor), but expected one of:

(int value)
didn’t match because some of the arguments have invalid types: (!torch.cuda.FloatTensor!)
(torch.cuda.ByteTensor other)
didn’t match because some of the arguments have invalid types: (!torch.cuda.FloatTensor!)