From 589a80c94197dcd16b4b955e36884c777c97104f Mon Sep 17 00:00:00 2001 From: Pier Fiedorowicz Date: Thu, 28 May 2026 10:47:48 -0700 Subject: [PATCH] Fixes a reference counting leak by breaking circular references Co-authored-by: Josh Williams --- distconv/distconv.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/distconv/distconv.py b/distconv/distconv.py index 7e9ed6b..8126d47 100644 --- a/distconv/distconv.py +++ b/distconv/distconv.py @@ -842,7 +842,9 @@ class _ToTensor(Function): @staticmethod def forward(ctx, dc_tensor: DCTensor): ctx.parallel_strategy = dc_tensor._parallel_strategy - return dc_tensor._tensor + # Need to alias the tensor to prevent the returned inner tensor from + # creating circular references when its grad_fn gets modified + return torch.Tensor(dc_tensor._tensor) @staticmethod def backward(ctx, grad: torch.Tensor):