Solved by rasbt in post #2 
              
              
                Also not sure why you’d get the warning. What you are doing seems to be right. Maybe it’s just a  false positive warning, I dunno. What you could try is 
out = torch.tensor(x.clone().detach()[:, rand_columns, :], requires_grad=True)

instead of 
out = x.clone().detach()[:, rand_columns, :].requires_…