Skip to content

Conversation

ysiraichi
Copy link
Collaborator

@ysiraichi ysiraichi commented Jul 5, 2023

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:

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

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]
@pytorch-bot
Copy link

pytorch-bot bot commented Jul 5, 2023

🔗 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 Failures

As of commit 7d58430:
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot bot added the release notes: fx release notes category label Jul 5, 2023
ysiraichi added a commit that referenced this pull request Jul 5, 2023
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]
ysiraichi added a commit that referenced this pull request Jul 7, 2023
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
@ysiraichi ysiraichi requested review from ezyang and jansel July 8, 2023 13:19
source: Source,
dynamic_dim: DimDynamic = DimDynamic.DUCK,
constraint_dim: DimConstraint = None, # NB: includes None
positive: Optional[bool] = True,
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Collaborator Author

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?

Copy link
Contributor

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

Copy link
Collaborator Author

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]
ysiraichi added a commit that referenced this pull request Jul 10, 2023
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]
ysiraichi added a commit that referenced this pull request Jul 10, 2023
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
@ezyang
Copy link
Contributor

ezyang commented Jul 10, 2023

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.

@ysiraichi
Copy link
Collaborator Author

Right. Do you mean: create symbols for positive and negative "on demand"?

@ezyang
Copy link
Contributor

ezyang commented Jul 10, 2023

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.

@ysiraichi
Copy link
Collaborator Author

@ezyang @jansel I renamed create_symint_and_symbol --> create_unspecified_symint_and_symbol, so as to avoid incorrect use. I'm pretty sure I have changed the its only call site. Is it ok to suppress the BC-lint step?

@ezyang
Copy link
Contributor

ezyang commented Jul 11, 2023

Yep do it

@ysiraichi ysiraichi added the suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter) label Jul 11, 2023
@ysiraichi
Copy link
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 11, 2023
@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

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 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 team Raised by workflow job

@ysiraichi
Copy link
Collaborator Author

@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

@facebook-github-bot facebook-github-bot deleted the gh/ysiraichi/60/head branch July 15, 2023 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo module: inductor open source release notes: fx release notes category suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants