From a2bbd06a3c049dd44c75f3323de17021f9deec66 Mon Sep 17 00:00:00 2001 From: liym27 <33742067+liym27@users.noreply.github.com> Date: Mon, 11 Jan 2021 19:11:36 +0800 Subject: [PATCH] [Cherry-Pick 2.0] Check the rank of input in kernel of set_value op (#30147) (#30301) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cherry-pick #30147,For op set_value, check input's rank < 7 --- paddle/fluid/operators/set_value_op.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/operators/set_value_op.h b/paddle/fluid/operators/set_value_op.h index e7624ed5eb..1f08e81bf0 100644 --- a/paddle/fluid/operators/set_value_op.h +++ b/paddle/fluid/operators/set_value_op.h @@ -83,7 +83,7 @@ template class SetValueKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const { - const int rank = ctx.Output("Out")->dims().size(); + const int rank = ctx.Input("Input")->dims().size(); // TODO(liym27): A more elegent code to do this. C++ has to make template // integer as constant, but we had better have alternative writing in the @@ -107,6 +107,9 @@ class SetValueKernel : public framework::OpKernel { case 6: SetValueCompute<6>(ctx); break; + default: + PADDLE_THROW(platform::errors::InvalidArgument( + "The rank of input should be less than 7, but received %d.", rank)); } } -- GitLab