diff --git a/paddle/fluid/jit/engine/executor_engine.cc b/paddle/fluid/jit/engine/executor_engine.cc index 58d80426e5fbaef258a3cefcaa383fe254deb2a1..1cde715b8f0301fcacfe35dbf74853e519d7ac58 100644 --- a/paddle/fluid/jit/engine/executor_engine.cc +++ b/paddle/fluid/jit/engine/executor_engine.cc @@ -44,14 +44,17 @@ std::vector ExecutorEngine::operator()( std::vector ExecutorEngine::operator()( const std::vector &inputs) { utils::ShareIntoScope(info_->InputArgNames(), inputs, &scope_); + const auto out_names = info_->OutputArgNames(); inner_exe_.Run(info_->ProgramDesc(), &scope_, /*blockID=*/0, false, true, - info_->OutputArgNames()); + out_names); std::vector outputs; - utils::FetchOuts(info_->OutputArgNames(), scope_, &outputs); + utils::FetchOuts(out_names, scope_, &outputs); + // Erase output vars to avoid data rewriting. + scope_.EraseVars(out_names); return outputs; } diff --git a/paddle/fluid/jit/engine/pe_engine.cc b/paddle/fluid/jit/engine/pe_engine.cc index 78e48667547e27b9007afabe71ba6738d210fcde..576687c0efaf1a20459dd6ef1e83acdefe729785 100644 --- a/paddle/fluid/jit/engine/pe_engine.cc +++ b/paddle/fluid/jit/engine/pe_engine.cc @@ -96,12 +96,15 @@ std::vector PEEngine::operator()(const std::vector &inputs) { std::vector PEEngine::operator()( const std::vector &inputs) { utils::ShareIntoScope(info_->InputArgNames(), inputs, &scope_); + const auto out_names = info_->OutputArgNames(); // need to recreate tmp variables in new scope inner_pe_->PrepareVariables(&scope_); - inner_pe_->RunWithoutFetch(info_->OutputArgNames()); + inner_pe_->RunWithoutFetch(out_names); std::vector outputs; - utils::FetchOuts(info_->OutputArgNames(), scope_, &outputs); + utils::FetchOuts(out_names, scope_, &outputs); + // Erase output vars to avoid data rewriting. + scope_.EraseVars(out_names); scope_.DropKids(); return outputs; }