During training, at some point I need my tensors to be padded to the same size.
Later on (still during training), I want to remove the padding by slicing and keeping only a certain part of the tensors.
I appears to me that this causes a cuda memory leak, since the subgraph of the removed part is not involved in the loss computation/backprop then and thus it is never cleaned up. Is my understanding correct about this?
And if so, how can I “trim” a tensor during training without running into this memory leak?