Only truncate leading 1s if the value is too big.#94521
Closed
ezyang wants to merge 3 commits intogh/ezyang/1805/basefrom
Closed
Only truncate leading 1s if the value is too big.#94521ezyang wants to merge 3 commits intogh/ezyang/1805/basefrom
ezyang wants to merge 3 commits intogh/ezyang/1805/basefrom
Conversation
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 <ezyang@meta.com> [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/94521
Note: Links to docs will display an error until the docs builds have been completed. ❌ 5 Failures, 1 PendingAs of commit a7eee5a: NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
ezyang
added a commit
that referenced
this pull request
Feb 9, 2023
…SymInts" This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 9, 2023
This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 10, 2023
…SymInts" This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 10, 2023
This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 10, 2023
…SymInts" This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 10, 2023
This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
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]
ezyang
added a commit
that referenced
this pull request
Feb 10, 2023
…SymInts" This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 10, 2023
This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 11, 2023
…SymInts" This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 11, 2023
This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
Contributor
Author
|
@pytorchbot revert -c nosignal -m "fails internal tests" |
Collaborator
|
@pytorchbot successfully started a revert job. Check the current status here. |
Collaborator
|
@ezyang your PR has been successfully reverted. |
pytorchmergebot
added a commit
that referenced
this pull request
Feb 19, 2023
This reverts commit 03f4a63. Reverted #94521 on behalf of https://github.com/ezyang due to fails internal tests
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]
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. 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]
ngimel
reviewed
Feb 19, 2023
Collaborator
ngimel
left a comment
There was a problem hiding this comment.
Yeah hard to do it fully correctly, but this is better than before.
Contributor
Author
|
better version at #95141 |
ezyang
added a commit
that referenced
this pull request
Feb 20, 2023
…cked" 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
added a commit
that referenced
this pull request
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
added a commit
that referenced
this pull request
Feb 20, 2023
…SymInts" This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 20, 2023
This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 20, 2023
…SymInts" This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> cc soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 20, 2023
This adds support for unbacked SymInts from nonzero, and then gets this working end-to-end with advanced indexing and boolean masking. I needed to apply a variety of fixes to get this to work; these fixes are emblematic of the kind of enablement work we will need to do for unbacked SymInts as they are used more heavily. * When we allocate a contiguous tensor, hard code relevant fields (e.g., `is_contiguous_`) true, instead of keeping the complicated guardless implementation. As Horace notes, all guardless implementations really do is push off the evaluation problem until later. We do poke contiguity reasonably often, but we also typically allocate these with torch.empty so we know statically they are contiguous. * Allow boolean tensors into the index.Tensor meta, and redirect fake tensor to call the meta function directly (so that when it calls nonzero, it decomposes to the fake tensor nonzero) * Don't rewrap tensors in TensorMeta; it does nothing but hits `empty_strided` which is generally not unbacked SymInt friendly * Refactor `compute_elementwise_output_strides` to return the output permutation. I then use this to rewrite the `empty_like` reference to avoid calling `empty_strided`; instead, it allocates a contiguous tensor and permutes it. * Refactor `_broadcast_shapes` to test for more common cases (shapes are equal) before broadcasting case, which is enough to get the broadcasting in advanced indexing going without adding an unnecessary == 1 guard. * Make nonzero return an unbacked symint in size, and put enough assumptions on it so that the boolean masking end to end works * Don't remove leading 1s in setitem unless the value tensor is too big for the input tensor. Submitted separately at #94521 * Don't record `memory_format` on TensorMeta if there are unbacked SymInts. Actually, we can probably do a bit better here; sometimes a tensor will have unbacked SymInt but is obviously contiguous and we ought to report that. Leaving that for future work. Signed-off-by: Edward Z. Yang <ezyangmeta.com> cc soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
pytorchmergebot
pushed a commit
that referenced
this pull request
Feb 21, 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> Pull Request resolved: #95141 Approved by: https://github.com/ngimel
pruthvistony
added a commit
to ROCm/pytorch
that referenced
this pull request
May 2, 2023
…torch#94521)"" This reverts commit f89ae0a.
pruthvistony
added a commit
to ROCm/pytorch
that referenced
this pull request
May 2, 2023
)" This reverts commit 03f4a63.
jhavukainen
pushed a commit
to kulinseth/pytorch
that referenced
this pull request
Mar 15, 2024
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 <ezyang@meta.com> Pull Request resolved: pytorch#94521 Approved by: https://github.com/voznesenskym
jhavukainen
pushed a commit
to kulinseth/pytorch
that referenced
this pull request
Mar 15, 2024
)" This reverts commit 03f4a63. Reverted pytorch#94521 on behalf of https://github.com/ezyang due to fails internal tests
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
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 ezyang@meta.com