[Unity][Op] introduce shape_to_tensor op#14447
Merged
vinx13 merged 4 commits intoapache:unityfrom Apr 3, 2023
Merged
Conversation
Collaborator
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
sunggg
commented
Mar 31, 2023
| ctx->ReportFatal(Diagnostic::Error(call) | ||
| << op << " requires the input " << op->arguments[i]->name | ||
| << " to be Tensor. However, the given one is " | ||
| << " to be Tensor. However, the given one has a " |
Contributor
Author
There was a problem hiding this comment.
This is unrelated to this PR, but found the current message confusing during the debugging.
vinx13
reviewed
Mar 31, 2023
| shape_tuple: tvm.runtime.ShapeTuple | ||
| Shape tuple that we want to convert to NDArray at runtime | ||
| """ | ||
| return tvm.nd.array([int(v) for v in shape_tuple]) |
Member
There was a problem hiding this comment.
do we assume it's always on cpu?
Contributor
Author
There was a problem hiding this comment.
Yes. shape tuple and shape computation happen on the CPU side.
a425bc7 to
5c8b7af
Compare
9870c35 to
fc0cc25
Compare
vinx13
approved these changes
Apr 3, 2023
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.
In Unity, we have a clear distinction between
tensorandshape: we haveShapeExprandShapeStructInfoin AST,ShapeTuplein runtime container. Meanwhile, most of operators and their TOPI implementations are defined with tensors. For example,relax.takeis defined as follows:To allow the shape computation, this PR introduces a
shape_to_tensorop that convertsShapeTupletoNDArrayat runtime. This enables the common shape computation patterns like following:It's worth noting that
tensor_to_shapeop is already introduced in #14282, so roundtrip between shape and tensor would be now possible.Currently, this op requires special handling in
FoldConstantpass since this pass is only able to evaluateTIR primfunc, notPackedFunc. Once we extendFoldConstantto supportPackedFuncevaluation, we should be able to remove these unnecessary special handling.cc. @jwfromm @yongwww @psrivas2 @slyubomirsky @tqchen