I have created a custom nn.Module(). In the initializer I want to initialize a leaf variable with a tensor. However, when optimizing, I get the following error: ValueError: can't optimize a non-leaf Variable.
My code looks like follows:
x = torch.zeros(<some format>).cuda()
x[:, :, :, int(np.floor(self.number_of_params/2))] = 1
self.y = Variable(x, requires_grad=True)

I also tried to use x.clone() or creating a Variable out of x and using x.data when creating y.
Why is y not a leaf variable?