Added CHECK if loss is NaN

As mentioned in #1349 If Loss is Nan it doesn't make sense to keep training.