未验证 提交 7f3e0eaa 编写于 作者: Z Zeng Jinle 提交者: GitHub

refine error msg, test=develop (#23589)

上级 ea22515a
...@@ -35,12 +35,16 @@ class ReaderBase { ...@@ -35,12 +35,16 @@ class ReaderBase {
: shapes_(shapes), : shapes_(shapes),
var_types_(var_types), var_types_(var_types),
need_check_feed_(need_check_feed) { need_check_feed_(need_check_feed) {
PADDLE_ENFORCE_EQ(shapes_.size(), need_check_feed_.size(), PADDLE_ENFORCE_EQ(
"Construct ReaderBase with mismatched sizes of shapes " shapes_.size(), need_check_feed_.size(),
"and need_check_feed"); platform::errors::InvalidArgument(
PADDLE_ENFORCE_EQ(var_types_.size(), need_check_feed_.size(), "Construct ReaderBase with mismatched sizes of shapes "
"Construct ReaderBase with mismatched sizes of var_types " "and need_check_feed"));
"and need_check_feed"); PADDLE_ENFORCE_EQ(
var_types_.size(), need_check_feed_.size(),
platform::errors::InvalidArgument(
"Construct ReaderBase with mismatched sizes of var_types "
"and need_check_feed"));
} }
virtual void ReadNext(std::vector<LoDTensor>* out); virtual void ReadNext(std::vector<LoDTensor>* out);
...@@ -108,7 +112,10 @@ class DecoratedReader : public ReaderBase, ...@@ -108,7 +112,10 @@ class DecoratedReader : public ReaderBase,
: ReaderBase(reader->Shapes(), reader->VarTypes(), : ReaderBase(reader->Shapes(), reader->VarTypes(),
reader->NeedCheckFeed()), reader->NeedCheckFeed()),
reader_(reader) { reader_(reader) {
PADDLE_ENFORCE_NOT_NULL(reader_); PADDLE_ENFORCE_NOT_NULL(
reader_,
platform::errors::InvalidArgument(
"The underlying reader of DecoratedReader should not be null"));
} }
void RegisterDecorateChain() { void RegisterDecorateChain() {
...@@ -148,7 +155,10 @@ class ReaderHolder { ...@@ -148,7 +155,10 @@ class ReaderHolder {
template <typename T> template <typename T>
void Reset(const std::shared_ptr<T>& reader) { void Reset(const std::shared_ptr<T>& reader) {
auto reader_base = std::dynamic_pointer_cast<ReaderBase>(reader); auto reader_base = std::dynamic_pointer_cast<ReaderBase>(reader);
PADDLE_ENFORCE_NOT_NULL(reader_base); PADDLE_ENFORCE_NOT_NULL(
reader_base,
platform::errors::InvalidArgument(
"The underlying reader of ReaderHolder should not be null"));
reader_ = reader_base; reader_ = reader_base;
} }
...@@ -157,7 +167,10 @@ class ReaderHolder { ...@@ -157,7 +167,10 @@ class ReaderHolder {
const std::shared_ptr<ReaderBase>& Get() const { return reader_; } const std::shared_ptr<ReaderBase>& Get() const { return reader_; }
void ReadNext(std::vector<LoDTensor>* out) { void ReadNext(std::vector<LoDTensor>* out) {
PADDLE_ENFORCE_NOT_NULL(reader_); PADDLE_ENFORCE_NOT_NULL(
reader_,
platform::errors::InvalidArgument(
"The underlying reader of ReaderHolder should not be null"));
reader_->ReadNext(out); reader_->ReadNext(out);
} }
...@@ -174,13 +187,19 @@ class ReaderHolder { ...@@ -174,13 +187,19 @@ class ReaderHolder {
void Shutdown() { void Shutdown() {
VLOG(1) << "Shutdown"; VLOG(1) << "Shutdown";
PADDLE_ENFORCE_NOT_NULL(reader_); PADDLE_ENFORCE_NOT_NULL(
reader_,
platform::errors::InvalidArgument(
"The underlying reader of ReaderHolder should not be null"));
reader_->Shutdown(); reader_->Shutdown();
} }
void Start() { void Start() {
VLOG(1) << "start"; VLOG(1) << "start";
PADDLE_ENFORCE_NOT_NULL(reader_); PADDLE_ENFORCE_NOT_NULL(
reader_,
platform::errors::InvalidArgument(
"The underlying reader of ReaderHolder should not be null"));
reader_->Start(); reader_->Start();
} }
......
...@@ -35,7 +35,9 @@ class CreateDoubleBufferReaderOp : public framework::OperatorBase { ...@@ -35,7 +35,9 @@ class CreateDoubleBufferReaderOp : public framework::OperatorBase {
dynamic_cast<framework::DecoratedReader*>(out->Get().get()); dynamic_cast<framework::DecoratedReader*>(out->Get().get());
PADDLE_ENFORCE_NOT_NULL( PADDLE_ENFORCE_NOT_NULL(
decorated_reader, decorated_reader,
platform::errors::NotFound("Not inited with DecoratedReader")); platform::errors::NotFound("The inited reader should be a "
"DecoratedReader when running "
"create_double_buffer_reader op."));
if (decorated_reader->UnderlyingReader() == underlying_reader.Get()) { if (decorated_reader->UnderlyingReader() == underlying_reader.Get()) {
return; return;
} }
......
...@@ -36,8 +36,11 @@ class CreatePyReaderOp : public framework::OperatorBase { ...@@ -36,8 +36,11 @@ class CreatePyReaderOp : public framework::OperatorBase {
auto* queue_holder_var = scope.FindVar(queue_name); auto* queue_holder_var = scope.FindVar(queue_name);
PADDLE_ENFORCE_NOT_NULL( PADDLE_ENFORCE_NOT_NULL(
queue_holder_var, queue_holder_var,
"No LoDTensorBlockingQueueHolder variable with name %s found", platform::errors::NotFound(
queue_name); "No LoDTensorBlockingQueueHolder variable with name %s found. This "
"may be because the DataLoader is defined in another Scope, "
"which is different from the Scope when calling Executor.run.",
queue_name));
std::shared_ptr<LoDTensorBlockingQueue> queue; std::shared_ptr<LoDTensorBlockingQueue> queue;
std::shared_ptr<OrderedMultiDeviceLoDTensorBlockingQueue> ordered_queue; std::shared_ptr<OrderedMultiDeviceLoDTensorBlockingQueue> ordered_queue;
int dev_idx = -1; int dev_idx = -1;
......
...@@ -43,24 +43,25 @@ bool DimensionIsCompatibleWith(const framework::DDim& first, ...@@ -43,24 +43,25 @@ bool DimensionIsCompatibleWith(const framework::DDim& first,
class ReadInferShape : public framework::InferShapeBase { class ReadInferShape : public framework::InferShapeBase {
public: public:
void operator()(framework::InferShapeContext* ctx) const override { void operator()(framework::InferShapeContext* ctx) const override {
PADDLE_ENFORCE(ctx->HasInput("Reader"), OP_INOUT_CHECK(ctx->HasInput("Reader"), "Input", "Reader", "read");
"The ReadOp must take a reader as input."); OP_INOUT_CHECK(ctx->HasOutputs("Out"), "Output", "Out", "read");
PADDLE_ENFORCE(ctx->HasOutputs("Out"),
"The ReadOp should be assigned with output.");
if (!ctx->IsRuntime() && ctx->Attrs().Get<bool>("infer_out")) { if (!ctx->IsRuntime() && ctx->Attrs().Get<bool>("infer_out")) {
std::vector<framework::DDim> reader_dims = ctx->GetReaderDims("Reader"); std::vector<framework::DDim> reader_dims = ctx->GetReaderDims("Reader");
std::vector<std::string> out_names = ctx->Outputs("Out"); std::vector<std::string> out_names = ctx->Outputs("Out");
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
reader_dims.size(), out_names.size(), reader_dims.size(), out_names.size(),
"The reader's dim number doesn't match the output number."); platform::errors::InvalidArgument(
"The reader's dim number doesn't match the output number."));
ctx->SetOutputsDim("Out", reader_dims); ctx->SetOutputsDim("Out", reader_dims);
auto in_desc = auto in_desc =
boost::get<framework::VarDesc*>(ctx->GetInputVarPtrs("Reader")[0]); boost::get<framework::VarDesc*>(ctx->GetInputVarPtrs("Reader")[0]);
auto in_lod_levels = in_desc->GetLoDLevels(); auto in_lod_levels = in_desc->GetLoDLevels();
auto out_var_ptrs = ctx->GetOutputVarPtrs("Out"); auto out_var_ptrs = ctx->GetOutputVarPtrs("Out");
PADDLE_ENFORCE_EQ(in_lod_levels.size(), out_var_ptrs.size(), PADDLE_ENFORCE_EQ(
"LoDLevels of Input(Reader) must be the same as the " in_lod_levels.size(), out_var_ptrs.size(),
"number of Outputs(Out)."); platform::errors::InvalidArgument(
"LoDLevels of Input(Reader) must be the same as the "
"number of Outputs(Out)."));
for (size_t i = 0; i < out_var_ptrs.size(); ++i) { for (size_t i = 0; i < out_var_ptrs.size(); ++i) {
auto* out_desc = boost::get<framework::VarDesc*>(out_var_ptrs[i]); auto* out_desc = boost::get<framework::VarDesc*>(out_var_ptrs[i]);
out_desc->SetLoDLevel(in_lod_levels[i]); out_desc->SetLoDLevel(in_lod_levels[i]);
...@@ -109,31 +110,36 @@ class ReadOp : public framework::OperatorBase { ...@@ -109,31 +110,36 @@ class ReadOp : public framework::OperatorBase {
VLOG(3) << "throw_eof_exp"; VLOG(3) << "throw_eof_exp";
PADDLE_THROW_EOF(); PADDLE_THROW_EOF();
} }
PADDLE_ENFORCE_EQ(ins.size(), out_arg_names.size(), PADDLE_ENFORCE_EQ(
"input size and output size of read_op do not match"); ins.size(), out_arg_names.size(),
platform::errors::InvalidArgument("input data number and output data "
"number of read_op do not match"));
const std::vector<framework::DDim>& shapes = reader->Shapes(); const std::vector<framework::DDim>& shapes = reader->Shapes();
const std::vector<framework::proto::VarType::Type>& var_types = const std::vector<framework::proto::VarType::Type>& var_types =
reader->VarTypes(); reader->VarTypes();
const std::vector<bool>& need_check_feed = reader->NeedCheckFeed(); const std::vector<bool>& need_check_feed = reader->NeedCheckFeed();
PADDLE_ENFORCE_EQ(out_arg_names.size(), need_check_feed.size(), PADDLE_ENFORCE_EQ(out_arg_names.size(), need_check_feed.size(),
"output size of read_op and the number of fed " platform::errors::InvalidArgument(
"variables of reader do not match"); "output size of read_op and the number of fed "
"variables of reader do not match"));
for (size_t i = 0; i < out_arg_names.size(); ++i) { for (size_t i = 0; i < out_arg_names.size(); ++i) {
auto* out = auto* out =
scope.FindVar(out_arg_names[i])->GetMutable<framework::LoDTensor>(); scope.FindVar(out_arg_names[i])->GetMutable<framework::LoDTensor>();
if (need_check_feed[i]) { if (need_check_feed[i]) {
auto in_dims = ins[i].dims(); auto in_dims = ins[i].dims();
PADDLE_ENFORCE_EQ(DimensionIsCompatibleWith(shapes[i], in_dims), true, PADDLE_ENFORCE_EQ(
"The fed Variable %s should have dimensions = %d, " DimensionIsCompatibleWith(shapes[i], in_dims), true,
"shape = [%s], but received fed shape [%s]", platform::errors::InvalidArgument(
out_arg_names[i], shapes[i].size(), shapes[i], "The fed Variable %s should have dimensions = %d, "
in_dims); "shape = [%s], but received fed shape [%s]",
out_arg_names[i], shapes[i].size(), shapes[i], in_dims));
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
ins[i].type(), var_types[i], ins[i].type(), var_types[i],
"The data type of fed Variable %s must be %s, but received %s", platform::errors::InvalidArgument(
out_arg_names[i], var_types[i], ins[i].type()); "The data type of fed Variable %s must be %s, but received %s",
out_arg_names[i], var_types[i], ins[i].type()));
} }
out->ShareDataWith(ins[i]); out->ShareDataWith(ins[i]);
out->set_lod(ins[i].lod()); out->set_lod(ins[i].lod());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册