Skip to content
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

Don't truncate leading 1s if they are unbacked #95141

Closed
wants to merge 3 commits into from

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented Feb 19, 2023

Stack from ghstack (oldest at bottom):

This prevents us from guarding on leading unbacked SymInts.

The previous attempt at #94521 I got the logic a bit wrong. My idea there was to avoid slicing when the values to be set have low enough dimensionality that they definitely aren't too long. To do this, I need to compute the difference between the data to be set, and the post-slice space for the values. But I incorrectly compared against the pre-slice space in the original PR. Another version of this PR which is wrong is to compare against variableIndices.size(); but remember that in advanced indexing with tensors/lists, each of the individual indices specify what coordinates to read out of each dimension! A third incorrect attempt tested variableIndices[0].dim(), which is only correct if you don't broadcast one of the later variable indices, and if there are enough variableIndices to cover all dims. This is all quite complicated, so I went for a simpler solution of checking if the leading dim had a hint before testing if it is not equal to one.

BTW, there is no test for this one stripping behavior. There is now a test for this, based off the real code that caused the problem.

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

If it's just right, broadcasting will do the right thing
automatically.

This helps with unbacked SymInts as I can avoid testing one
equality on the inside.

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

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Feb 19, 2023

🔗 Helpful Links

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

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

✅ No Failures

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

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

ezyang added a commit that referenced this pull request Feb 19, 2023
If it's just right, broadcasting will do the right thing
automatically.

This helps with unbacked SymInts as I can avoid testing one
equality on the inside.

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

ghstack-source-id: 905f6454a7897951ba156367c53ab515e71faf19
Pull Request resolved: #95141
If it's just right, broadcasting will do the right thing automatically.

This helps with unbacked SymInts as I can avoid testing one equality on the inside.

The previous attempt at #94521 I got the logic a bit wrong. I need to compute the difference between the data to be set, and the post-slice space for the values. But I incorrectly compared against the *pre-slice* space in the original PR. Another version of this PR which is wrong is to compare against variableIndices.size(); but remember that in advanced indexing with tensors/lists, each of the individual indices specify what coordinates to read out of each dimension; so to get the post-slice space you have to look at the dim of the advanced index itself! There is now a test for this.

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

[ghstack-poisoned]
@ezyang ezyang changed the title Reland "Only truncate leading 1s if the value is too big." Don't truncate leading 1s if they are unbacked Feb 19, 2023
ezyang added a commit that referenced this pull request Feb 19, 2023
If it's just right, broadcasting will do the right thing
automatically.

This helps with unbacked SymInts as I can avoid testing one
equality on the inside.

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

ghstack-source-id: abc461993881c6398e318b3e0dd3b858a6d22e44
Pull Request resolved: #95141
@ezyang ezyang requested a review from ngimel February 19, 2023 20:45
@ezyang ezyang added release notes: composability release notes category topic: not user facing topic category labels Feb 20, 2023
@ezyang ezyang added the ciflow/trunk Trigger trunk jobs on your pull request label Feb 20, 2023
This prevents us from guarding on leading unbacked SymInts.

The previous attempt at #94521 I got the logic a bit wrong. My idea there was to avoid slicing when the values to be set have low enough dimensionality that they definitely aren't too long. To do this, I need to compute the difference between the data to be set, and the post-slice space for the values. But I incorrectly compared against the *pre-slice* space in the original PR. Another version of this PR which is wrong is to compare against variableIndices.size(); but remember that in advanced indexing with tensors/lists, each of the individual indices specify what coordinates to read out of each dimension! A third incorrect attempt tested `variableIndices[0].dim()`, which is only correct if you don't broadcast one of the later variable indices, and if there are enough variableIndices to cover all dims. This is all quite complicated, so I went for a simpler solution of checking if the leading dim had a hint before testing if it is not equal to one.

BTW, there is no test for this one stripping behavior. There is now a test for this, based off the real code that caused the problem.

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

[ghstack-poisoned]
@ezyang
Copy link
Contributor Author

ezyang commented Feb 21, 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

pruthvistony added a commit to ROCm/pytorch that referenced this pull request May 2, 2023
@facebook-github-bot facebook-github-bot deleted the gh/ezyang/1829/head branch June 8, 2023 16:50
jhavukainen pushed a commit to kulinseth/pytorch that referenced this pull request Mar 15, 2024
This prevents us from guarding on leading unbacked SymInts.

The previous attempt at pytorch#94521 I got the logic a bit wrong. My idea there was to avoid slicing when the values to be set have low enough dimensionality that they definitely aren't too long. To do this, I need to compute the difference between the data to be set, and the post-slice space for the values. But I incorrectly compared against the *pre-slice* space in the original PR. Another version of this PR which is wrong is to compare against variableIndices.size(); but remember that in advanced indexing with tensors/lists, each of the individual indices specify what coordinates to read out of each dimension! A third incorrect attempt tested `variableIndices[0].dim()`, which is only correct if you don't broadcast one of the later variable indices, and if there are enough variableIndices to cover all dims. This is all quite complicated, so I went for a simpler solution of checking if the leading dim had a hint before testing if it is not equal to one.

BTW, there is no test for this one stripping behavior. There is now a test for this, based off the real code that caused the problem.

Signed-off-by: Edward Z. Yang <ezyangmeta.com>
Pull Request resolved: pytorch#95141
Approved by: https://github.com/ngimel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: composability release notes category topic: not user facing topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants