I think the issue is caused by the wrong usage of directly string the tensors in ctx and if I’m not mistaken, we’ve seen a few similar issues in the past posted here.
Use ctx->save_for_backward and the memory leak should be gone.