未验证 提交 25871e0e 编写于 作者: W wangxinxin08 提交者: GitHub

add axis check for elementwise op while the dimension of x is equal to the...

add axis check for elementwise op while the dimension of x is equal to the dimension of tensor (#35340)
上级 a622b701
......@@ -85,6 +85,14 @@ class ElementwiseOp : public framework::OperatorWithKernel {
auto y_dims = ctx->GetInputDim("Y");
int max_dim = std::max(x_dims.size(), y_dims.size());
int axis = ctx->Attrs().Get<int>("axis");
if (x_dims.size() == y_dims.size()) {
PADDLE_ENFORCE_EQ((axis == -1) || (axis == 0), true,
platform::errors::InvalidArgument(
"axis should be -1 or 0 while the dimension of "
"tensor X (%s) is equal to the dimension of "
"tensor Y (%s), but received axis: %s",
x_dims.size(), y_dims.size(), axis));
}
PADDLE_ENFORCE_EQ((axis >= (-1 * max_dim)) && (axis < max_dim), true,
platform::errors::InvalidArgument(
"The axis range must be [%s, %s), but axis is %s. "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册