From 74c43ac638c38723ead394422b45913752a4a139 Mon Sep 17 00:00:00 2001 From: Wilber Date: Tue, 1 Dec 2020 01:06:12 +0800 Subject: [PATCH] fix lite unit test. (#29233) --- paddle/fluid/inference/lite/test_engine.cc | 3 ++- paddle/fluid/operators/lite/lite_engine_op_test.cc | 3 ++- paddle/fluid/operators/lite/ut_helper.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/inference/lite/test_engine.cc b/paddle/fluid/inference/lite/test_engine.cc index e505af19d5..8e65fa2fbe 100644 --- a/paddle/fluid/inference/lite/test_engine.cc +++ b/paddle/fluid/inference/lite/test_engine.cc @@ -29,6 +29,7 @@ namespace inference { namespace lite { using inference::lite::AddTensorToBlockDesc; +using paddle::inference::lite::AddFetchListToBlockDesc; using inference::lite::CreateTensor; using inference::lite::serialize_params; @@ -65,7 +66,7 @@ void make_fake_model(std::string* model, std::string* param) { AddTensorToBlockDesc(block_, "x", std::vector({2, 4}), true); AddTensorToBlockDesc(block_, "y", std::vector({2, 4}), true); AddTensorToBlockDesc(block_, "z", std::vector({2, 4}), false); - AddTensorToBlockDesc(block_, "out", std::vector({2, 4}), false); + AddFetchListToBlockDesc(block_, "out"); *block_->add_ops() = *feed0->Proto(); *block_->add_ops() = *feed1->Proto(); diff --git a/paddle/fluid/operators/lite/lite_engine_op_test.cc b/paddle/fluid/operators/lite/lite_engine_op_test.cc index 76c963ac65..14088351cc 100644 --- a/paddle/fluid/operators/lite/lite_engine_op_test.cc +++ b/paddle/fluid/operators/lite/lite_engine_op_test.cc @@ -25,6 +25,7 @@ USE_NO_KERNEL_OP(lite_engine) using paddle::inference::lite::AddTensorToBlockDesc; +using paddle::inference::lite::AddFetchListToBlockDesc; using paddle::inference::lite::CreateTensor; using paddle::inference::lite::serialize_params; namespace paddle { @@ -60,7 +61,7 @@ TEST(LiteEngineOp, engine_op) { AddTensorToBlockDesc(block_, "x", std::vector({2, 4}), true); AddTensorToBlockDesc(block_, "y", std::vector({2, 4}), true); AddTensorToBlockDesc(block_, "z", std::vector({2, 4}), false); - AddTensorToBlockDesc(block_, "out", std::vector({2, 4}), false); + AddFetchListToBlockDesc(block_, "out"); *block_->add_ops() = *feed1->Proto(); *block_->add_ops() = *feed0->Proto(); *block_->add_ops() = *elt_add->Proto(); diff --git a/paddle/fluid/operators/lite/ut_helper.h b/paddle/fluid/operators/lite/ut_helper.h index f83b2a1a85..bc049dae77 100644 --- a/paddle/fluid/operators/lite/ut_helper.h +++ b/paddle/fluid/operators/lite/ut_helper.h @@ -42,6 +42,16 @@ void AddTensorToBlockDesc(framework::proto::BlockDesc* block, desc.SetPersistable(persistable); *var = *desc.Proto(); } + +void AddFetchListToBlockDesc(framework::proto::BlockDesc* block, + const std::string& name) { + using framework::proto::VarType; + auto* var = block->add_vars(); + framework::VarDesc desc(name); + desc.SetType(VarType::FETCH_LIST); + *var = *desc.Proto(); +} + void serialize_params(std::string* str, framework::Scope* scope, const std::vector& params) { std::ostringstream os; -- GitLab