From: @liubuyu Reviewed-by: Signed-off-by:tags/v1.1.0
| @@ -25,14 +25,28 @@ | |||||
| #include "common/duplex_pipe.h" | #include "common/duplex_pipe.h" | ||||
| #include "utils/log_adapter.h" | #include "utils/log_adapter.h" | ||||
| #include "utils/ms_context.h" | |||||
| namespace mindspore { | namespace mindspore { | ||||
| namespace kernel { | namespace kernel { | ||||
| void ReplaceStr(std::string *dest, const std::string &replace, char new_char); | void ReplaceStr(std::string *dest, const std::string &replace, char new_char); | ||||
| constexpr inline static int kBufferSize = 4096; | constexpr inline static int kBufferSize = 4096; | ||||
| constexpr inline static auto kEnv = "python"; | |||||
| // The TAG as prefix of real command from remote. | // The TAG as prefix of real command from remote. | ||||
| constexpr inline static auto kTag = "[~]"; | constexpr inline static auto kTag = "[~]"; | ||||
| static std::string GetPyExe() { | |||||
| // get real python executable path | |||||
| auto ms_context = MsContext::GetInstance(); | |||||
| if (ms_context == nullptr) { | |||||
| return kEnv; | |||||
| } | |||||
| auto env = ms_context->get_param<std::string>(MS_CTX_PYTHON_EXE_PATH); | |||||
| if (env.empty()) { | |||||
| return kEnv; | |||||
| } | |||||
| return env; | |||||
| } | |||||
| class KernelBuildClient { | class KernelBuildClient { | ||||
| public: | public: | ||||
| @@ -164,7 +178,6 @@ static std::string GetScriptFilePath(const std::string cmd_env, const std::strin | |||||
| class AscendKernelBuildClient : public KernelBuildClient { | class AscendKernelBuildClient : public KernelBuildClient { | ||||
| public: | public: | ||||
| // Server configure | // Server configure | ||||
| constexpr inline static auto kEnv = "python"; | |||||
| constexpr inline static auto kGetPathScript = | constexpr inline static auto kGetPathScript = | ||||
| "-c " | "-c " | ||||
| "\"" | "\"" | ||||
| @@ -196,9 +209,12 @@ class AscendKernelBuildClient : public KernelBuildClient { | |||||
| return instance; | return instance; | ||||
| } | } | ||||
| std::string GetEnv() override { return kEnv; } | |||||
| std::string GetEnv() override { return GetPyExe(); } | |||||
| std::string GetScript() override { return GetScriptFilePath(kEnv, kGetPathScript); } | |||||
| std::string GetScript() override { | |||||
| auto env = GetPyExe(); | |||||
| return GetScriptFilePath(env, kGetPathScript); | |||||
| } | |||||
| // Before building. | // Before building. | ||||
| std::string SelectFormat(const std::string &json); | std::string SelectFormat(const std::string &json); | ||||
| @@ -229,7 +245,6 @@ class AscendKernelBuildClient : public KernelBuildClient { | |||||
| class GpuKernelBuildClient : public KernelBuildClient { | class GpuKernelBuildClient : public KernelBuildClient { | ||||
| public: | public: | ||||
| // Server configure | // Server configure | ||||
| constexpr inline static auto kEnv = "python"; | |||||
| constexpr inline static auto kGetPathScript = | constexpr inline static auto kGetPathScript = | ||||
| "-c " | "-c " | ||||
| "\"" | "\"" | ||||
| @@ -249,9 +264,12 @@ class GpuKernelBuildClient : public KernelBuildClient { | |||||
| return instance; | return instance; | ||||
| } | } | ||||
| std::string GetEnv() override { return kEnv; } | |||||
| std::string GetEnv() override { return GetPyExe(); } | |||||
| std::string GetScript() override { return GetScriptFilePath(kEnv, kGetPathScript); } | |||||
| std::string GetScript() override { | |||||
| auto env = GetPyExe(); | |||||
| return GetScriptFilePath(env, kGetPathScript); | |||||
| } | |||||
| // Fetch pid(pid_t) from remote. | // Fetch pid(pid_t) from remote. | ||||
| int AkgGetPid(); | int AkgGetPid(); | ||||
| @@ -91,7 +91,8 @@ PYBIND11_MODULE(_c_expression, m) { | |||||
| .def("build_data_graph", &ExecutorPy::BuildGraph, py::arg("build_params"), py::arg("phase") = py::str("train"), | .def("build_data_graph", &ExecutorPy::BuildGraph, py::arg("build_params"), py::arg("phase") = py::str("train"), | ||||
| py::arg("broadcast_params") = py::dict(), "Build data graph.") | py::arg("broadcast_params") = py::dict(), "Build data graph.") | ||||
| .def("has_compiled", &ExecutorPy::HasCompiled, py::arg("phase") = py::str(""), "get if cell compiled.") | .def("has_compiled", &ExecutorPy::HasCompiled, py::arg("phase") = py::str(""), "get if cell compiled.") | ||||
| .def("run_init_graph", &ExecutorPy::RunInitGraph, "Run init Graph."); | |||||
| .def("run_init_graph", &ExecutorPy::RunInitGraph, "Run init Graph.") | |||||
| .def("set_py_exe_path", &ExecutorPy::PyExePath, py::arg("phase") = py::str(""), "set python executable path."); | |||||
| (void)py::class_<EnvInstance, std::shared_ptr<EnvInstance>>(m, "EnvInstance_").def(py::init()); | (void)py::class_<EnvInstance, std::shared_ptr<EnvInstance>>(m, "EnvInstance_").def(py::init()); | ||||
| @@ -895,6 +895,15 @@ void ExecutorPy::RunInitGraph(const py::dict &init_params, const std::string &ph | |||||
| #endif | #endif | ||||
| } | } | ||||
| void ExecutorPy::PyExePath(const py::object &py_exe_path) { | |||||
| if (!py::isinstance<py::str>(py_exe_path)) { | |||||
| MS_LOG(EXCEPTION) << "Failed, phase input is not a str"; | |||||
| } | |||||
| auto py_exe_path_s = py::cast<std::string>(py_exe_path); | |||||
| auto ms_context = MsContext::GetInstance(); | |||||
| ms_context->set_param<std::string>(MS_CTX_PYTHON_EXE_PATH, py_exe_path_s); | |||||
| } | |||||
| bool InitExecDataset(const std::string &queue_name, int64_t iter_num, int64_t batch_size, | bool InitExecDataset(const std::string &queue_name, int64_t iter_num, int64_t batch_size, | ||||
| const std::vector<TypePtr> &types, const std::vector<std::vector<int64_t>> &shapes, | const std::vector<TypePtr> &types, const std::vector<std::vector<int64_t>> &shapes, | ||||
| const std::vector<int64_t> &input_indexes, const std::string &phase, bool need_run) { | const std::vector<int64_t> &input_indexes, const std::string &phase, bool need_run) { | ||||
| @@ -90,6 +90,7 @@ class ExecutorPy : public std::enable_shared_from_this<ExecutorPy> { | |||||
| void UpdataParamNodeDefaultInput(const std::string &phase, | void UpdataParamNodeDefaultInput(const std::string &phase, | ||||
| const std::unordered_map<std::string, tensor::TensorPtr> ¶ms); | const std::unordered_map<std::string, tensor::TensorPtr> ¶ms); | ||||
| void RunInitGraph(const py::dict &init_params, const std::string &phase); | void RunInitGraph(const py::dict &init_params, const std::string &phase); | ||||
| void PyExePath(const py::object &phase); | |||||
| py::dict GetParameterLayout(const std::string &phase); | py::dict GetParameterLayout(const std::string &phase); | ||||
| py::dict GetCNodeStrategy(const std::string &phase); | py::dict GetCNodeStrategy(const std::string &phase); | ||||
| void SetCNodeStrategy(const std::string &name, const parallel::Strategys &strategy); | void SetCNodeStrategy(const std::string &name, const parallel::Strategys &strategy); | ||||
| @@ -16,6 +16,7 @@ | |||||
| # ============================================================================ | # ============================================================================ | ||||
| """Providing interface methods.""" | """Providing interface methods.""" | ||||
| import types | import types | ||||
| import sys | |||||
| from collections import OrderedDict | from collections import OrderedDict | ||||
| from functools import wraps | from functools import wraps | ||||
| @@ -340,6 +341,7 @@ class _Executor: | |||||
| self.is_init = False | self.is_init = False | ||||
| self._executor = Executor_.get_instance() | self._executor = Executor_.get_instance() | ||||
| self.compile_cache = {} | self.compile_cache = {} | ||||
| self._executor.set_py_exe_path(sys.executable) | |||||
| def init_dataset(self, queue_name, dataset_size, batch_size, dataset_types, dataset_shapes, | def init_dataset(self, queue_name, dataset_size, batch_size, dataset_types, dataset_shapes, | ||||
| input_indexs, phase='dataset'): | input_indexs, phase='dataset'): | ||||
| @@ -34,6 +34,7 @@ std::map<std::string, MsBackendPolicy> MsContext::policy_map_ = {{"ge", kMsBacke | |||||
| MsContext::MsContext(const std::string &policy, const std::string &target) { | MsContext::MsContext(const std::string &policy, const std::string &target) { | ||||
| set_param<bool>(MS_CTX_SAVE_GRAPHS_FLAG, false); | set_param<bool>(MS_CTX_SAVE_GRAPHS_FLAG, false); | ||||
| set_param<std::string>(MS_CTX_SAVE_GRAPHS_PATH, "."); | set_param<std::string>(MS_CTX_SAVE_GRAPHS_PATH, "."); | ||||
| set_param<std::string>(MS_CTX_PYTHON_EXE_PATH, "python"); | |||||
| set_param<bool>(MS_CTX_ENABLE_DUMP, false); | set_param<bool>(MS_CTX_ENABLE_DUMP, false); | ||||
| set_param<std::string>(MS_CTX_SAVE_DUMP_PATH, "."); | set_param<std::string>(MS_CTX_SAVE_DUMP_PATH, "."); | ||||
| set_param<uint32_t>(MS_CTX_TSD_REF, 0); | set_param<uint32_t>(MS_CTX_TSD_REF, 0); | ||||
| @@ -102,6 +102,7 @@ enum MsCtxParam : unsigned { | |||||
| MS_CTX_SAVE_DUMP_PATH, | MS_CTX_SAVE_DUMP_PATH, | ||||
| MS_CTX_SAVE_GRAPHS_PATH, | MS_CTX_SAVE_GRAPHS_PATH, | ||||
| MS_CTX_VARIABLE_MEMORY_MAX_SIZE, | MS_CTX_VARIABLE_MEMORY_MAX_SIZE, | ||||
| MS_CTX_PYTHON_EXE_PATH, | |||||
| MS_CTX_TYPE_STRING_END, | MS_CTX_TYPE_STRING_END, | ||||
| // parameter numbers of each type | // parameter numbers of each type | ||||