未验证 提交 e051bba0 编写于 作者: H Huihuang Zheng 提交者: GitHub

Remove RunFromCinn in PE because We Will Call CinnRunner in Compute of SubgraphOp (#36385)

Remove RunFromCinn method in PE because We Will Call CinnRunner in Compute method of SubgraphOp
上级 2c44ee7e
......@@ -34,7 +34,6 @@ limitations under the License. */
#include "paddle/fluid/framework/ir/memory_optimize_pass/memory_optimization_var_info.h"
#include "paddle/fluid/framework/ir/memory_optimize_pass/reference_count_pass_helper.h"
#include "paddle/fluid/framework/ir/multi_devices_graph_pass/set_reader_device_info_utils.h"
#include "paddle/fluid/framework/paddle2cinn/cinn_runner.h"
#include "paddle/fluid/framework/variable_helper.h"
#include "paddle/fluid/platform/cuda_graph_with_memory_pool.h"
#include "paddle/fluid/platform/event.h"
......@@ -44,7 +43,6 @@ limitations under the License. */
#include "paddle/fluid/platform/cuda_device_guard.h"
#endif
DECLARE_bool(use_cinn);
DECLARE_double(eager_delete_tensor_gb);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
......@@ -945,40 +943,6 @@ void ParallelExecutor::RunWithoutFetch(
member_->executor_->Run(/*fetch_tensors*/ {}, /*return_merged*/ false);
}
FetchResultType ParallelExecutor::RunFromCinn(
const std::unordered_map<std::string, LoDTensor> &feed_tensors,
const std::vector<std::string> &fetch_names) {
// Feed tensor to scope, now only support 1 scope
// TODO(zhhsplendid): handle multiple scope
size_t scope_id = 0;
std::map<std::string, const LoDTensor *> cinn_input_tensors;
for (auto &name_tensor_pair : feed_tensors) {
bool is_persistable = member_->IsPersistable(name_tensor_pair.first);
if (!is_persistable) {
member_->SetSkipMemoryReuse(scope_id, name_tensor_pair.first);
}
Scope *feed_scope = is_persistable ? member_->local_scopes_[scope_id]
: member_->local_exec_scopes_[scope_id];
Variable *feed_var = feed_scope->Var(name_tensor_pair.first);
LoDTensor *trg = feed_var->GetMutable<LoDTensor>();
trg->ShareDataWith(name_tensor_pair.second);
trg->set_lod(name_tensor_pair.second.lod());
cinn_input_tensors[name_tensor_pair.first] = trg;
}
// TODO(zhhsplendid): get correct API after CINN API is ready
// now only return empty fetch result;
std::shared_ptr<paddle2cinn::CinnRunner> cinn_runner =
paddle2cinn::CinnRunner::GetInstance();
cinn_runner->Run(Graph(), member_->local_exec_scopes_[scope_id],
&cinn_input_tensors);
paddle::framework::FetchResultType fetches = FetchList(fetch_names.size());
return fetches;
}
void ParallelExecutor::SkipMemoryReuse(
size_t scope_idx, const std::vector<std::string> &skip_vars) {
for (auto &var_name : skip_vars) {
......
......@@ -14,7 +14,6 @@ limitations under the License. */
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
......@@ -93,10 +92,6 @@ class ParallelExecutor {
void RunWithoutFetch(const std::vector<std::string> &skip_eager_vars);
FetchResultType RunFromCinn(
const std::unordered_map<std::string, LoDTensor> &feed_tensors,
const std::vector<std::string> &fetch_names);
void ResetOpHandleScopeMapOfGraphs(
const std::unordered_map<Scope *, Scope *> &scope_map);
......
......@@ -3293,18 +3293,6 @@ All parameter, weight, gradient are variables in Paddle.
BOOST_GET(paddle::framework::FetchUnmergedList, ret)));
}
})
.def("run_from_cinn",
[](ParallelExecutor &self,
const std::unordered_map<std::string, LoDTensor> &feed_tensors,
const std::vector<std::string> &fetch_names) -> py::object {
paddle::framework::FetchResultType ret;
{
pybind11::gil_scoped_release release;
ret = self.RunFromCinn(feed_tensors, fetch_names);
}
return py::cast(
std::move(BOOST_GET(paddle::framework::FetchList, ret)));
})
.def("device_count", &ParallelExecutor::DeviceCount);
BindFleetWrapper(&m);
......
......@@ -24,7 +24,7 @@ from .wrapped_decorator import signature_safe_contextmanager
import six
from .data_feeder import convert_dtype
from .framework import Program, default_main_program, Variable, Operator
from .framework import convert_np_dtype_to_dtype_, get_flags
from .framework import convert_np_dtype_to_dtype_
from . import core
from . import unique_name
from . import compiler
......@@ -1016,17 +1016,8 @@ class Executor(object):
if need_check_feed:
check_feed_shape_type(var, feed_tensor, exe.device_count())
feed_tensor_dict[feed_name] = feed_tensor
exe.feed_and_split_tensor_into_local_scopes(feed_tensor_dict)
#TODO(zhhsplendid): handle other feed data format case for CINN
use_cinn = get_flags("FLAGS_use_cinn")["FLAGS_use_cinn"]
if use_cinn:
fetch_var_names = list(map(_to_name_str, fetch_list))
fetch_tensors = exe.run_from_cinn(
feed_tensor_dict, fetch_var_names)._move_to_list()
return as_numpy(
fetch_tensors) if return_numpy else fetch_tensors
else:
exe.feed_and_split_tensor_into_local_scopes(feed_tensor_dict)
elif isinstance(feed, list) or isinstance(feed, tuple):
res = list()
for i, each in enumerate(feed):
......@@ -1047,7 +1038,6 @@ class Executor(object):
res_dict[feed_name] = tensor
res.append(res_dict)
use_cinn = get_flags("FLAGS_use_cinn")["FLAGS_use_cinn"]
exe.feed_tensors_into_local_scopes(res)
if hasattr(program._program, 'lr_sheduler'):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册