Conversation
Collaborator
Author
|
Currently, the following does not work: import torch, thunder
torch.set_grad_enabled(False)
def fn(x):
with torch.enable_grad():
return x.sin()
x = torch.randn((), requires_grad=True, device="cuda")
assert fn(x).grad_fn is not None
assert thunder.jit(fn)(x).grad_fn is not None # AssertionError
assert thunder.dynamo.thunderfx(fn)(x).grad_fn is not None # AssertionErrorThis is because:
This maybe a similar issue to #2396 (comment). |
set_grad_enabled faithfully before connecting to autogradset_grad_enabled
Collaborator
Author
|
Let me close this PR as the purpose has somewhat changed. I'll reopen as a new PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2398. Thunder has support for
torch.set_grad_enabledcalls that come fromtorch.no_grad()context by managingcd.is_grad_enabledwithout actually callingtorch.set_grad_enabled. As in #2398, when Thunder's graph splitter splits the region,torch.set_grad_enabled(True/False)appears in each segment independently without its counterpart. We should actually call it, and it should be done before connecting the computation to Autograd so that it will populate thegrad_fnattribute appropriately.