KEMBAR78
Improve reflection_pad2d lowering for dynamic shapes by ezyang · Pull Request #110988 · pytorch/pytorch · GitHub
Skip to content

Conversation

@ezyang
Copy link
Contributor

@ezyang ezyang commented Oct 10, 2023

Fixes #110696

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 10, 2023

🔗 Helpful Links

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

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

✅ You can merge normally! (2 Unrelated Failures)

As of commit c4aa9cb with merge base 261cae7 (image):

UNSTABLE - The following jobs failed but were likely due to flakiness present on trunk and has been marked as unstable:

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

ezyang added a commit that referenced this pull request Oct 10, 2023
Fixes #110696

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: 0135b37
Pull Request resolved: #110988
@ezyang
Copy link
Contributor Author

ezyang commented Oct 10, 2023

Still needs tests, but a review will still be helpful

def constant(value: Union[int, float, bool], dtype: torch.dtype) -> TypedExpr:
if is_boolean_dtype(dtype):
if isinstance(value, sympy.Expr):
expr = value
Copy link
Collaborator

Choose a reason for hiding this comment

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

ops.constant shouldn't be called with sympy.Expr. Instead it should be ops.index_expr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it turns out that it's easy enough to change the ops.constant call in the lowering to ops.index_expr, but now I am wondering, is there really any material difference between these two calls? Like, it's not like you're going to get worse code if you call index_expr with a constant, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally I think they should be similar but in practice they are materially different. ops.constant will respect the dtype argument and generate code like tl.full([1, 1], 256, tl.int32) whereas ops.index_expr goes through the sympy expression printer which gives an integer literal 256 which ignores the specified dtype.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in any case I fixed it, plz review lol

@albanD albanD removed their request for review October 11, 2023 17:15
Fixes #110696

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Oct 12, 2023
Fixes #110696

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: a20ba24
Pull Request resolved: #110988
@ezyang ezyang requested a review from peterbell10 October 12, 2023 19:31
@ezyang ezyang added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 12, 2023
@ezyang ezyang requested review from eellison, jansel and lezcano October 12, 2023 19:31
Fixes #110696

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Oct 12, 2023
Fixes #110696

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: 69643a9
Pull Request resolved: #110988
dtype=x.get_dtype(),
inner_fn=fn,
ranges=[*batch, sympy.Integer(h + top + bot), sympy.Integer(w + left + right)],
ranges=[*batch, sympy.sympify(h + top + bot), sympy.sympify(w + left + right)],
Copy link
Contributor

@eellison eellison Oct 12, 2023

Choose a reason for hiding this comment

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

why do we need sympy.sympify here ? h or w should either be integers or symbols which would work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if h, top and bot happen to be all int, we won't return a sympy.Integer, but I noticed that in inductor it is sometimes load bearing to return a sympy expression, not a plain int

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be fine to return an int here

@ezyang
Copy link
Contributor Author

ezyang commented Oct 13, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
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

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.

6 participants