Solved by tom in post #2 
              
              
                The mistake is to compare floating point variables with == instead of torch.allclose. 
What you are seeing is that floating point numbers are not as nice as actual real numbers. For example, addition (of multiple values) does not commute due to numerical precision effects: Try print(1e20 + 1 - 1e20).…