You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "spectrometerHBH (via GitHub)" <gi...@apache.org> on 2023/03/09 21:12:05 UTC
[GitHub] [tvm] spectrometerHBH opened a new pull request, #14264: [Unity][TOPI] fp16 LayerNorm & GroupNorm
spectrometerHBH opened a new pull request, #14264:
URL: https://github.com/apache/tvm/pull/14264
This pr modifies the topi implementation (which is also the legalizer's backend of Relax) of LayerNorm and GroupNorm operators to allow them to accept fp16 inputs, cast to fp32 internally, and produce fp16 outputs.
This can help eliminate unnecessary casts caused by AMP.
--
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] junrushao merged pull request #14264: [Unity][TOPI] fp16 LayerNorm & GroupNorm
Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao merged PR #14264:
URL: https://github.com/apache/tvm/pull/14264
--
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] yzh119 commented on a diff in pull request #14264: [Unity][TOPI] fp16 LayerNorm & GroupNorm
Posted by "yzh119 (via GitHub)" <gi...@apache.org>.
yzh119 commented on code in PR #14264:
URL: https://github.com/apache/tvm/pull/14264#discussion_r1133120804
##########
include/tvm/topi/nn/layer_norm.h:
##########
@@ -75,8 +84,18 @@ inline Tensor layer_norm(const Tensor& data, const Tensor& gamma, const Tensor&
arg_counter++;
}
}
- auto square = [](const PrimExpr& x) { return x * x; };
- return func({data(eval_range), square(data(eval_range))}, reduce_axes, nullptr);
+ auto square = [is_float16](const PrimExpr& x) {
+ if (is_float16) {
+ return Cast(DataType::Float(32), x) * Cast(DataType::Float(32), x);
+ }
+ return x * x;
+ };
+ if (is_float16) {
+ return func({Cast(DataType::Float(32), data(eval_range)), square(data(eval_range))},
Review Comment:
ditto.
##########
include/tvm/topi/nn/group_norm.h:
##########
@@ -56,8 +59,13 @@ inline Tensor group_norm(const Tensor& data, const Tensor& gamma, const Tensor&
new_shape.push_back(shape[i]);
}
}
- auto data_reshaped = reshape(data, new_shape);
- // reshape gamma and beta, C -> G, C/G
+ Tensor data_reshaped;
+ if (is_float16) {
+ data_reshaped = cast(reshape(data, new_shape), DataType::Float(32));
Review Comment:
I would be good if we mention the behavior of implicit type cast in the docstring.
--
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 #14264: [Unity][TOPI] fp16 LayerNorm & GroupNorm
Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #14264:
URL: https://github.com/apache/tvm/pull/14264#issuecomment-1462831244
<!---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