Closed ltebean closed 5 months ago
@ltebean it's not going to cause any problems as used the demo, it's doing an inplace div of a tensor that was just returned by the model, it saves an allocation, the tensor is not used in any other scope in this situation.
In the demo, this line of code will cause memory leak
reason:
The reason behind this is related to the behavior of the PyTorch library. In PyTorch, operations like /= and *= perform in-place operations, meaning they modify the original tensor. On the other hand, operations like = create a new tensor and assign it to the variable.
When you use /= and *= for normalizing the image features, you are modifying the original tensor in place. This can sometimes lead to unexpected memory management issues, especially when dealing with large tensors or when the same code is executed multiple times.
suggestion: update the code to