Indeed, this works well with a Tensor but Variable hasn’t got the nonzero method.
To do that, you need to get the tensor with mask.data, then apply the nonzero method, and then convert back to a Variable since it expects a Variable as input.
Also, it’s good to note that when you get the error below, it is often due to the fact that you input a Tensor in places where you should input a Variable:
{RuntimeError} save_for_backward can only save input or output tensors, but argument 0 doesn't satisfy this condition,

So you could do:
input.index_select(dim, Variable(mask.data.nonzero()))

Tell me if it’s ok ! (Though I didn’t test it, I guess it should be fine)