Skip to content

Commit bf222f1

Browse files
authored
Use sub scope in tensor_array_to_tensor op. (#14524)
test=develop
1 parent 840c1b2 commit bf222f1

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

paddle/fluid/framework/executor.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
392392

393393
int64_t max_memory_size = GetEagerDeletionThreshold();
394394
std::unique_ptr<GarbageCollector<Tensor>> gc;
395-
// WhileOp would set keep_kids to false
396-
// WhileGradOp would need the scopes created in WhileOp
395+
// WhileOp would set keep_kids to true,
396+
// because WhileGradOp needs the scopes created in WhileOp.
397397
// Perhaps, we should not perform eager deletion in WhileOp
398398
// The scopes and variables created by WhileOp would be deleted
399399
// in WhileGradOp.

paddle/fluid/inference/api/analysis_predictor.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ bool AnalysisPredictor::Run(const std::vector<PaddleTensor> &inputs,
174174
inference::Timer timer;
175175
timer.tic();
176176
// set feed variable
177-
std::vector<framework::LoDTensor> feeds;
178177
framework::Scope *scope = sub_scope_ ? sub_scope_ : scope_.get();
179178
if (!SetFeed(inputs, scope)) {
180179
LOG(ERROR) << "fail to set feed";

paddle/fluid/inference/api/api_impl.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ bool NativePaddlePredictor::Run(const std::vector<PaddleTensor> &inputs,
138138
Timer timer;
139139
timer.tic();
140140
// set feed variable
141-
std::vector<framework::LoDTensor> feeds;
142141
framework::Scope *scope = sub_scope_ != nullptr ? sub_scope_ : scope_.get();
143142
if (!SetFeed(inputs, scope)) {
144143
LOG(ERROR) << "fail to set feed";

paddle/fluid/inference/tests/api/CMakeLists.txt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ inference_analysis_api_test(test_analyzer_seq_conv1 ${SEQ_CONV1_INSTALL_DIR} ana
7474
# ocr
7575
set(OCR_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/ocr")
7676
if (NOT EXISTS ${OCR_INSTALL_DIR})
77-
inference_download_and_uncompress(${OCR_INSTALL_DIR} "http://paddlemodels.cdn.bcebos.com/" "inference-vis-demos%2Focr.tar.gz")
77+
inference_download_and_uncompress(${OCR_INSTALL_DIR} "http://paddlemodels.cdn.bcebos.com/" "inference-vis-demos%2Focr.tar.gz")
7878
endif()
7979
inference_analysis_api_test(test_analyzer_ocr ${OCR_INSTALL_DIR} analyzer_vis_tester.cc)
8080

@@ -88,31 +88,31 @@ inference_analysis_api_test_with_fake_data(test_analyzer_mobilenet
8888

8989
# anakin
9090
if (WITH_ANAKIN AND WITH_MKL) # only needed in CI
91-
# anakin rnn1
92-
set(ANAKIN_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/anakin")
93-
set(ANAKIN_RNN1_INSTALL_DIR "${ANAKIN_INSTALL_DIR}/rnn1")
94-
inference_download(${ANAKIN_RNN1_INSTALL_DIR} ${INFERENCE_URL} "anakin_test%2Fditu_rnn.anakin2.model.bin")
95-
inference_download(${ANAKIN_RNN1_INSTALL_DIR} ${INFERENCE_URL} "anakin_test%2Fditu_rnn_data.txt")
96-
cc_test(test_anakin_rnn1 SRCS anakin_rnn1_tester.cc
97-
ARGS --model=${ANAKIN_RNN1_INSTALL_DIR}/anakin_test%2Fditu_rnn.anakin2.model.bin
98-
--datapath=${ANAKIN_RNN1_INSTALL_DIR}/anakin_test%2Fditu_rnn_data.txt
99-
DEPS inference_anakin_api_shared SERIAL)
100-
# anakin mobilenet
101-
if(WITH_GPU)
102-
set(ANAKIN_MOBILENET_INSTALL_DIR "${ANAKIN_INSTALL_DIR}/mobilenet")
103-
inference_download(${ANAKIN_MOBILENET_INSTALL_DIR} ${INFERENCE_URL} "mobilenet_v2.anakin.bin")
104-
cc_test(test_anakin_mobilenet SRCS anakin_mobilenet_tester.cc
105-
ARGS --model=${ANAKIN_MOBILENET_INSTALL_DIR}/mobilenet_v2.anakin.bin
106-
DEPS inference_anakin_api_shared dynload_cuda SERIAL)
107-
endif()
91+
# anakin rnn1
92+
set(ANAKIN_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/anakin")
93+
set(ANAKIN_RNN1_INSTALL_DIR "${ANAKIN_INSTALL_DIR}/rnn1")
94+
inference_download(${ANAKIN_RNN1_INSTALL_DIR} ${INFERENCE_URL} "anakin_test%2Fditu_rnn.anakin2.model.bin")
95+
inference_download(${ANAKIN_RNN1_INSTALL_DIR} ${INFERENCE_URL} "anakin_test%2Fditu_rnn_data.txt")
96+
cc_test(test_anakin_rnn1 SRCS anakin_rnn1_tester.cc
97+
ARGS --model=${ANAKIN_RNN1_INSTALL_DIR}/anakin_test%2Fditu_rnn.anakin2.model.bin
98+
--datapath=${ANAKIN_RNN1_INSTALL_DIR}/anakin_test%2Fditu_rnn_data.txt
99+
DEPS inference_anakin_api_shared SERIAL)
100+
# anakin mobilenet
101+
if(WITH_GPU)
102+
set(ANAKIN_MOBILENET_INSTALL_DIR "${ANAKIN_INSTALL_DIR}/mobilenet")
103+
inference_download(${ANAKIN_MOBILENET_INSTALL_DIR} ${INFERENCE_URL} "mobilenet_v2.anakin.bin")
104+
cc_test(test_anakin_mobilenet SRCS anakin_mobilenet_tester.cc
105+
ARGS --model=${ANAKIN_MOBILENET_INSTALL_DIR}/mobilenet_v2.anakin.bin
106+
DEPS inference_anakin_api_shared dynload_cuda SERIAL)
107+
endif()
108108
endif()
109109

110110
if(WITH_GPU AND TENSORRT_FOUND)
111-
set(TRT_MODEL_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/trt")
112-
if (NOT EXISTS ${TRT_MODEL_INSTALL_DIR})
113-
inference_download_and_uncompress(${TRT_MODEL_INSTALL_DIR} ${INFERENCE_URL}/tensorrt_test "trt_test_models.tar.gz")
114-
endif()
115-
inference_analysis_test(test_trt_models SRCS trt_models_tester.cc
116-
EXTRA_DEPS ${INFERENCE_EXTRA_DEPS}
117-
ARGS --infer_model=${TRT_MODEL_INSTALL_DIR}/trt_test_models SERIAL)
111+
set(TRT_MODEL_INSTALL_DIR "${INFERENCE_DEMO_INSTALL_DIR}/trt")
112+
if (NOT EXISTS ${TRT_MODEL_INSTALL_DIR})
113+
inference_download_and_uncompress(${TRT_MODEL_INSTALL_DIR} ${INFERENCE_URL}/tensorrt_test "trt_test_models.tar.gz")
114+
endif()
115+
inference_analysis_test(test_trt_models SRCS trt_models_tester.cc
116+
EXTRA_DEPS ${INFERENCE_EXTRA_DEPS}
117+
ARGS --infer_model=${TRT_MODEL_INSTALL_DIR}/trt_test_models SERIAL)
118118
endif()

paddle/fluid/operators/tensor_array_to_tensor_op.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ class LoDTensorArray2TensorOp : public framework::OperatorBase {
106106
out_inx_dim[0] = inx.size();
107107
out_inx.Resize(out_inx_dim);
108108

109+
auto &local_scope = scope.NewScope();
109110
std::string var_name = "out_index";
110-
framework::Variable *tmp_index_var =
111-
const_cast<framework::Scope &>(scope).Var(var_name);
111+
framework::Variable *tmp_index_var = local_scope.Var(var_name);
112112
auto &tmp_index_tensor =
113113
*(tmp_index_var->GetMutable<paddle::framework::LoDTensor>());
114114
tmp_index_tensor.Resize(out_inx_dim);
@@ -128,12 +128,12 @@ class LoDTensorArray2TensorOp : public framework::OperatorBase {
128128
out_dims[axis] = out_dim_sum;
129129
out.Resize(out_dims);
130130

131-
LodTensorArray2LodTensorVector(scope, base_name, Input("X"), &names);
132-
// Invoke Reshape Op
131+
LodTensorArray2LodTensorVector(local_scope, base_name, Input("X"), &names);
132+
// Invoke concat Op
133133
auto concat_op = framework::OpRegistry::CreateOp(
134134
"concat", {{"X", names}}, {{"Out", {Output("Out")}}}, attrs);
135135

136-
concat_op->Run(scope, place);
136+
concat_op->Run(local_scope, place);
137137
}
138138
};
139139

0 commit comments

Comments
 (0)