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
padding_in_crf
Yiqun Liu 6 years ago committed by GitHub
parent c6f163cd7a
commit 77572b70cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,21 +52,29 @@ struct OpInfo {
} }
const proto::OpProto& Proto() const { 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(), PADDLE_ENFORCE(proto_->IsInitialized(),
"Operator Proto must be initialized in op info"); "Operator's Proto must be initialized in op info");
return *proto_; return *proto_;
} }
const OpCreator& Creator() const { const OpCreator& Creator() const {
PADDLE_ENFORCE_NOT_NULL(creator_, PADDLE_ENFORCE_NOT_NULL(creator_,
"Operator Creator has not been registered"); "Operator's Creator has not been registered");
return creator_; return creator_;
} }
const GradOpMakerFN& GradOpMaker() const { const GradOpMakerFN& GradOpMaker() const {
PADDLE_ENFORCE_NOT_NULL(grad_op_maker_, // Normally, proto_ should not be null, except some special operators, such
"Operator GradOpMaker has not been registered."); // 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_; return grad_op_maker_;
} }

Loading…
Cancel
Save