Skip to content

Commit 58bd4c4

Browse files
committed
Treat set_grad_enabled faithfully before connecting to autograd
1 parent 75d5e31 commit 58bd4c4

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

thunder/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,9 @@ def fn_(*args, **kwargs) -> Any:
865865
cache_entry, inps, pro_to_epi = get_computation_and_inputs(*args, **kwargs)
866866

867867
result = cache_entry.computation_fn(*inps)
868+
# We must do this before connecting to autograd so that
869+
# grad_fn attribute will be set on the outputs accordingly
870+
pytorch.set_grad_enabled(cd.is_grad_enabled)
868871
result = maybe_connect_to_autograd(cache_entry, result)
869872
result = call_epilogue(cache_entry, result, pro_to_epi)
870873

0 commit comments

Comments
 (0)