From 77572b70cb85b89797195b76a98516993158b957 Mon Sep 17 00:00:00 2001 From: Yiqun Liu Date: Thu, 15 Aug 2019 10:52:51 +0800 Subject: [PATCH] Enhance the error message when GrapOpMaker is null. (#19070) * Enhance the error message when GrapOpMaker is null. test=develop * Call Proto() instead of directly using proto_ pointer. test=develop * Rollback to use proto_ directly, because some sepecial grad ops, such some double grad ops, donot have proto. test=develop --- paddle/fluid/framework/op_info.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/op_info.h b/paddle/fluid/framework/op_info.h index daa72769c49..ab1554d140b 100644 --- a/paddle/fluid/framework/op_info.h +++ b/paddle/fluid/framework/op_info.h @@ -52,21 +52,29 @@ struct OpInfo { } const proto::OpProto& Proto() const { - PADDLE_ENFORCE_NOT_NULL(proto_, "Operator Proto has not been registered"); + PADDLE_ENFORCE_NOT_NULL(proto_, "Operator's Proto has not been registered"); PADDLE_ENFORCE(proto_->IsInitialized(), - "Operator Proto must be initialized in op info"); + "Operator's Proto must be initialized in op info"); return *proto_; } const OpCreator& Creator() const { PADDLE_ENFORCE_NOT_NULL(creator_, - "Operator Creator has not been registered"); + "Operator's Creator has not been registered"); return creator_; } const GradOpMakerFN& GradOpMaker() const { - PADDLE_ENFORCE_NOT_NULL(grad_op_maker_, - "Operator GradOpMaker has not been registered."); + // Normally, proto_ should not be null, except some special operators, such + // as LeaklyReluDoubleGrad op. + std::string type = proto_ ? proto_->type() : "unknown"; + PADDLE_ENFORCE_NOT_NULL( + grad_op_maker_, + "Operator %s's GradOpMaker has not been " + "registered.\nPlease check whether %s_op has " + "grad_op.\nIf not, please set stop_gradient to True " + "for its input and output variables using var.stop_gradient=True.", + type.c_str(), type.c_str()); return grad_op_maker_; } -- GitLab