Skip to content

Conversation

@voznesenskym
Copy link
Collaborator

@voznesenskym voznesenskym commented Dec 3, 2022

Stack from ghstack (oldest at bottom):

This adds a pair of equivalent tests, both of which invoke aot_autograd with the same inputs, more or less. One through dynamo, one directly. Where the direct call fails, dynamo passes due to guards. This pair of tests protects that behavior and sets us up for future refactors.

cc @mlazos @soumith @yanboliang @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @chunyuan-w @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @desertfire

wip

wip

WIP

Useful tests

lint

Extend test to cover failure reason

fix

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Dec 3, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/90130

Note: Links to docs will display an error until the docs builds have been completed.

❌ 5 Failures

As of commit 88173a0:

The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Dec 3, 2022
voznesenskym added a commit that referenced this pull request Dec 3, 2022
wip

wip

WIP

Useful tests

lint

Extend test to cover failure reason

fix

ghstack-source-id: efb1ffc
Pull Request resolved: #90130
@voznesenskym voznesenskym changed the title wip Add two useful tests to aid in debugging dynamo + aot_autograd dedup Dec 3, 2022
)

@patch('functorch._src.aot_autograd.AOT_COUNTER', new_callable=itertools.count)
@patch("functorch._src.config.debug_assert", True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad merge?

…grad dedup"


This adds a pair of equivalent tests, both of which invoke aot_autograd with the same inputs, more or less. One through dynamo, one directly. Where the direct call fails, dynamo passes due to guards. This pair of tests protects that behavior and sets us up for future refactors. 

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
voznesenskym added a commit that referenced this pull request Dec 4, 2022
wip

wip

WIP

Useful tests

lint

Extend test to cover failure reason

fix

ghstack-source-id: 87bf422
Pull Request resolved: #90130

better rebase
Comment on lines 307 to 312
for out in pytree.tree_flatten(outs)[0]:
if isinstance(out, torch.Tensor) and out.requires_grad:
out.sum().backward(retain_graph=True)
grads = [inp.grad for inp in pytree.tree_flatten(inps)[0]]
for inp in pytree.tree_flatten(inps)[0]:
inp.grad = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simpler way to do this

Suggested change
for out in pytree.tree_flatten(outs)[0]:
if isinstance(out, torch.Tensor) and out.requires_grad:
out.sum().backward(retain_graph=True)
grads = [inp.grad for inp in pytree.tree_flatten(inps)[0]]
for inp in pytree.tree_flatten(inps)[0]:
inp.grad = None
flat_outs = pytree.tree_flatten_only(torch.Tensor, outs)[0]
flat_inps = pytree.tree_flatten_only(torch.Tensor, inps)[0]
grads = torch.autograd.grad((o for o in flat_outs if o.requires_grad), flat_inps)
return outs, grads

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, don't we already have this helper function defined, why do we need another copy?


x = torch.randn(3, 3, requires_grad=True)
y = torch.randn(3, 3, requires_grad=True)
z = torch.randn(3, 3, requires_grad=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it would have been better to have more descriptive name for y and z; e.g., y_true and y_false or y_grad and y_nograd, to make it more clear which ones is requires grad True and which one is False.

@ezyang
Copy link
Contributor

ezyang commented Dec 5, 2022

I mentioned this in earlier review; these tests are straight up copy pastes of already existing tests in the test suite. Lines of code in the test suite are a liability, not an asset, since the more lines of test code you have, the harder it is to refactor APIs (since you now have to update all the test code.) Please make more effort to deduplicate these tests.

@voznesenskym
Copy link
Collaborator Author

I mentioned this in earlier review; these tests are straight up copy pastes of already existing tests in the test suite.

One is, and one is different enough and needs some dynamo test imports that we'd probably need to keep it. But for the aot_dispatch test, 100% agreed.

Lines of code in the test suite are a liability, not an asset, since the more lines of test code you have, the harder it is to refactor APIs (since you now have to update all the test code.) Please make more effort to deduplicate these tests.

Of course :) I agree! Higher level - does the reasoning in the tests for why we have these two seem sound? I was hoping more to get a take from you on that.

@ezyang
Copy link
Contributor

ezyang commented Dec 5, 2022

The test itself is fine. I'm imagining a new type of test which is done in test/dynamo, but the model in question is simple enough that you can also run it through directly with aot_module_simplified. Or maybe something like OpInfo but ProgramInfo, where we have sample programs that can be run through various levels of the stack.

…grad dedup"


This adds a pair of equivalent tests, both of which invoke aot_autograd with the same inputs, more or less. One through dynamo, one directly. Where the direct call fails, dynamo passes due to guards. This pair of tests protects that behavior and sets us up for future refactors. 

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
…grad dedup"


This adds a pair of equivalent tests, both of which invoke aot_autograd with the same inputs, more or less. One through dynamo, one directly. Where the direct call fails, dynamo passes due to guards. This pair of tests protects that behavior and sets us up for future refactors. 

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
voznesenskym added a commit that referenced this pull request Dec 6, 2022
wip

wip

WIP

Useful tests

lint

Extend test to cover failure reason

fix

ghstack-source-id: c71fd56
Pull Request resolved: #90130

better rebase

Fix test logic to be less duplicated

More test
@voznesenskym voznesenskym requested a review from a team as a code owner December 6, 2022 02:34
@voznesenskym voznesenskym changed the title Add two useful tests to aid in debugging dynamo + aot_autograd dedup Add tests to aid in debugging dynamo + aot_autograd dedup Dec 6, 2022
voznesenskym added a commit that referenced this pull request Dec 7, 2022
wip

wip

WIP

Useful tests

lint

Extend test to cover failure reason

fix

ghstack-source-id: c71fd56
Pull Request resolved: #90130

better rebase

Fix test logic to be less duplicated

More test

Fix test to raise

Test comment
This adds a pair of equivalent tests, both of which invoke aot_autograd with the same inputs, more or less. One through dynamo, one directly. Where the direct call fails, dynamo passes due to guards. This pair of tests protects that behavior and sets us up for future refactors. 

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
@ezyang
Copy link
Contributor

ezyang commented Dec 7, 2022

i'm unsubsubscribing, rerequest review when ready

This adds a pair of equivalent tests, both of which invoke aot_autograd with the same inputs, more or less. One through dynamo, one directly. Where the direct call fails, dynamo passes due to guards. This pair of tests protects that behavior and sets us up for future refactors. 

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2023

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions bot added the Stale label Feb 6, 2023
@github-actions github-actions bot closed this Mar 8, 2023
@facebook-github-bot facebook-github-bot deleted the gh/voznesenskym/31/head branch June 8, 2023 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants