Skip to content

Commit 1316673

Browse files
committed
Do not tag argument proxy as DETACHED_AUTOGRAD_GRAPH
1 parent a82c4c7 commit 1316673

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎thunder/core/symbol.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,13 @@ def __call__(self, *args, **kwargs):
327327

328328
cd = get_compile_data()
329329
if cd is not None and not cd.is_grad_enabled:
330+
flat_args, _ = tree_flatten((args, kwargs))
331+
flat_arg_ids = {id(arg) for arg in flat_args}
330332
# If grad is disabled using `torch.no_grad` or `torch._C._set_grad_enabled(False)`,
331333
# tag the results with `DETACHED_AUTOGRAD_GRAPH` which makes this Symbol a constant for
332334
# vjp transform (applied later).
333335
def tag_tensorproxy_output_as_detached(proxy):
334-
if isinstance(proxy, TensorProxy):
336+
if isinstance(proxy, TensorProxy) and id(proxy) not in flat_arg_ids:
335337
proxy.tags.add(ProxyTag.DETACHED_AUTOGRAD_GRAPH)
336338

337339
return proxy

0 commit comments

Comments
 (0)