Torch.cat([a,b]) won't update with a or b

Hi there,

When c = torch.cat([a, b]), I expect c.data will change with a.data, but it doesn’t.
The following codes show the idea.

import torch
from torch.autograd import Variable
a, b = Variable(torch.ones(1)), Variable(torch.ones(1))
c = torch.cat([a, b])
a.data = torch.ones(1)*2
print(c.data)

c.data = [1,1], not [2,1].
I wonder if this is a feature or will it be fixed?

Thanks for your help.

c = torch.cat([a, b]) calculates the value of c every time you run it. This is a feature.

As a general rule, you shouldn’t modify a.data because any change to a.data is not stored in the computation graph and won’t be differentiated when backpropagating.

Thanks for your clarification :slight_smile: