Don't do autodiff when ReLU it's not differentiable

Hi everyone,

Do you know if it’s possible to train a model with the condition to not do the back propagation when it’s not differentiable ? For exemple, I want to throw away the input if at some point I do ReLU’(0).

class MyReLU(torch.autograd.Function):

def forward(ctx, input):
    if input == 0:
        return input.clamp(min=0)
        return input.clamp(min=0)

def backward(ctx, grad_output):
    input, = ctx.saved_tensors 
    grad_input = grad_output.clone()
    grad_input[input < 0] = 0
    return grad_input  

Do you think it’s possible to do it ?