Hi! I’m running a memory-intensive code and I want to save memory as much as possible. If I have multiple convolutional layers:
x = self.conv1(x)
x = self.conv2(x)
x = self.conv3(x)
…
the fact that I’m using the same variable name “x” doesn’t help here, because they’re all kept in PyTorch’s graph. So the block of code above is no different that this block?:
As far as I understand, all the three methods you describe use essentially the same amount of memory. Not using different variable names may save the memory used for storing those variable names, not more. And this is an insignificant amount, so you should use as many variable names as will make the code easy to read.
One way to reduce memory requirements is to go through the input in small batches, and to use PyTorch DataLoader to load the data.