albanD:

taking


Thanks for your answer! This is the problem. But the tricky point is when  output[0] and y[0] is not zero number ,then the loss is valid number but if some of the output (for example, output[4]) has zero, then the whole loss will be inf, not only the loss[4] is inf .