Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird interaction with p.grad in dynamo #117184

Open
janeyx99 opened this issue Jan 10, 2024 · 1 comment
Open

Weird interaction with p.grad in dynamo #117184

janeyx99 opened this issue Jan 10, 2024 · 1 comment
Labels
dynamo-must-fix These bugs affect TorchDynamo reliability. module: dynamo oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@janeyx99
Copy link
Contributor

janeyx99 commented Jan 10, 2024

馃悰 Describe the bug

I encountered this while trying to enable dynamo on unit tests. Not mentioning requires_grad and then setting the grad of a parameter within a compiled region when the parameter lives outside of that region causes internal dynamo to think that the grad is None.

In my repro below, to_sparse() could be replaced with any function (like .add will produce the same error).

Error logs

InternalTorchDynamoError: 'NoneType' object has no attribute 'to_sparse'

from user code:
   File "<ipython-input-4-48c0ef0ff017>", line 6, in f
    p.grad = p.grad.to_sparse()

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True

Minified repro

import torch
param = torch.rand(2, 3, dtype=torch.float32, device='cuda')  # moving this inside f would work! 

def f(p):
    p.grad = torch.rand_like(p)
    p.grad = p.grad.to_sparse()  # why does dynamo think p.grad at this moment is empty?

compiled_f = torch._dynamo.optimize("eager")(f)
compiled_f(param)

Versions

on main

cc @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @zou3519 @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng

@voznesenskym
Copy link
Collaborator

I think I saw this recently, and maybe have a fix, let me go look.

@bdhirsh bdhirsh added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: dynamo labels Jan 12, 2024
@anijain2305 anijain2305 added the dynamo-must-fix These bugs affect TorchDynamo reliability. label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamo-must-fix These bugs affect TorchDynamo reliability. module: dynamo oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

4 participants