From 8a89ca94cee7d671ce89a3295bf170b27168914a Mon Sep 17 00:00:00 2001 From: chengduo <30176695+chengduoZH@users.noreply.github.com> Date: Mon, 19 Aug 2019 09:57:21 +0800 Subject: [PATCH] Fix REGISTER_OP_WITHOUT_GRADIENT (#19251) * fix REGISTER_OP_WITHOUT_GRADIENT test=develop --- paddle/fluid/framework/op_registry.h | 9 +++-- .../fluid/tests/unittests/test_backward.py | 34 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/framework/op_registry.h b/paddle/fluid/framework/op_registry.h index a53a81c270a..3f14f47f0dd 100644 --- a/paddle/fluid/framework/op_registry.h +++ b/paddle/fluid/framework/op_registry.h @@ -16,6 +16,7 @@ limitations under the License. */ #include #include +#include #include #include #include @@ -53,8 +54,9 @@ class Registrar { template struct OperatorRegistrar : public Registrar { explicit OperatorRegistrar(const char* op_type) { - PADDLE_ENFORCE(!OpInfoMap::Instance().Has(op_type), - "'%s' is registered more than once.", op_type); + if (OpInfoMap::Instance().Has(op_type)) { + PADDLE_THROW("'%s' is registered more than once.", op_type); + } static_assert(sizeof...(ARGS) != 0, "OperatorRegistrar should be invoked at least by OpClass"); OpInfo info; @@ -206,7 +208,8 @@ struct OpKernelRegistrarFunctorEx