You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

init.cc 23 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <pybind11/operators.h>
  17. #include "backend/kernel_compiler/oplib/oplib.h"
  18. #include "backend/kernel_compiler/oplib/oploader.h"
  19. #include "pipeline/jit/pipeline.h"
  20. #include "frontend/operator/composite/composite.h"
  21. #include "pipeline/pynative/pynative_execute.h"
  22. #include "utils/symbolic.h"
  23. #include "pybind_api/api_register.h"
  24. #include "pipeline/jit/parse/python_adapter.h"
  25. #include "utils/summary/event_writer.h"
  26. #include "utils/config_manager.h"
  27. #include "utils/mpi/mpi_config.h"
  28. #include "frontend/parallel/context.h"
  29. #include "frontend/parallel/costmodel_context.h"
  30. #ifdef ENABLE_GPU_COLLECTIVE
  31. #include "runtime/device/gpu/distribution/collective_init.h"
  32. #else
  33. #include "runtime/device/gpu/distribution/collective_fake_init.h"
  34. #endif
  35. #if (ENABLE_CPU && (ENABLE_D || ENABLE_GPU))
  36. #include "ps/util.h"
  37. #endif
  38. #include "ps/ps_context.h"
  39. #include "pybind_api/gil_scoped_long_running.h"
  40. namespace py = pybind11;
  41. using EnvInstance = mindspore::EnvInstance;
  42. using ExecutorPy = mindspore::pipeline::ExecutorPy;
  43. using Pipeline = mindspore::pipeline::Pipeline;
  44. using PrimitivePy = mindspore::PrimitivePy;
  45. using MetaFuncGraph = mindspore::MetaFuncGraph;
  46. using EventWriter = mindspore::summary::EventWriter;
  47. using OpLib = mindspore::kernel::OpLib;
  48. using OpInfoLoaderPy = mindspore::kernel::OpInfoLoaderPy;
  49. using ParallelContext = mindspore::parallel::ParallelContext;
  50. using CostModelContext = mindspore::parallel::CostModelContext;
  51. using mindspore::MsCtxParam;
  52. using PSContext = mindspore::ps::PSContext;
  53. // Interface with python
  54. PYBIND11_MODULE(_c_expression, m) {
  55. m.doc() = "MindSpore c plugin";
  56. auto fns = mindspore::PybindDefineRegister::AllFuncs();
  57. for (auto &item : fns) {
  58. item.second(&m);
  59. }
  60. mindspore::ScopedLongRunning::SetHook(std::make_unique<mindspore::GilScopedLongRunningHook>());
  61. // Class Pipeline interface
  62. (void)py::class_<ExecutorPy, std::shared_ptr<ExecutorPy>>(m, "Executor_")
  63. .def_static("get_instance", &ExecutorPy::GetInstance, "Executor get_instance.")
  64. .def("__call__", &ExecutorPy::Run, py::arg("args"), py::arg("phase") = py::str(""), "Executor run function.")
  65. .def("del_net_res", &ExecutorPy::DelNetRes, py::arg("network_id") = py::str(""), "Delete network resource.")
  66. .def("get_func_graph", &ExecutorPy::GetFuncGraph, py::arg("phase") = py::str(""), "Get graph pointer.")
  67. .def("get_func_graph_proto", &ExecutorPy::GetFuncGraphProto, py::arg("phase") = py::str(""),
  68. py::arg("type") = py::str("onnx_ir"), "Get graph proto string by specifying ir type.")
  69. .def("compile", &ExecutorPy::Compile, py::arg("obj"), py::arg("args"), py::arg("phase") = py::str(""),
  70. py::arg("use_vm") = py::bool_(false), "Compile obj by executor.")
  71. .def("updata_param_node_default_input", &ExecutorPy::UpdataParamNodeDefaultInput, py::arg("phase"),
  72. py::arg("params"), "Fetch the inputs of Conv or Matmul for quant export.")
  73. .def("get_parameter_layout", &ExecutorPy::GetParameterLayout, py::arg("phase") = py::str("train"),
  74. "Get Parameter Tensor Layout Dictionary.")
  75. .def("get_parallel_parameter_name_list", &ExecutorPy::GetParallelParameterNameList,
  76. py::arg("phase") = py::str("train"), "Get Parallel Parameter Name List.")
  77. .def("get_strategy", &ExecutorPy::GetCNodeStrategy, py::arg("phase") = py::str("train"),
  78. "Get CNode Strategy Dictionary.")
  79. .def("get_num_parallel_ops", &ExecutorPy::GetNumOpsInfo, py::arg("phase") = py::str("train"),
  80. "Get the number of parallel operators.")
  81. .def("get_allreduce_fusion", &ExecutorPy::GetAllreduceFusion, py::arg("phase") = py::str("train"),
  82. "Get Allreduce Fusion Dictionary.")
  83. .def("fetch_info_for_quant_export", &ExecutorPy::FetchInfoForQuantExport, py::arg("phase") = py::str("train"),
  84. "Fetch the inputs of Conv or Matmul for quant export.")
  85. .def("build_data_graph", &ExecutorPy::BuildGraph, py::arg("build_params"), py::arg("phase") = py::str("train"),
  86. py::arg("broadcast_params") = py::dict(), "Build data graph.")
  87. .def("has_compiled", &ExecutorPy::HasCompiled, py::arg("phase") = py::str(""), "get if cell compiled.")
  88. .def("run_init_graph", &ExecutorPy::RunInitGraph, "Run init Graph.")
  89. .def("set_py_exe_path", &ExecutorPy::PyExePath, py::arg("phase") = py::str(""), "set python executable path.");
  90. (void)py::class_<EnvInstance, std::shared_ptr<EnvInstance>>(m, "EnvInstance_").def(py::init());
  91. (void)m.def("generate_key", &mindspore::pipeline::GenerateKey, "Generate the function graph key.");
  92. (void)m.def("real_run_op", &mindspore::pynative::RunOp, "Run op pynatively.");
  93. (void)m.def("reset_op_id", &mindspore::pipeline::ResetOpId, "Reset Operator Id");
  94. (void)m.def("init_hccl", &mindspore::pipeline::InitHccl, "Init Hccl");
  95. (void)m.def("finalize_hccl", &mindspore::pipeline::FinalizeHccl, "Finalize Hccl");
  96. (void)m.def("verify_inputs_signature", &mindspore::pipeline::VerifyInputSignature, "Verify input signature.");
  97. (void)m.def("init_exec_dataset", &mindspore::pipeline::InitExecDataset, py::arg("queue_name"), py::arg("size"),
  98. py::arg("batch_size"), py::arg("types"), py::arg("shapes"), py::arg("input_indexs"),
  99. py::arg("phase") = py::str("dataset"), py::arg("need_run") = py::bool_(true), "Init and exec dataset.");
  100. (void)m.def("_set_dataset_mode_config", &mindspore::ConfigManager::SetDatasetModeConfig, "API for set dataset mode.");
  101. (void)m.def("init_pipeline", &mindspore::pipeline::InitPipeline, "Init Pipeline.");
  102. (void)m.def("export_graph", &mindspore::pipeline::ExportGraph, "Export Graph.");
  103. (void)py::class_<mindspore::MpiConfig, std::shared_ptr<mindspore::MpiConfig>>(m, "MpiConfig")
  104. .def_static("get_instance", &mindspore::MpiConfig::GetInstance, "Get mpi config instance.")
  105. .def("get_enable_mpi", &mindspore::MpiConfig::enable_mpi, "Get whether enable mpi.")
  106. .def("set_enable_mpi", &mindspore::MpiConfig::set_enable_mpi, "Set whether to enable mpi.");
  107. (void)py::class_<ParallelContext, std::shared_ptr<ParallelContext>>(m, "AutoParallelContext")
  108. .def_static("get_instance", &ParallelContext::GetInstance, "Get auto parallel context instance.")
  109. .def("get_device_num", &ParallelContext::device_num, "Get device num.")
  110. .def("set_device_num", &ParallelContext::set_device_num, "Set device num.")
  111. .def("get_device_num_is_set", &ParallelContext::device_num_is_set, "Get device num is set.")
  112. .def("get_global_rank", &ParallelContext::global_rank, "Get global rank.")
  113. .def("set_global_rank", &ParallelContext::set_global_rank, "Set global rank.")
  114. .def("get_global_rank_is_set", &ParallelContext::global_rank_is_set, "Get global rank is set.")
  115. .def("get_gradients_mean", &ParallelContext::gradients_mean, "Get mirror mean.")
  116. .def("set_gradients_mean", &ParallelContext::set_gradients_mean, "Set mirror mean.")
  117. .def("get_gradient_fp32_sync", &ParallelContext::gradient_fp32_sync, "Get cast before mirror.")
  118. .def("set_gradient_fp32_sync", &ParallelContext::set_gradient_fp32_sync, "Set cast before mirror.")
  119. .def("get_loss_repeated_mean", &ParallelContext::loss_repeated_mean, "Get loss repeated mean.")
  120. .def("set_loss_repeated_mean", &ParallelContext::set_loss_repeated_mean, "Set loss repeated mean.")
  121. .def("get_parallel_mode", &ParallelContext::parallel_mode, "Get parallel mode.")
  122. .def("set_parallel_mode", &ParallelContext::set_parallel_mode, "Set parallel mode.")
  123. .def("get_grad_accumulation_step", &ParallelContext::grad_accumulation_step, "Get grad accumulation step.")
  124. .def("set_grad_accumulation_step", &ParallelContext::set_grad_accumulation_step, "Set grad accumulation step.")
  125. .def("get_strategy_search_mode", &ParallelContext::strategy_search_mode, "Get strategy search mode.")
  126. .def("set_strategy_search_mode", &ParallelContext::set_strategy_search_mode, "Set strategy search mode.")
  127. .def("set_all_reduce_fusion_split_indices", &ParallelContext::SetAllReduceFusionSplitIndices,
  128. "Set all reduce fusion split indices.")
  129. .def("get_all_reduce_fusion_split_indices", &ParallelContext::GetAllReduceFusionSplitIndices,
  130. "Get all reduce fusion split indices.")
  131. .def("set_all_reduce_fusion_split_sizes", &ParallelContext::SetAllReduceFusionSplitSizes,
  132. "Set all reduce fusion split sizes.")
  133. .def("get_all_reduce_fusion_split_sizes", &ParallelContext::GetAllReduceFusionSplitSizes,
  134. "Get all reduce fusion split sizes.")
  135. .def("set_enable_all_reduce_fusion", &ParallelContext::set_enable_all_reduce_fusion,
  136. "Set enable/disable all reduce fusion.")
  137. .def("get_enable_all_reduce_fusion", &ParallelContext::enable_all_reduce_fusion,
  138. "Get enable/disable all reduce fusion.")
  139. .def("get_parameter_broadcast", &ParallelContext::parameter_broadcast, "Get parameter broadcast.")
  140. .def("get_parameter_broadcast_is_set", &ParallelContext::parameter_broadcast_is_set,
  141. "Get parameter broadcast is set.")
  142. .def("set_parameter_broadcast", &ParallelContext::set_parameter_broadcast, "Set parameter broadcast.")
  143. .def("set_strategy_ckpt_load_file", &ParallelContext::set_strategy_ckpt_load_file,
  144. "Set strategy checkpoint load file.")
  145. .def("set_strategy_ckpt_save_file", &ParallelContext::set_strategy_ckpt_save_file,
  146. "Set strategy checkpoint save file.")
  147. .def("get_strategy_ckpt_load_file", &ParallelContext::strategy_ckpt_load_file, "Get strategy checkpoint load file.")
  148. .def("get_strategy_ckpt_save_file", &ParallelContext::strategy_ckpt_save_file, "Get strategy checkpoint save file.")
  149. .def("set_group_ckpt_save_file", &ParallelContext::set_group_ckpt_save_file, "Set group checkpoint save file.")
  150. .def("set_pipeline_stage_split_num", &ParallelContext::set_pipeline_stage_split_num,
  151. "Set pipeline stage split num.")
  152. .def("get_pipeline_stage_split_num", &ParallelContext::pipeline_stage_split_num, "Get pipeline stage split num.")
  153. .def("set_full_batch", &ParallelContext::set_full_batch, "Set whether load full batch on each device.")
  154. .def("get_full_batch", &ParallelContext::full_batch, "Get whether load full batch on each device.")
  155. .def("set_enable_parallel_optimizer", &ParallelContext::set_enable_parallel_optimizer,
  156. "Set enable/disable parallel optimizer.")
  157. .def("get_enable_parallel_optimizer", &ParallelContext::enable_parallel_optimizer,
  158. "Get enable/disable parallel optimizer.")
  159. .def("reset", &ParallelContext::Reset, "Reset auto parallel context.");
  160. (void)py::class_<CostModelContext, std::shared_ptr<CostModelContext>>(m, "CostModelContext")
  161. .def_static("get_instance", &CostModelContext::GetInstance, "Get cost_model context instance.")
  162. .def("set_device_memory_capacity", &CostModelContext::set_device_memory_capacity,
  163. "Set the capacity of device memory.")
  164. .def("get_device_memory_capacity", &CostModelContext::device_memory_capacity, "Get the capacity of device memory.")
  165. .def("set_costmodel_alpha", &CostModelContext::set_costmodel_alpha,
  166. "Set the parameter cost_model_alpha of the DP algorithm.")
  167. .def("get_costmodel_alpha", &CostModelContext::costmodel_alpha,
  168. "Get the parameter cost_model_alpha of the DP algorithm.")
  169. .def("set_costmodel_beta", &CostModelContext::set_costmodel_beta,
  170. "Set the parameter cost_model_beta of the DP algorithm.")
  171. .def("get_costmodel_beta", &CostModelContext::costmodel_beta,
  172. "Get the parameter cost_model_beta of the DP algorithm.")
  173. .def("set_costmodel_gamma", &CostModelContext::set_costmodel_gamma,
  174. "Set the parameter cost_model_gamma of the DP algorithm")
  175. .def("get_costmodel_gamma", &CostModelContext::costmodel_gamma,
  176. "Get the parameter cost_model_gamma of the DP algorithm.")
  177. .def("set_costmodel_communi_threshold", &CostModelContext::set_costmodel_communi_threshold,
  178. "Set the parameter cost_model_communi_threshold of the DP algorithm.")
  179. .def("get_costmodel_communi_threshold", &CostModelContext::costmodel_communi_threshold,
  180. "Get the parameter cost_model_communi_threshold of the DP algorithm.")
  181. .def("set_costmodel_communi_const", &CostModelContext::set_costmodel_communi_const,
  182. "Set the parameter cost_model_communi_const of the DP algorithm.")
  183. .def("get_costmodel_communi_const", &CostModelContext::costmodel_communi_const,
  184. "Get the parameter cost_model_communi_const of the DP algorithm.")
  185. .def("set_costmodel_communi_bias", &CostModelContext::set_costmodel_communi_bias,
  186. "Set the parameter cost_model_communi_bias of the DP algorithm.")
  187. .def("get_costmodel_communi_bias", &CostModelContext::costmodel_communi_bias,
  188. "Get the parameter cost_model_communi_bias of the DP algorithm.")
  189. .def("set_multi_subgraphs", &CostModelContext::set_multi_subgraphs, "Set the parameter is_multi_subgraphs.")
  190. .def("get_multi_subgraphs", &CostModelContext::is_multi_subgraphs, "Get the parameter is_multi_subgraphs.")
  191. .def("set_run_phase", &CostModelContext::set_run_phase, "Set the flag run_phase.")
  192. .def("get_run_phase", &CostModelContext::run_phase, "Get the flag run_phase.")
  193. .def("set_costmodel_allreduce_fusion_algorithm", &CostModelContext::set_costmodel_allreduce_fusion_algorithm,
  194. "Set the parameter gradient AllReduce fusion algorithm.")
  195. .def("get_costmodel_allreduce_fusion_algorithm", &CostModelContext::costmodel_allreduce_fusion_algorithm,
  196. "Get the parameter gradient AllReduce fusion algorithm.")
  197. .def("set_costmodel_allreduce_fusion_times", &CostModelContext::set_costmodel_allreduce_fusion_times,
  198. "Set the parameter gradient AllReduce times.")
  199. .def("get_costmodel_allreduce_fusion_times", &CostModelContext::costmodel_allreduce_fusion_times,
  200. "Get the parameter gradient AllReduce times.")
  201. .def("set_costmodel_allreduce_fusion_tail_percent", &CostModelContext::set_costmodel_allreduce_fusion_tail_percent,
  202. "Set the parameter gradient AllReduce fusion tail percent.")
  203. .def("get_costmodel_allreduce_fusion_tail_percent", &CostModelContext::costmodel_allreduce_fusion_tail_percent,
  204. "Get the parameter gradient AllReduce fusion tail percent.")
  205. .def("set_costmodel_allreduce_fusion_tail_time", &CostModelContext::set_costmodel_allreduce_fusion_tail_time,
  206. "Set the parameter gradient AllReduce fusion tail time.")
  207. .def("get_costmodel_allreduce_fusion_tail_time", &CostModelContext::costmodel_allreduce_fusion_tail_time,
  208. "Get the parameter gradient AllReduce fusion tail time.")
  209. .def("set_costmodel_allreduce_fusion_allreduce_inherent_time",
  210. &CostModelContext::set_costmodel_allreduce_fusion_allreduce_inherent_time,
  211. "Set the parameter gradient AllReduce fusion allreduce inherent time.")
  212. .def("get_costmodel_allreduce_fusion_allreduce_inherent_time",
  213. &CostModelContext::costmodel_allreduce_fusion_allreduce_inherent_time,
  214. "Get the parameter gradient AllReduce fusion allreduce inherent time.")
  215. .def("set_costmodel_allreduce_fusion_allreduce_bandwidth",
  216. &CostModelContext::set_costmodel_allreduce_fusion_allreduce_bandwidth,
  217. "Set the parameter gradient AllReduce fusion allreduce bandwidth.")
  218. .def("get_costmodel_allreduce_fusion_allreduce_bandwidth",
  219. &CostModelContext::costmodel_allreduce_fusion_allreduce_bandwidth,
  220. "Get the parameter gradient AllReduce fusion allreduce bandwidth.")
  221. .def("set_costmodel_allreduce_fusion_computation_time_parameter",
  222. &CostModelContext::set_costmodel_allreduce_fusion_computation_time_parameter,
  223. "Set the parameter gradient AllReduce fusion computation time parameter.")
  224. .def("get_costmodel_allreduce_fusion_computation_time_parameter",
  225. &CostModelContext::costmodel_allreduce_fusion_computation_time_parameter,
  226. "Get the parameter gradient AllReduce fusion computation time parameter.")
  227. .def("set_tensor_slice_align_enable", &CostModelContext::set_tensor_slice_alignment_enable,
  228. "Set the parameter tensor_slice_align_enable in strategy generation.")
  229. .def("get_tensor_slice_align_enable", &CostModelContext::tensor_slice_alignment_enable,
  230. "Get the parameter tensor_slice_align_enable in strategy generation.")
  231. .def("set_tensor_slice_align_size", &CostModelContext::set_tensor_slice_alignment_size,
  232. "Set the parameter tensor_slice_size in strategy generation.")
  233. .def("get_tensor_slice_align_size", &CostModelContext::tensor_slice_alignment_size,
  234. "Get the parameter tensor_slice_size in strategy generation.")
  235. .def("set_fully_use_devices", &CostModelContext::set_fully_use_device,
  236. "Set the parameter fully_use_devices in the DP algorithm.")
  237. .def("get_fully_use_devices", &CostModelContext::fully_use_device,
  238. "Get the parameter fully_use_devices in the DP algorithm.")
  239. .def("set_elementwise_op_strategy_follow", &CostModelContext::set_elementwise_stra_follow,
  240. "Set the parameter elementwise_op_strategy_follow in the DP algorithm.")
  241. .def("get_elementwise_op_strategy_follow", &CostModelContext::elementwise_stra_follow,
  242. "Get the parameter elementwise_op_strategy_follow in the DP algorithm.")
  243. .def("set_dp_algo_enable_approxi", &CostModelContext::set_dp_algo_enable_approxi,
  244. "Set the flag whether enabling approximation in the DP algorithm.")
  245. .def("get_dp_algo_enable_approxi", &CostModelContext::dp_algo_enable_approxi,
  246. "Get the flag whether enabling approximation in the DP algorithm.")
  247. .def("set_dp_algo_approxi_epsilon", &CostModelContext::set_dp_algo_approxi_epsilon,
  248. "Set the epsilon which is used in the approximation of DP algorithm.")
  249. .def("get_dp_algo_approxi_epsilon", &CostModelContext::dp_algo_approxi_epsilon,
  250. "Get the epsilon which is used in the approximation of DP algorithm.")
  251. .def("set_dp_algo_single_loop", &CostModelContext::set_dp_algo_single_loop,
  252. "Set the flag of generating a single suite of OperatorInfos in for-loop.")
  253. .def("get_dp_algo_single_loop", &CostModelContext::dp_algo_single_loop,
  254. "Get the flag of whether or not generating a single suite of OperatorInfos in for-loop.")
  255. .def("reset_cost_model", &CostModelContext::ResetCostModel, "Reset the CostModelContext.")
  256. .def("reset_algo_parameters", &CostModelContext::ResetAlgoParameters, "Reset the AlgoParameters.");
  257. (void)py::module::import("atexit").attr("register")(py::cpp_function{[&]() -> void {
  258. // only in case that c++ calling python interface, ClearResAtexit should be called.
  259. if (mindspore::parse::python_adapter::IsPythonEnv()) {
  260. mindspore::pipeline::ClearResAtexit();
  261. #ifdef ENABLE_MINDDATA
  262. py::module iterators = py::module::import("mindspore.dataset.engine.iterators");
  263. (void)iterators.attr("_cleanup")();
  264. #endif
  265. }
  266. }});
  267. (void)py::class_<EventWriter, std::shared_ptr<EventWriter>>(m, "EventWriter_")
  268. .def(py::init<const std::string &>())
  269. .def("GetFileName", &EventWriter::GetFileName, "Get the file name.")
  270. .def("Open", &EventWriter::Open, "Open the write file.")
  271. .def("Write", &EventWriter::Write, "Write the serialize event.")
  272. .def("EventCount", &EventWriter::GetWriteEventCount, "Write event count.")
  273. .def("Flush", &EventWriter::Flush, "Flush the event.")
  274. .def("Close", &EventWriter::Close, "Close the write.")
  275. .def("Shut", &EventWriter::Shut, "Final close the write.");
  276. (void)py::class_<OpLib, std::shared_ptr<OpLib>>(m, "Oplib")
  277. .def(py::init())
  278. .def_static("reg_op", &OpLib::RegOp, "Register op info.");
  279. #ifdef ENABLE_GPU_COLLECTIVE
  280. (void)m.def("init_gpu_collective", &mindspore::device::gpu::CollectiveInitializer::InitCollective,
  281. "Init gpu collective communication mode.");
  282. (void)m.def("finalize_gpu_collective", &mindspore::device::gpu::CollectiveInitializer::FinalizeCollective,
  283. "Finalize gpu collective communication mode.");
  284. #else
  285. (void)m.def("init_gpu_collective", &mindspore::device::gpu::CollectiveFakeInitializer::InitCollective,
  286. "Init gpu collective communication mode.");
  287. (void)m.def("finalize_gpu_collective", &mindspore::device::gpu::CollectiveFakeInitializer::FinalizeCollective,
  288. "Finalize gpu collective communication mode.");
  289. #endif
  290. (void)py::class_<PSContext, std::shared_ptr<PSContext>>(m, "PSContext")
  291. .def_static("get_instance", &PSContext::instance, "Get PS context instance.")
  292. .def("set_ps_enable", &PSContext::SetPSEnable, "Set PS mode enabled or disabled.")
  293. .def("is_ps_enabled", &PSContext::is_ps_enabled, "Get PS mode enable-disable status.")
  294. .def("reset", &PSContext::Reset, "Reset PS context attributes.")
  295. .def("is_role_worker", &PSContext::is_role_worker, "Get whether the role of this process is Worker.")
  296. .def("is_role_pserver", &PSContext::is_role_pserver, "Get whether the role of this process is PServer.")
  297. .def("is_role_sched", &PSContext::is_role_sched, "Get whether the role of this process is Scheduler.")
  298. .def("ps_rank_id", &PSContext::ps_rank_id, "Get Worker and PServer rank id.")
  299. .def("insert_hash_table_size", &PSContext::InsertHashTableSize, "Insert hash table size.")
  300. .def("reinsert_hash_table_size", &PSContext::ReInsertHashTableSize,
  301. "Insert hash table size with new parameter name.")
  302. .def("insert_weight_init_info", &PSContext::InsertWeightInitInfo, "Insert embedding table initialization seed.")
  303. .def("insert_accumu_init_info", &PSContext::InsertAccumuInitInfo, "Insert accumulation initialization value.")
  304. .def("clone_hash_table", &PSContext::CloneHashTable, "Clone a hash table.")
  305. .def("set_cache_enable", &PSContext::set_cache_enable, "Set ps mode cache enable or not.")
  306. .def("set_rank_id", &PSContext::set_rank_id, "Set rank id for worker on ps mode.");
  307. (void)py::class_<OpInfoLoaderPy, std::shared_ptr<OpInfoLoaderPy>>(m, "OpInfoLoaderPy")
  308. .def(py::init())
  309. .def("get_all_ops_info", &OpInfoLoaderPy::GetAllOpsInfo, "get all ops info.");
  310. }