I am curious why the following code will return False. In torch, slice seems to affect the linear layer output. Thanks for your attention~
torch.manual_seed(1234)
a = torch.randn((50, 4096)).float()
idx = [0, 2]
b = a[idx,:]
w1 = torch.nn.Linear(4096, 4096, bias=False)
w2 = torch.nn.Linear(4096, 4096, bias=False)
w3 = torch.nn.Linear(4096, 4096, bias=False)
act = torch.nn.SiLU()
out_a = w3(act(w1(a)) * w2(a))
out_b = w3(act(w1(b)) * w2(b))
print(torch.equal(out_a[idx,:], out_b))
In the above test, the outputs of out_a[idx,:] and out_b are very closed but different, like 0.0507067293 and 0.0507068783.
New contributor
jesseL1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.