diff --git a/paddle/fluid/framework/op_info.h b/paddle/fluid/framework/op_info.h index daa72769c4957ff5ad0e7b3141bbf97bd348b408..ab1554d140bc83067678abd2f148d2abb57aa433 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_; }