Based on the output message I would assume targets * sigmoid_x.log() creates the NaN values.
In particular, could you check the values of sigmoid_x.log()?
If you are passing zeros in sigmoid_x, the log() operation will result in an -inf output.