It worked! Thanks
class SmoothStep(torch.autograd.Function):
    @staticmethod
    def forward(ctx, x):
        ctx.save_for_backward(x)
        y = torch.zeros_like(x)
        m = (x > 0.0)
        y[m] = (-1/x[m]).exp()
        return y

    @staticmethod
    def backward(ctx, dy):
        x, = ctx.saved_tensors
        dx = torch.zeros_like(x)
        m = (x > 0.0)
        xm = x[m]
        dx[m] = (-1/xm).exp() / xm.pow(2)
        return dx * dy
    
f = SmoothStep.apply
x = torch.linspace(-1, 1, 1000, requires_grad=True)

y0 = f(x)
y1, = torch.autograd.grad(y0.sum(), x, create_graph=True)
y2, = torch.autograd.grad(y1.sum(), x, create_graph=True)
y3, = torch.autograd.grad(y2.sum(), x, create_graph=True)

assert torch.isfinite(y0).all() and torch.isfinite(y1).all() and torch.isfinite(y2).all() and torch.isfinite(y3).all()