Thank you for sharing your solution. However, this code snippet does not work for me. The error message shows that
TypeError: save_for_backward can only save variables, but argument 0 is of type float

I tried to change scale (which is lambd in your code) into a autograd.Variable, but the error remained.  At the same time, it does not quite make sense to make a constant autograd.Variable.
However, converting the scale (aka. lambd) into a class variable got my code up and running.  Here is my solution
class GradientReverse(torch.autograd.Function):
    scale = 1.0
    @staticmethod
    def forward(ctx, x):
        return x.view_as(x)

    @staticmethod
    def backward(ctx, grad_output):
        return GradientReverse.scale * grad_output.neg()
    
def grad_reverse(x, scale=1.0):
    GradientReverse.scale = scale
    return GradientReverse.apply(x)

I think this could also work for data parallel, but I have not tested yet (maybe some other day this week).