Hi,
The gradient for sqrt(0) is going to be +inf. So it is a fairly dangerous thing to have!
It might be better to compute the sqrt first and then set to 0 the values you want to zero out. That way, all the gradients will remain well defined.