Solved by Nikronic in post #2 
              
              
                Hi, 
The logic you using is correct, actually the data types are causing this differences. 
For instance, if you use your own code in functions: 
count_p = (b == 1.0).sum() + 1
count_n = (b == 0.0).sum() + 1                
loss2 = torch.mean(-((b * a.log()) * (1 / count_p)) - (((1 - b) * (1 - a).lo…