Skip to content

[Inductor] Fix for WrapperCodeGen.statically_known_int_or_none - #121808

Closed
kadeng wants to merge 9 commits into
gh/kadeng/45/basefrom
gh/kadeng/45/head
Closed

kadeng wants to merge 9 commits into
gh/kadeng/45/basefrom
gh/kadeng/45/head

Conversation

@kadeng

@kadeng kadeng commented Mar 13, 2024 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @muchulee8 @aakhundov @ColinPeppler @amjames @desertfire @chauhang

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Mar 13, 2024 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit c8afc4c with merge base 6b5259e (image):
💚 Looks good so far! There are no failures yet. 💚

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

kadeng added a commit that referenced this pull request Mar 13, 2024
There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

ghstack-source-id: ea817c0
Pull Request resolved: #121808
@kadeng
kadeng requested review from aakhundov, jansel and lezcano March 13, 2024 13:34
@lezcano

lezcano commented Mar 13, 2024

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 13, 2024
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@jansel jansel left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a test?

@tonycwliu

Copy link
Copy Markdown

Good found! Way to go!

@kadeng

kadeng commented Mar 14, 2024

Copy link
Copy Markdown
Contributor Author

Add a test?

Makes sense, I will add one. At the moment, this change is blocked due to a CI failure. On first sight it looks like this change triggered something (or CI is broken)

@lezcano

lezcano commented Mar 15, 2024

Copy link
Copy Markdown
Collaborator

the CI failure was just the CI being flaky, it looks like

…none"

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
kadeng added a commit that referenced this pull request Mar 19, 2024
There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI
Additional test in test_torchinductor_dynamic_shapes

NOTE: The test might have uncovered another preexisting issue. This can be triggered by uncommenting a single line in the unit test.

ghstack-source-id: 184c815
Pull Request resolved: #121808
…none"

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
…none"

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
kadeng added a commit that referenced this pull request Mar 19, 2024
There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI
Additional test in test_torchinductor_dynamic_shapes

NOTE: The test might have uncovered another preexisting issue. This can be triggered by uncommenting a single line in the unit test.

ghstack-source-id: 184c815
Pull Request resolved: #121808

@lezcano lezcano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test is quite complex. Isn't it possible to test this function similar to what we do at

shape_env = _shape_env_from_inputs(example_inputs)
fake_mode = detect_fake_mode(example_inputs)
if not fake_mode:
fake_mode = torch._subclasses.FakeTensorMode(allow_non_fake_inputs=True)
FakeTensorProp(gm, mode=fake_mode).propagate(*example_inputs)
else:
FakeTensorProp(gm, mode=fake_mode).propagate_dont_convert_inputs(
*example_inputs
)
with V.set_fake_mode(fake_mode):
graph = GraphLowering(
gm,
shape_env=shape_env,
num_static_inputs=0,
)
with V.set_graph_handler(graph), V.set_debug_handler(DebugContext()):
graph.run(*example_inputs)

@kadeng

kadeng commented Mar 20, 2024 •

Copy link
Copy Markdown
Contributor Author

This test is quite complex. Isn't it possible to test this function similar to what we do at

yes, that looks right and will likely execute much faster.

I arrived at the test you see here after writing it in different ways - also looking at how tests were set up in test_torchinductor.py using the TritonCodeGenTests.NoOpCompilerBackend - but I was often hitting the ConstraintViolationError I mentioned above when constraining it to a static int in one way or another.

So, to exclude the possibility that I was setting up the shape env in the wrong way for testing, I used the one that is actually created by the full logic of torch.compile with inductor backend.

torch._dynamo.reset()

_x = torch.randn([5, 3, 3])
torch._dynamo.mark_dynamic(_x, 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just use maybe_mark_dynamic here.

return x.cos()
if x.shape[0] < 5:
return x * 2
# x.shape[0] == 5 at this point

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Funnily enough, this should also error out when using mark_dynamic. Mind filing an issue? cc @ezyang

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Filed #122307

…none"

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
@kadeng

kadeng commented Mar 20, 2024

Copy link
Copy Markdown
Contributor Author

This test is quite complex. Isn't it possible to test this function similar to what we do at

Tried that ( see https://gist.github.com/kadeng/2544c6add99c8b55d9000ffe04e69974 ) but it didn't really work. The test variant I originally wrote, with maybe_mark_dynamic instead of mark_dynamic works nicely now, though. I'd leave it at that.

…none"

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
kadeng added a commit that referenced this pull request Mar 20, 2024
There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI
Additional test in test_torchinductor_dynamic_shapes

NOTE: The test might have uncovered another preexisting issue. This can be triggered by uncommenting a single line in the unit test.

ghstack-source-id: 1d97ac8
Pull Request resolved: #121808
…none"

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
…none"

There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
kadeng added a commit that referenced this pull request Mar 20, 2024
There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI
Additional test in test_torchinductor_dynamic_shapes

NOTE: The test might have uncovered another preexisting issue. This can be triggered by uncommenting a single line in the unit test.

ghstack-source-id: 7aaaa17
Pull Request resolved: #121808

@lezcano lezcano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

kadeng added a commit that referenced this pull request Mar 21, 2024
There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI
Additional test in test_torchinductor_dynamic_shapes

NOTE: The test might have uncovered another preexisting issue. This can be triggered by uncommenting a single line in the unit test.

ghstack-source-id: 07ebf1e
Pull Request resolved: #121808
@lezcano

lezcano commented Mar 21, 2024

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
github-actions Bot deleted the gh/kadeng/45/head branch April 21, 2024 01:54
pytorch-bot Bot pushed a commit that referenced this pull request Apr 22, 2024
There's obviously a small typo in WrapperCodeGen.statically_known_int_or_none,
where the return value of a call to V.graph._shape_env._maybe_evaluate_static
is being discarded.

This fix changes that to work how it was likely intended to.

Test Plan:
CI

Pull Request resolved: #121808
Approved by: https://github.com/lezcano, https://github.com/jansel, https://github.com/aakhundov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants