Get boolean masking to work with unbacked SymInts#94523
Closed
ezyang wants to merge 16 commits intogh/ezyang/1806/basefrom
Closed
Get boolean masking to work with unbacked SymInts#94523ezyang wants to merge 16 commits intogh/ezyang/1806/basefrom
ezyang wants to merge 16 commits intogh/ezyang/1806/basefrom
Conversation
Signed-off-by: Edward Z. Yang <ezyang@meta.com> [ghstack-poisoned]
This was referenced 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]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/94523
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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]
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 16, 2023
Extracted from #94523 Signed-off-by: Edward Z. Yang <ezyang@meta.com> [ghstack-poisoned]
ezyang
added a commit
that referenced
this pull request
Feb 16, 2023
…nts" Extracted from #94523 which has E2E test Signed-off-by: Edward Z. Yang <ezyangmeta.com> [ghstack-poisoned]
pytorchmergebot
pushed a commit
that referenced
this pull request
Feb 17, 2023
Extracted from #94523 which has E2E test Signed-off-by: Edward Z. Yang <ezyang@meta.com> Pull Request resolved: #95003 Approved by: https://github.com/voznesenskym, https://github.com/ngimel
pytorchmergebot
pushed a commit
that referenced
this pull request
Feb 17, 2023
Extracted from #94523 Signed-off-by: Edward Z. Yang <ezyang@meta.com> Pull Request resolved: #95004 Approved by: https://github.com/voznesenskym, https://github.com/ngimel, https://github.com/Skylion007
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]
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]
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. * Feature guard tracing through nonzero with capture_dynamic_output_shape_ops because Inductor generally can't handle it * 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) * 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 calls `empty_permuted`. * 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 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]
Closed
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. * Feature guard tracing through nonzero with capture_dynamic_output_shape_ops because Inductor generally can't handle it * 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) * 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 calls `empty_permuted`. * 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 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]
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. * Feature guard tracing through nonzero with capture_dynamic_output_shape_ops because Inductor generally can't handle it * 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) * 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 calls `empty_permuted`. * 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 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]
This was referenced Feb 21, 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. * Feature guard tracing through nonzero with capture_dynamic_output_shape_ops because Inductor generally can't handle it * 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) * 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 calls `empty_permuted`. * 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 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]
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. * Feature guard tracing through nonzero with capture_dynamic_output_shape_ops because Inductor generally can't handle it * 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) * 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 calls `empty_permuted`. * 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 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]
jhavukainen
pushed a commit
to kulinseth/pytorch
that referenced
this pull request
Mar 15, 2024
…h#95003) Extracted from pytorch#94523 which has E2E test Signed-off-by: Edward Z. Yang <ezyang@meta.com> Pull Request resolved: pytorch#95003 Approved by: https://github.com/voznesenskym, https://github.com/ngimel
jhavukainen
pushed a commit
to kulinseth/pytorch
that referenced
this pull request
Mar 15, 2024
Extracted from pytorch#94523 Signed-off-by: Edward Z. Yang <ezyang@meta.com> Pull Request resolved: pytorch#95004 Approved by: https://github.com/voznesenskym, https://github.com/ngimel, https://github.com/Skylion007
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):
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.
compute_elementwise_output_stridesto return the output permutation. I then use this to rewrite theempty_likereference to avoid callingempty_strided; instead, it allocates callsempty_permuted._broadcast_shapesto 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.memory_formaton 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 ezyang@meta.com
cc @soumith @voznesenskym @yanboliang @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @desertfire