In Docs, there are torch.add(input, value, out=None) and torch.add(input, value, others, out=None).
I expect ‘b’ and ‘c’ in the following code should be the same in value but not:
import torch
lr = 1e-2
torch.manual_seed(666)
a = torch.randn(3,3)
a.grad = torch.randn(3,3)
b = torch.add(a, -lr, a.grad)
c = torch.add(a, -lr*a.grad)
print(torch.abs(b-c).sum())
So, can you please help me on why they are different?
Yes, the final value is 1.8626e-9. But it should be a strict 0.0 . There may be precision problem in float computing but the result should be the same.
So, you mean these two operations are implemented differently in C codes and that causes different results? Would you please give me a little more information about the differences?