Hi Hoang!



 Hoang_Phan:

when I tried the above implementation with A=B, it returned a tensor containing all nans


Please note that both the implementation I posted above, as well as,
by default, pytorch’s kl_div(), expect the input (A in the example
above) to be log-probabilities and the target (B) to be probabilities.
If you pass in a probability that is zero or negative, you will get a nan.
If this doesn’t clear up your issue, please post a short, complete, runnable
example that reproduces the issue you see.
Best.
K. Frank