You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "sunggg (via GitHub)" <gi...@apache.org> on 2023/04/04 16:21:42 UTC
[GitHub] [tvm] sunggg opened a new pull request, #14493: [Unity][Op] introduce `ScatterElement` op
sunggg opened a new pull request, #14493:
URL: https://github.com/apache/tvm/pull/14493
This PR brings `ScatterElement` op that can be useful for preprocessing argument tensors in the frontend.
For example, for `topi::dynamic_strided_slice` expects its argument tensors (e.g., `begin`, `end`) to have the same rank with the data tensor. (see [link](https://github.com/apache/tvm/blob/unity/include/tvm/topi/transform.h#L657-L661))
```
inline Tensor dynamic_strided_slice(const Tensor& x, const Array<PrimExpr>& begin,
const Array<PrimExpr>& end, const Array<PrimExpr>& strides,
std::string name = "T_dynamic_strided_slice",
std::string tag = kInjective) {
const size_t src_tensor_dim = x->shape.size();
ICHECK_LE(begin.size(), src_tensor_dim);
ICHECK_LE(end.size(), src_tensor_dim);
ICHECK_LE(strides.size(), src_tensor_dim);
ICHECK_EQ(begin.size(), end.size());
ICHECK_EQ(begin.size(), strides.size());
...
```
Thus, frontend often needs to preprocess those argument tensors to make sure the later constraints are satisfied.
For example, say if we have the following situation:
```
data_rank = 4
axes = [2,0]
begin = [1,2]
# We want to preprocess `begin` to
new_begin = [2, 0, 1, 0]
```
With `ScatterElement`, we can conveniently do so.
```Python
new_begin = R.scatter_elements(
relax.const([0] * data_rank), # data
axes, # indices
begin, # updates
axis=0,
reduction="update")
)
```
cc. @jwfromm @yongwww @psrivas2
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] yongwww commented on pull request #14493: [Unity][Op] introduce `ScatterElement` op
Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on PR #14493:
URL: https://github.com/apache/tvm/pull/14493#issuecomment-1497867762
Not sure if this ScatterElement will be used by some other ops as well. I feel we can handle this scattering stuff in strided_slice itself. For example, the strided_slice is able to support begin/end has less elements than the rank of input data: https://github.com/apache/tvm/blob/unity/tests/python/topi/python/test_topi_transform.py#L850
BTW, the ICHECK_LE in the posted sample expects the begin/end has equal (or less) elements
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] zxybazh merged pull request #14493: [Unity][Op] introduce `ScatterElement` op
Posted by "zxybazh (via GitHub)" <gi...@apache.org>.
zxybazh merged PR #14493:
URL: https://github.com/apache/tvm/pull/14493
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] sunggg commented on pull request #14493: [Unity][Op] introduce `ScatterElement` op
Posted by "sunggg (via GitHub)" <gi...@apache.org>.
sunggg commented on PR #14493:
URL: https://github.com/apache/tvm/pull/14493#issuecomment-1498193471
@yongwww thanks for taking a look!
In TOPI, we have two versions of strided slice: One static, one dynamic.
Static one is less constraints, you can pass arbitrarily number of begin/end elements since those values are compile-time constants. However, dynamic strided slice is bit more restricted because you need to know the "rank" of such arguments as presented in the description.
When you look at the test for dynamic slice, they all have the equal ranks with the data rank: https://github.com/apache/tvm/blob/unity/tests/python/topi/python/test_topi_transform.py#L854
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] yongwww commented on pull request #14493: [Unity][Op] introduce `ScatterElement` op
Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on PR #14493:
URL: https://github.com/apache/tvm/pull/14493#issuecomment-1498209377
@sunggg Gotcha, thanks for sharing this info!!!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tvm-bot commented on pull request #14493: [Unity][Op] introduce `ScatterElement` op
Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #14493:
URL: https://github.com/apache/tvm/pull/14493#issuecomment-1496261143
<!---bot-comment-->
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](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
<!--bot-comment-ccs-start-->
* cc @quic-sanirudh <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
<sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] yongwww commented on a diff in pull request #14493: [Unity][Op] introduce `ScatterElement` op
Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on code in PR #14493:
URL: https://github.com/apache/tvm/pull/14493#discussion_r1159067973
##########
src/relax/op/tensor/manipulate.cc:
##########
@@ -1359,5 +1359,119 @@ TVM_REGISTER_OP("relax.cumsum")
.add_argument("data", "Tensor", "The input tensor.")
.set_attr<FInferStructInfo>("FInferStructInfo", InferStructInfoCumsum);
+/* relax.scatter_elements */
+TVM_REGISTER_NODE_TYPE(ScatterElementsAttrs);
+
+Expr scatter_elements(Expr data, Expr indices, Expr updates, int axis, String reduction) {
+ auto attrs = make_object<ScatterElementsAttrs>();
+ attrs->axis = std::move(axis);
+ attrs->reduction = std::move(reduction);
+ static const Op& op = Op::Get("relax.scatter_elements");
+ return Call(op, {data, indices, updates}, Attrs(attrs), {});
+}
+
+TVM_REGISTER_GLOBAL("relax.op.scatter_elements").set_body_typed(scatter_elements);
+
+StructInfo InferStructInfoScatterElements(const Call& call, const BlockBuilder& ctx) {
+ arith::Analyzer* analyzer = ctx->GetAnalyzer();
+ const auto* data_sinfo = GetStructInfoAs<TensorStructInfoNode>(call->args[0]);
+ const auto* indices_sinfo = GetStructInfoAs<TensorStructInfoNode>(call->args[1]);
+ const auto* updates_sinfo = GetStructInfoAs<TensorStructInfoNode>(call->args[2]);
+
+ auto diag_def = [&](const TensorStructInfoNode* sinfo, String name, String type_key) {
+ if (sinfo == nullptr) {
+ ctx->ReportFatal(Diagnostic::Error(call)
+ << "ScatterEelemtns requires the input " << name
Review Comment:
typo: ScatterElements
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org