ptrblck:

I haven’t seen your error message yet, but it seems it related to an in-place modification, because you are re-assigning the values of W in this line:




Is that an in-place modification though?

X=torch.randn((100,3))
Y=torch.randn((100))

w1=torch.tensor(0.1, requires_grad=True)
w2=torch.tensor(0.1, requires_grad=True)
w3=torch.tensor(0.1, requires_grad=True)

W=torch.tensor([0.1, 0.1, 0.1])
print(id(W[0]),id(W[1]),id(W[2]))
W[0]=w1 * w2; W[1]=w2 * w3; W[2]=w3 * w1
print(id(W[0]),id(W[1]),id(W[2]))

4778466184 4778466184 4778466184
4778467120 4778467120 4778467120

The addresses are different. In fact, I’m not even sure why each of the elements of the tensor, W, don’t have unique addresses, at least prior to being assigned values based on the w’s. Once tensor elements are assigned values, particularly values based on tensors with requires_grad=True, it seems that they all are given the same address. Is that correct?