Skip to content

Commit aca60e9

Browse files
authored
remove unnecessary prepare_data (#17080)
test=develop
1 parent 55ce36e commit aca60e9

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

paddle/fluid/framework/operator.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ Scope* OperatorWithKernel::PrepareData(
10231023
std::vector<std::string>* transfered_inplace_vars,
10241024
RuntimeContext* ctx) const {
10251025
Scope* new_scope = nullptr;
1026+
if (!need_prepare_data_) return new_scope;
10261027

10271028
std::unordered_set<std::string> no_buffer_ins;
10281029
if (info_) {
@@ -1115,6 +1116,10 @@ Scope* OperatorWithKernel::PrepareData(
11151116
SetTensorToVariable(*var, out, trans_var);
11161117
}
11171118
}
1119+
// If new_scope = nullptr, it means that for each input of this Op, there is
1120+
// no TransformData. Thus, PrepareData could be skipped at the rest iterations
1121+
// of this Op's execution to save the elapsed time.
1122+
if (!new_scope) need_prepare_data_ = false;
11181123

11191124
return new_scope;
11201125
}

paddle/fluid/framework/operator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ class OperatorWithKernel : public OperatorBase {
506506
mutable std::unique_ptr<OpKernelFunc> kernel_func_;
507507
mutable std::unique_ptr<RuntimeContext> runtime_ctx_;
508508
mutable const Scope* pre_scope_ = nullptr;
509+
mutable bool need_prepare_data_ = true;
509510
mutable bool enable_cache_runtime_context = false;
510511
mutable bool enable_cache_expected_kernel = false;
511512
mutable bool all_kernels_must_compute_runtime_shape = false;

0 commit comments

Comments
 (0)