Just for some instructions to name a tensor please

Hi,

Is it good or bad or free to reuse names of tensors. Provided some part of my program is like this:

    def forward(self, x):
         x = self.conv(x)
         x = self.bn(x)
         x = self.relu(x)
        return x

Is this good for memory usage and speed compared with the following method:

    def forward(self, x):
         x1 = self.conv(x)
         x2 = self.bn(x1)
         x3 = self.relu(x2)
        return x3

Is there actually a difference ?

Hi,

It will make a small difference in memory in case you don’t use gradients. If you use gradients, most of these tensors are kept around for the backward pass anyway.
Speed wise, these should not be any difference.

Ah, I see. Thanks a great deal