I think that should work.
Also, I just realized that Function should be defined in a different way in the newer versions of pytorch:

class GradReverse(Function):
    @staticmethod
    def forward(ctx, x):
        return x.view_as(x)

    @staticmethod
    def backward(ctx, grad_output):
        return grad_output.neg()

def grad_reverse(x):
    return GradReverse.apply(x)

The return x.view_as(x) seems to be necessary, because otherwise backward is not being called, I guess that as optimization Autograd checks if the Function modified the tensor to see if backward should be called.