No, it’s the correct way to detach the tensor and only store the Python float.
However, removing all additional code and only executing the training loop could further narrow down the issue and either point towards a currently unspotted error in the code or an internal bug, which might cause the memory increase.