NaN could really happen at anywhere, mainly:

division by 0
something involving the annoying log/exp calculation, like log probability, I have just located a Nan problem myself this morning. Eg:

   a=Normal(1, 1e-23)
   a.log_prob(a.sample()) -> NaN because sigma is too small.