Hi,
If you save the Tensor like self.foo = torch.zeros(100). It will be registered as a buffer and will be moved the same way parameters of the module are. You can then resize_(new_size).zero_() it at the beginning of each forward pass. Note that the resize is a no-op if the Tensor is already big enough BUT if you reduce the size, the unused memory won’t be free and will remain there until you delete the tensor (or resize it to a bigger size again).