fix: tracing ivy.set_item with Ellipsis/unbound slices #28771
Merged
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.
@hmahmood24 just wanted your opinion on this.
The problem is if we trace through the manual set_item logic -
_parse_slice
/_parse_ellipsis
, etc with anEllipsis
or unboundedslice
in the query, the indices which get parsed out will then be hard coded into the traced graph. So the traced graph would only work with inputs of the specific shape it was traced with. We can get around this by using numpy as a intermediary step, but this makes the traced graph incompatible with tf.function.My thought is that we can just use numpy whenever there is an ellipsis or unbounded slice in the query, then at least the traced graph will work when not compiled - this is what I've implemented here. Curious if you agree with my thinking though.
fyi, this issue with dynamic shapes was appearing a lot in the kornia integration testing, which is what brought this issue to light. The changes made here seem to solve most, if not all, the issues.