-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Make unspecified ints to range over negative and positive. #104658
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/104658
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 7d58430: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` ghstack-source-id: 1d5229b Pull Request resolved: #104658
…o range over negative and positive." Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` cc voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx ipiszy chenyang78 [ghstack-poisoned]
Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` ghstack-source-id: 683ad02 Pull Request resolved: #104658
source: Source, | ||
dynamic_dim: DimDynamic = DimDynamic.DUCK, | ||
constraint_dim: DimConstraint = None, # NB: includes None | ||
positive: Optional[bool] = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really Optional[bool]? What does None mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you can set this to False to mean "never positive", but we don't actually have any concrete use case for this, AFAIK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. I did this so that I wouldn't need to positive = positive if positive else None
when I'm actually creating the symbol. Maybe I could just leave a comment when I call it with positive=None
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comment is OK too, just make it hard for people to accidentally say positive=False
when they meant positive=None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. Maybe we could just throw in an assert there like:
def create_symbol(
...
positive: Optional[bool] = True
):
assert positive != False, (
"Unspecified integers range over negative and positive numbers. "
"Setting positive=False means strictly negative. "
"Use positive=None instead."
)
Let me know what you think.
Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 kadeng muchulee8 anijain2305 [ghstack-poisoned]
Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` ghstack-source-id: 533f70d Pull Request resolved: #104658
Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 kadeng muchulee8 anijain2305 [ghstack-poisoned]
Currently, negative unspecified ints get specialized. This PR creates symbolic values for unspecified ints (including negative ones). For example, with this PR, the following code only compiles once, instead of 3 times: ```python def foo(x, y): return torch.fill(torch.zeros(x.shape), y) foo(10) foo(-5) foo(-3) ``` ghstack-source-id: 8965e07 Pull Request resolved: #104658
By the way, if we notice that this is making codegen worse (because we are unable to assume that something is positive), we could proactively make the ints positive (guarding appropriately) pending seeing a negative value. It didn't seem like it's necessary here but this is something we can put in our back pocket. |
Right. Do you mean: create symbols for positive and negative "on demand"? |
Essentially, we could proactively assume that a symbol is positive even if we have no evidence for it, and then make it range over negative/positive if we saw a counterexample. Anyway, not for this PR. |
Yep do it |
@pytorchbot merge |
Merge startedYour 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 |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / win-vs2019-cpu-py3 / test (default, 2, 3, windows.4xlarge.nonephemeral) Details for Dev Infra teamRaised by workflow job |
@pytorchbot merge |
Merge startedYour 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 |
Stack from ghstack (oldest at bottom):
Currently, negative unspecified ints get specialized. This PR creates symbolic values for
unspecified ints (including negative ones).
For example, with this PR, the following code only compiles once, instead of 3 times:
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @kadeng @muchulee8 @anijain2305