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.

step_auto_parallel.cc 42 kB

6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  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 "parallel/step_auto_parallel.h"
  17. #include <inttypes.h>
  18. #include <sys/time.h>
  19. #include <algorithm>
  20. #include <map>
  21. #include <memory>
  22. #include <set>
  23. #include <string>
  24. #include <unordered_map>
  25. #include <utility>
  26. #include <vector>
  27. #include "ir/anf.h"
  28. #include "ir/meta_tensor.h"
  29. #include "optimizer/opt.h"
  30. #include "optimizer/optimizer.h"
  31. #include "parallel/auto_parallel/dp_algo_costmodel.h"
  32. #include "parallel/auto_parallel/edge_costmodel.h"
  33. #include "parallel/auto_parallel/graph_costmodel.h"
  34. #include "parallel/auto_parallel/rec_core/rec_generate_strategy.h"
  35. #include "parallel/auto_parallel/rec_core/rec_parse_graph.h"
  36. #include "parallel/auto_parallel/rec_core/rec_partition.h"
  37. #include "parallel/context.h"
  38. #include "parallel/ops_info/tmp_identity_info.h"
  39. #include "parallel/step_parallel.h"
  40. #include "pipeline/parse/python_adapter.h"
  41. #include "pipeline/pipeline.h"
  42. namespace mindspore {
  43. namespace parallel {
  44. // splittable_op_ will continuously be updated
  45. std::vector<std::string> splittable_op_ = {MATMUL,
  46. GELU,
  47. TANH,
  48. SOFTMAX,
  49. LOG_SOFTMAX,
  50. ACTIVATION,
  51. PRELU,
  52. FLOORDIV,
  53. L2_NORMALIZE,
  54. TRANSPOSE,
  55. RESHAPE,
  56. TENSOR_ADD,
  57. SUB,
  58. MUL,
  59. DIV,
  60. GREATER,
  61. MAXPOOL,
  62. MAXPOOLV2,
  63. VIRTUAL_DATA_SET,
  64. SPARSE_SOFTMAX_CROSS_ENTROPY_WITH_LOGITS,
  65. RELU,
  66. ONEHOT,
  67. DROPOUT_DO_MASK,
  68. REDUCE_MAX,
  69. REDUCE_MIN,
  70. ARGMAXWITHVALUE,
  71. ARGMINWITHVALUE,
  72. REDUCE_SUM,
  73. CONV2D,
  74. FUSE_BATCH_NORM,
  75. POOLING,
  76. SOFTMAX_CROSS_ENTROPY_WITH_LOGITS,
  77. SIGMOID_CROSS_ENTROPY_WITH_LOGITS,
  78. MAX_POOL_WITH_ARGMAX,
  79. SIMPLE_MEAN,
  80. FLATTEN,
  81. BATCH_NORM,
  82. LAYER_NORM,
  83. BIAS_ADD,
  84. ASSIGN_SUB,
  85. COS,
  86. ACOS,
  87. EXP,
  88. LOG,
  89. REDUCE_MEAN,
  90. REAL_DIV,
  91. SIGMOID,
  92. POW,
  93. MAXIMUM,
  94. MINIMUM,
  95. EQUAL,
  96. NOT_EQUAL,
  97. LOGICALNOT,
  98. GATHERV2,
  99. STRIDEDSLICE,
  100. SQRT,
  101. GET_NEXT,
  102. CAST,
  103. NEG,
  104. SQUARE,
  105. BATCH_MATMUL,
  106. EXPAND_DIMS,
  107. SQUEEZE};
  108. std::vector<std::string> elementwise_op_ = {ACTIVATION, GELU, TANH, SOFTMAX, LOG_SOFTMAX, RELU, SQRT, CAST,
  109. POW, EXP, LOG, COS, ACOS, LOGICALNOT, NEG, SQUARE};
  110. bool StepAutoParallel(const FuncGraphPtr &root, const opt::OptimizerPtr &) {
  111. MS_EXCEPTION_IF_NULL(root);
  112. MS_EXCEPTION_IF_NULL(ParallelContext::GetInstance());
  113. std::string parallel_mode = ParallelContext::GetInstance()->parallel_mode();
  114. // assume no change to graph
  115. bool changes = false;
  116. // control whether use model_parallel mode
  117. if ((parallel_mode != AUTO_PARALLEL) || root->flags()[AUTO_PARALLEL_RUN_ONCE_ONLY]) {
  118. return changes;
  119. }
  120. // check whether strategy_search_mode is valid
  121. std::string strategy_search_mode = ParallelContext::GetInstance()->strategy_search_mode();
  122. if ((strategy_search_mode != DYNAMIC_PROGRAMMING) && (strategy_search_mode != RECURSIVE_PROGRAMMING)) {
  123. // Setting searching mode: dynanic programming as default.
  124. strategy_search_mode = DYNAMIC_PROGRAMMING;
  125. MS_LOG(INFO) << "Non-idicated strategy searching mode, using DP searching mode as default";
  126. }
  127. struct timeval start_time, end_time;
  128. (void)gettimeofday(&start_time, nullptr);
  129. if (MsContext::GetInstance()->save_graphs_flag()) {
  130. draw::Draw(STEP_AUTO_PARALLEL_BEGIN, root);
  131. }
  132. MS_LOG(INFO) << "Now entering step auto parallel";
  133. TOTAL_OPS = 0;
  134. AnfNodePtr ret = root->get_return();
  135. std::vector<AnfNodePtr> all_nodes = DeepScopedGraphSearch(ret);
  136. if (ParallelInit() != SUCCESS) {
  137. MS_LOG(EXCEPTION) << "Parallel init failed";
  138. }
  139. // mark the forward cnodes, parallel only care these nodes
  140. MarkForwardCNode(root);
  141. if (FindCommunicationOp(all_nodes)) {
  142. MS_LOG(EXCEPTION) << "The graph contain communication op";
  143. }
  144. // search parallelization strategy
  145. if (strategy_search_mode == DYNAMIC_PROGRAMMING) {
  146. if (ParallelStrategySearch(all_nodes, root) != SUCCESS) {
  147. MS_LOG(EXCEPTION) << "Auto-parallel strategy search failed when using DP searching mode";
  148. }
  149. } else if (strategy_search_mode == RECURSIVE_PROGRAMMING) {
  150. if (ParallelStrategyRecSearch(all_nodes, root) != SUCCESS) {
  151. MS_LOG(EXCEPTION) << "Auto-parallel strategy search failed when using RP searching mode";
  152. }
  153. } else {
  154. MS_LOG(EXCEPTION) << "Auto-parallel strategy searching mode unexpected";
  155. }
  156. (void)gettimeofday(&end_time, nullptr);
  157. uint64_t time = kUSecondInSecond * static_cast<uint64_t>(end_time.tv_sec - start_time.tv_sec);
  158. time += static_cast<uint64_t>(end_time.tv_usec - start_time.tv_usec);
  159. MS_LOG(INFO) << "Now leaving step auto parallel, used time: " << time << " us";
  160. root->flags()[AUTO_PARALLEL_RUN_ONCE_ONLY] = true;
  161. return changes;
  162. }
  163. // Given the node, return whether each input is a parameter or a output of a operator.
  164. // The returned boolean vector should be the same order of the inputs, thus its implementation
  165. // is closely consistent with ExtractShape() in step_parallel.cc
  166. std::vector<bool> ExtractInputParameterByNode(const CNodePtr &node) {
  167. std::vector<bool> is_parameter;
  168. std::vector<AnfNodePtr> node_inputs{node->inputs()};
  169. for (size_t i = 1; i < node_inputs.size(); ++i) {
  170. auto input = node_inputs[i];
  171. if (input->isa<Parameter>()) {
  172. auto input_parameter = input->cast<ParameterPtr>();
  173. if (input_parameter->has_default()) {
  174. bool require_grad =
  175. py::cast<bool>(parse::python_adapter::GetPyObjAttr(input_parameter->default_param(), "requires_grad"));
  176. is_parameter.push_back(require_grad);
  177. } else {
  178. is_parameter.push_back(false);
  179. }
  180. } else if (input->isa<CNode>() || IsValueNode<tensor::Tensor>(input) || IsValueNode<RefKey>(input)) {
  181. is_parameter.push_back(false);
  182. }
  183. }
  184. return is_parameter;
  185. }
  186. // Given the type, return the number of bytes to represent this type
  187. size_t GetLengthOfDataType(const TypePtr &type) {
  188. switch (type->type_id()) {
  189. case kNumberTypeBool:
  190. return sizeof(bool);
  191. case kNumberTypeInt8:
  192. return sizeof(int8_t);
  193. case kNumberTypeInt16:
  194. return sizeof(int16_t);
  195. case kNumberTypeInt32:
  196. return sizeof(int32_t);
  197. case kNumberTypeInt64:
  198. return sizeof(int64_t);
  199. case kNumberTypeUInt8:
  200. return sizeof(uint8_t);
  201. case kNumberTypeUInt16:
  202. return sizeof(uint16_t);
  203. case kNumberTypeUInt32:
  204. return sizeof(uint32_t);
  205. case kNumberTypeUInt64:
  206. return sizeof(uint64_t);
  207. case kNumberTypeFloat16:
  208. return sizeof(float) / 2;
  209. case kNumberTypeFloat32:
  210. return sizeof(float);
  211. case kNumberTypeFloat64:
  212. return sizeof(double);
  213. case kNumberTypeInt:
  214. return sizeof(int);
  215. case kNumberTypeUInt:
  216. return sizeof(unsigned int);
  217. case kNumberTypeFloat:
  218. return sizeof(float);
  219. default:
  220. MS_LOG(EXCEPTION) << "Unexpected type " << type->type_name();
  221. }
  222. }
  223. size_t GetInputsTypeLen(const AnfNodePtr &input) {
  224. MS_EXCEPTION_IF_NULL(input);
  225. if (!input->isa<CNode>() && !input->isa<Parameter>() && !IsValueNode<tensor::Tensor>(input)) {
  226. MS_LOG(EXCEPTION) << "The input node is not a cnode or parameter or tensor";
  227. }
  228. size_t input_type_len = 0;
  229. auto type = input->Type();
  230. MS_EXCEPTION_IF_NULL(type);
  231. if (type->isa<mindspore::TensorType>()) {
  232. auto input_element_type = type->cast<mindspore::TensorTypePtr>()->element();
  233. input_type_len = GetLengthOfDataType(input_element_type);
  234. } else {
  235. MS_LOG(EXCEPTION) << "Unknown type: " << type->type_name();
  236. }
  237. return input_type_len;
  238. }
  239. std::vector<size_t> ExtractInputTypeLengthByNode(const CNodePtr &node) {
  240. MS_EXCEPTION_IF_NULL(node);
  241. std::vector<size_t> inputs_type_len;
  242. std::vector<AnfNodePtr> node_inputs{node->inputs()};
  243. // extract input element length
  244. for (auto &input : node_inputs) {
  245. if (IsValueNode<RefKey>(input)) {
  246. auto func_graph = node->func_graph();
  247. MS_EXCEPTION_IF_NULL(func_graph);
  248. std::vector<AnfNodePtr> parameters = FindParameterByRefKeyNode(input, func_graph);
  249. if (parameters.size() != 1) {
  250. MS_LOG(EXCEPTION) << "Find parameter by ref key node failed";
  251. }
  252. inputs_type_len.push_back(GetInputsTypeLen(parameters[0]));
  253. } else if (input->isa<CNode>() || input->isa<Parameter>() || IsValueNode<tensor::Tensor>(input)) {
  254. // extract input shape from parameter and apply node
  255. inputs_type_len.push_back(GetInputsTypeLen(input));
  256. }
  257. }
  258. return inputs_type_len;
  259. }
  260. std::vector<TypePtr> ExtractOutputTypeByNode(const CNodePtr &node) {
  261. MS_EXCEPTION_IF_NULL(node);
  262. std::vector<TypePtr> outputs_type;
  263. // extract output element type
  264. auto primary_output_type = node->Type();
  265. MS_EXCEPTION_IF_NULL(primary_output_type);
  266. if (primary_output_type->isa<mindspore::Tuple>()) {
  267. // in this case, the output is a tuple
  268. auto tuple_output_type = primary_output_type->cast<mindspore::TuplePtr>();
  269. auto elements = tuple_output_type->elements();
  270. for (auto &ele : elements) {
  271. if (ele->isa<mindspore::TensorType>()) {
  272. auto ele_element_type = ele->cast<mindspore::TensorTypePtr>()->element();
  273. outputs_type.push_back(ele_element_type);
  274. } else {
  275. MS_LOG(EXCEPTION) << "Unknown type: " << primary_output_type->type_name();
  276. }
  277. }
  278. } else {
  279. // in this case, the output is a single tensor
  280. if (primary_output_type->isa<mindspore::TensorType>()) {
  281. auto element_type = primary_output_type->cast<mindspore::TensorTypePtr>()->element();
  282. outputs_type.push_back(element_type);
  283. } else {
  284. MS_LOG(EXCEPTION) << "Unknown type: " << primary_output_type->type_name();
  285. }
  286. }
  287. return outputs_type;
  288. }
  289. bool IsElementWiseOperator(const std::string &op_name) {
  290. auto iter = std::find(elementwise_op_.begin(), elementwise_op_.end(), op_name);
  291. return (iter != elementwise_op_.end());
  292. }
  293. bool IsSplittableOperator(const std::string &op_name) {
  294. std::vector<std::string>::iterator iter;
  295. iter = std::find(splittable_op_.begin(), splittable_op_.end(), op_name);
  296. return (iter != splittable_op_.end());
  297. }
  298. bool IsAutoParallelCareNode(const CNodePtr &cnode) {
  299. MS_EXCEPTION_IF_NULL(cnode);
  300. ValueNodePtr prim_node = cnode->input(0)->cast<ValueNodePtr>();
  301. if (prim_node == nullptr) {
  302. return false;
  303. }
  304. PrimitivePtr prim = GetValueNode<PrimitivePtr>(prim_node);
  305. if (prim == nullptr) {
  306. return false;
  307. }
  308. bool bool_result = IsParallelCareNode(cnode) && !IsSplittableOperator(prim->name());
  309. if (bool_result) {
  310. MS_LOG(EXCEPTION) << "Should implementing OperatorInfo for: " << prim->name();
  311. } else if (prim->name() == CAST) {
  312. return true;
  313. }
  314. return IsParallelCareNode(cnode) && IsSplittableOperator(prim->name());
  315. }
  316. OperatorInfoPtr CreateTheOperatorInfo(const PrimitivePtr &prim, const CNodePtr &cnode) {
  317. MS_EXCEPTION_IF_NULL(prim);
  318. MS_EXCEPTION_IF_NULL(cnode);
  319. auto attrs = prim->attrs();
  320. std::vector<Shapes> shape_list = ExtractShape(cnode);
  321. if (shape_list.empty()) {
  322. MS_LOG(EXCEPTION) << "Failure: node " << cnode->UniqueId() << " failed to extract shape";
  323. }
  324. // Create an OperatorInfo instance
  325. OperatorInfoPtr operator_info = NewOperatorInstance(prim, attrs, shape_list);
  326. MS_EXCEPTION_IF_NULL(operator_info);
  327. // Set the parameter information for this OperatorInfo (whether the inputs are parameters or not)
  328. std::vector<bool> parameter_info = ExtractInputParameterByNode(cnode);
  329. if (operator_info->set_is_parameter(parameter_info) != SUCCESS) {
  330. MS_LOG(ERROR) << "Initializing parameter information failed for operator: " << operator_info->name();
  331. return nullptr;
  332. }
  333. // Set the data type for inputs and outputs of this OperatorInfo
  334. auto inputs_type_length = ExtractInputTypeLengthByNode(cnode);
  335. auto outputs_type = ExtractOutputTypeByNode(cnode);
  336. std::vector<size_t> outputs_type_length;
  337. outputs_type_length.reserve(outputs_type.size());
  338. std::transform(outputs_type.begin(), outputs_type.end(), std::back_inserter(outputs_type_length),
  339. GetLengthOfDataType);
  340. if (operator_info->SetInputAndOutputTypeLength(inputs_type_length, outputs_type_length) != SUCCESS) {
  341. MS_LOG(ERROR) << "Setting the lengths of inputs and outputs failed for operator: " << operator_info->name();
  342. return nullptr;
  343. }
  344. if (operator_info->set_outputs_type(outputs_type) != SUCCESS) {
  345. MS_LOG(ERROR) << "Setting the types of outputs failed for operator: " << operator_info->name();
  346. return nullptr;
  347. }
  348. // When the 'inputs' contains numerical values for some operators, these values should be extracted from
  349. // ANF graph
  350. auto &inputs = cnode->inputs();
  351. std::vector<ValuePtr> input_value;
  352. for (size_t index = 1; index < inputs.size(); ++index) {
  353. if (inputs[index]->isa<ValueNode>()) {
  354. input_value.push_back(GetValueNode(inputs[index]));
  355. } else {
  356. input_value.emplace_back(nullptr);
  357. }
  358. }
  359. operator_info->set_input_value(input_value);
  360. operator_info->set_outputs_dtype(cnode->Type());
  361. operator_info->set_cnode(cnode);
  362. // If no strategy has been configured for this operator, then candidate strategies are generated for
  363. // auto-strategy searching; if this primitive is CAST, we ignore the user-specified strategy
  364. if (!StrategyFound(attrs) || prim->name() == CAST) {
  365. // Compute split_flag_list_, indicating which input has batch dimension. This is ONLY used for preparation for
  366. // BatchParallelInfo operator
  367. operator_info->ComputeBatchSplitFlagList();
  368. if (operator_info->GenerateStrategies(0) != SUCCESS) {
  369. MS_LOG(ERROR) << "Strategy search for Operator " << operator_info->name() << " failed.";
  370. return nullptr;
  371. }
  372. } else {
  373. // In this case, the configured strategy should be extracted to help setting cost
  374. StrategyPtr strategyPtr = parallel::ExtractStrategy(attrs);
  375. if (strategyPtr != nullptr) {
  376. if (prim->name() == RESHAPE) {
  377. MS_LOG(EXCEPTION) << "Setting strategy for Reshape goes for nothing!";
  378. }
  379. // Set cost for this configured strategy
  380. if (operator_info->SetCostUnderStrategy(strategyPtr) != SUCCESS) {
  381. MS_LOG(EXCEPTION) << "Failure: operator " << prim->name() << " SetCostUnderStrategy failed";
  382. } else if (FULLY_USE_DEVICES) {
  383. // If configured to fully use devices, then checking for the user-specified strategy
  384. int32_t used_devices = operator_info->used_devices();
  385. MS_EXCEPTION_IF_NULL(g_device_manager);
  386. auto total_device_num = g_device_manager->GetDeviceListByStageId(0).size();
  387. // 'used_devices == 1' means that ALL-1 strategy, which is valid in auto-parallel
  388. if (used_devices == 1) {
  389. return operator_info;
  390. }
  391. // 'used_devices == -1' means that 'used_devices_' is not set
  392. if ((used_devices == -1) || IntToSize(used_devices) != total_device_num) {
  393. MS_LOG(EXCEPTION) << "In configuration 'FULLY_USE_DEVICES' = True, "
  394. << "but the specified strategy uses device: " << used_devices
  395. << ", total devices: " << total_device_num;
  396. }
  397. }
  398. }
  399. }
  400. return operator_info;
  401. }
  402. Status ConstructCostGraphNodes(const std::vector<AnfNodePtr> &all_nodes, const FuncGraphPtr &) {
  403. MS_LOG(INFO) << "Constructing nodes for cost graph begins.";
  404. entire_costgraph = std::make_shared<CostGraph>();
  405. entire_costgraph->SetDeviceMemoryAndCostParameter();
  406. bool new_operator = true, first_operator = true;
  407. std::string first_operator_cnode;
  408. size_t current_op_index = 0;
  409. // Step 1
  410. for (auto &node : all_nodes) {
  411. // NOTE: we only care about splittable Primitive operators
  412. auto cnode = node->cast<CNodePtr>();
  413. bool bool_result = (cnode == nullptr) || (!IsValueNode<Primitive>(cnode->input(0)));
  414. if (bool_result) {
  415. continue;
  416. }
  417. ValueNodePtr prim_anf_node = cnode->input(0)->cast<ValueNodePtr>();
  418. if (!IsAutoParallelCareNode(cnode)) {
  419. continue;
  420. }
  421. PrimitivePtr prim = GetValueNode<PrimitivePtr>(prim_anf_node);
  422. MS_EXCEPTION_IF_NULL(prim);
  423. // When visiting the second subgraph, use the corresponding operatorInfo which already created
  424. bool modify_new_operator = (new_operator) && (!first_operator) && (cnode->UniqueId() == first_operator_cnode);
  425. if (modify_new_operator) {
  426. new_operator = false;
  427. }
  428. if (new_operator) {
  429. auto operator_info = CreateTheOperatorInfo(prim, cnode);
  430. if (operator_info == nullptr) {
  431. return FAILED;
  432. }
  433. // Needed by rec_parser
  434. operator_info->set_type(prim->name());
  435. std::vector<std::string> inputs_tensor_name = ExtractInputsTensorName(cnode);
  436. entire_costgraph->AddOperator(operator_info);
  437. (void)cnode->set_operator_info(operator_info);
  438. if (first_operator) {
  439. first_operator_cnode = cnode->UniqueId();
  440. first_operator = false;
  441. }
  442. // Needed by rec_parser
  443. entire_costgraph->add_inputs_tensor_name(inputs_tensor_name);
  444. } else {
  445. auto current_op_ptr = entire_costgraph->FindOperatorByIndex(current_op_index);
  446. if (current_op_ptr == nullptr) {
  447. MS_LOG(EXCEPTION) << "Find " << prim->name() << " from CostGraph failed.";
  448. } else {
  449. bool is_find_wrong = (current_op_ptr->name().find(VIRTUAL_DATA_SET_INFO) == std::string::npos) &&
  450. (current_op_ptr->name().find(BATCH_PARALLEL) == std::string::npos) &&
  451. (current_op_ptr->name().find(prim->name()) == std::string::npos);
  452. if (is_find_wrong) {
  453. MS_LOG(EXCEPTION) << "The OperatorInfo: " << current_op_ptr->name()
  454. << " does not match the Prim: " << prim->name();
  455. }
  456. (void)cnode->set_operator_info(current_op_ptr);
  457. current_op_index++;
  458. }
  459. }
  460. }
  461. if ((!new_operator) && (current_op_index != entire_costgraph->GetOperators().size())) {
  462. MS_LOG(EXCEPTION) << "The second subgraph's operator number: " << current_op_index
  463. << " does not match the first ones: " << entire_costgraph->GetOperators().size();
  464. }
  465. MS_LOG(INFO) << "Constructing nodes for cost graph ends.";
  466. return SUCCESS;
  467. }
  468. void ConstructCostGraphEdges(const std::vector<AnfNodePtr> &all_nodes) {
  469. // Step 2
  470. MS_LOG(INFO) << "Constructing edges for cost graph begins.";
  471. for (auto &node : all_nodes) {
  472. auto cnode = node->cast<CNodePtr>();
  473. bool bool_result_cnode = (cnode == nullptr) || !IsValueNode<Primitive>(cnode->input(0));
  474. if (bool_result_cnode) {
  475. continue;
  476. }
  477. auto &inputs = cnode->inputs();
  478. ValueNodePtr prim_anf_node = inputs[0]->cast<ValueNodePtr>();
  479. if (!IsAutoParallelCareNode(cnode)) {
  480. continue;
  481. }
  482. PrimitivePtr prim = GetValueNode<PrimitivePtr>(prim_anf_node);
  483. size_t edge_count = 0;
  484. for (size_t i = 1; i < inputs.size(); ++i) {
  485. auto prev_cnode = inputs[i]->cast<CNodePtr>();
  486. bool bool_result_prev_cnode = (prev_cnode == nullptr) || (!IsValueNode<Primitive>(prev_cnode->input(0)));
  487. if (bool_result_prev_cnode) {
  488. continue;
  489. }
  490. ValueNodePtr prev_prim_anf_node = prev_cnode->input(0)->cast<ValueNodePtr>();
  491. PrimitivePtr prev_prim = prev_prim_anf_node->value()->cast<PrimitivePtr>();
  492. size_t output_index = 0;
  493. bool bool_result =
  494. (IsAutoParallelCareNode(prev_cnode)) || (prev_prim->name() == TUPLE_GETITEM) || (prev_prim->name() == DEPEND);
  495. while (bool_result) {
  496. if (IsAutoParallelCareNode(prev_cnode)) {
  497. std::string edge_name =
  498. prev_cnode->operator_info()->name() + OPERATOR_TO_OPERATOR_CONNECTOR + cnode->operator_info()->name();
  499. // If the edge between these two operators already has been added, then the edge will not be added again.
  500. if (entire_costgraph->IsEdgeInCostGraph(edge_name, output_index, i - 1)) {
  501. break;
  502. }
  503. EdgePtr edge_ptr;
  504. MS_LOG(INFO) << "Creating edge: " << edge_name;
  505. bool follow_strategy = ELEMENTWISE_OP_STRA_FOLLOW && IsElementWiseOperator(prev_prim->name());
  506. if (follow_strategy) {
  507. // Redistribution in not allowed on the edge.
  508. // Elementwise operators have the same strategy as their previous operators.
  509. edge_ptr = std::make_shared<Edge>(edge_name, prev_cnode->operator_info(), cnode->operator_info(),
  510. output_index, i - 1, false, true);
  511. } else {
  512. edge_ptr = std::make_shared<Edge>(edge_name, prev_cnode->operator_info(), cnode->operator_info(),
  513. output_index, i - 1, false);
  514. }
  515. // Init costs for this edge
  516. if (edge_ptr->InitEdgeCost() != SUCCESS) {
  517. MS_LOG(EXCEPTION) << "Edge cost initialization failed";
  518. }
  519. cnode->operator_info()->AddPrevEdge(edge_ptr);
  520. prev_cnode->operator_info()->AddSuccEdge(edge_ptr);
  521. entire_costgraph->AddEdge(prev_cnode->operator_info(), cnode->operator_info(), edge_ptr);
  522. MS_LOG(INFO) << "Successfully adding the edge between " << prev_cnode->operator_info()->name() << " and "
  523. << cnode->operator_info()->name();
  524. edge_count++;
  525. break;
  526. } else if (prev_prim->name() == TUPLE_GETITEM) {
  527. // In this case, 'prev_anf_node' is 'tuple_getitem', the actual precursor node is node before
  528. // this 'tuple_getitem'
  529. MS_LOG(INFO) << "Jumping the 'tuple_getitem' operator.";
  530. output_index = IntToSize(GetValue<int>(GetValueNode(prev_cnode->input(2))));
  531. prev_cnode = prev_cnode->input(1)->cast<CNodePtr>();
  532. bool bool_result_tuple = (prev_cnode == nullptr) || (!IsValueNode<Primitive>(prev_cnode->input(0)));
  533. if (bool_result_tuple) {
  534. break;
  535. }
  536. prev_prim_anf_node = prev_cnode->input(0)->cast<ValueNodePtr>();
  537. prev_prim = prev_prim_anf_node->value()->cast<PrimitivePtr>();
  538. if (!IsAutoParallelCareNode(prev_cnode)) {
  539. MS_LOG(EXCEPTION) << "Did not create OperatorInfo for : " << prev_prim->name();
  540. }
  541. MS_LOG(INFO) << "Jumped the 'tuple_getitem' operator, "
  542. << "and creating an edge between the Operator before "
  543. << "'tuple_getitem' and the Operator after 'tuple_getitem'.";
  544. } else if (prev_prim->name() == DEPEND) {
  545. // In this case, 'prev_anf_node' is 'depend', the actual precursor node is node before
  546. // this 'depend'
  547. MS_LOG(INFO) << "Jumping the 'depend' operator.";
  548. prev_cnode = prev_cnode->input(1)->cast<CNodePtr>();
  549. bool bool_result_depend = (prev_cnode == nullptr) || (!IsValueNode<Primitive>(prev_cnode->input(0)));
  550. if (bool_result_depend) {
  551. break;
  552. }
  553. prev_prim_anf_node = prev_cnode->input(0)->cast<ValueNodePtr>();
  554. prev_prim = prev_prim_anf_node->value()->cast<PrimitivePtr>();
  555. MS_LOG(INFO) << "Jumped the 'depend' operator, "
  556. << "and creating an edge between the Operator before "
  557. << "'depend' and the Operator after 'depend'.";
  558. }
  559. bool_result =
  560. (IsAutoParallelCareNode(prev_cnode)) || (prev_prim->name() == TUPLE_GETITEM) || (prev_prim->name() == DEPEND);
  561. }
  562. }
  563. MS_LOG(INFO) << "Successfully created " << edge_count << " edges for: " << cnode->operator_info()->name();
  564. }
  565. MS_LOG(INFO) << "Constructing edges for cost graph ends.";
  566. }
  567. std::pair<AnfNodePtr, std::vector<AnfNodePtr>> CNodeWithRefKeys(const AnfNodePtr &cnode) {
  568. MS_EXCEPTION_IF_NULL(cnode);
  569. std::vector<AnfNodePtr> refkeys;
  570. if (cnode->isa<CNode>()) {
  571. auto cnode_ptr = cnode->cast<CNodePtr>();
  572. auto inputs = cnode_ptr->inputs();
  573. for (auto &one_input : inputs) {
  574. if (IsValueNode<RefKey>(one_input)) {
  575. refkeys.push_back(one_input);
  576. }
  577. }
  578. if (refkeys.size() >= 1) {
  579. return std::make_pair(cnode, refkeys);
  580. }
  581. }
  582. return {nullptr, refkeys};
  583. }
  584. void AugmentCostGraph(const std::vector<AnfNodePtr> &all_nodes) {
  585. // Step 3
  586. for (auto &node : all_nodes) {
  587. auto cnode_with_refkeys = CNodeWithRefKeys(node);
  588. if ((!node->isa<Parameter>()) && (cnode_with_refkeys.first == nullptr)) {
  589. continue;
  590. }
  591. std::string parameter_name;
  592. AnfNodePtr target_parameter = nullptr;
  593. AnfNodeIndexSet target_set;
  594. if (cnode_with_refkeys.first != nullptr) {
  595. // Dealing with the RefKey case
  596. auto refkeys = cnode_with_refkeys.second;
  597. auto cnode = cnode_with_refkeys.first;
  598. auto cnode_ptr = cnode->cast<CNodePtr>();
  599. if (cnode_ptr == nullptr || !IsValueNode<Primitive>(cnode_ptr->input(0))) {
  600. continue;
  601. }
  602. if (!IsAutoParallelCareNode(cnode_ptr)) {
  603. continue;
  604. }
  605. if (refkeys.size() > 1) {
  606. MS_LOG(EXCEPTION) << "CNode: " << cnode->fullname_with_scope() << " 's inputs have more than 1 RefKeys.";
  607. }
  608. MS_EXCEPTION_IF_NULL(cnode->func_graph());
  609. auto cnode_func_graph = cnode->func_graph();
  610. MS_EXCEPTION_IF_NULL(cnode->func_graph()->manager());
  611. // Find the RefKey being used
  612. auto candidate_set_by_refkey = cnode_func_graph->manager()->node_users()[refkeys[0]];
  613. for (auto &candidate : candidate_set_by_refkey) {
  614. auto candidate_node = candidate.first;
  615. auto c = candidate_node->cast<CNodePtr>();
  616. if (c == nullptr || !IsValueNode<Primitive>(c->input(0))) {
  617. continue;
  618. }
  619. if (!IsAutoParallelCareNode(c)) {
  620. continue;
  621. }
  622. target_set.add(candidate);
  623. }
  624. // Find the corresponding Parameter being used
  625. std::vector<AnfNodePtr> parameters = FindParameterByRefKeyNode(refkeys[0], cnode_func_graph);
  626. if (parameters.size() != 1) {
  627. MS_LOG(EXCEPTION) << "Find parameter by ref key node failed";
  628. }
  629. parameter_name = parameters[0]->cast<ParameterPtr>()->name();
  630. target_parameter = parameters[0];
  631. auto candidate_set_by_para = cnode_func_graph->manager()->node_users()[parameters[0]];
  632. for (auto &candidate : candidate_set_by_para) {
  633. auto candidate_node = candidate.first;
  634. auto c = candidate_node->cast<CNodePtr>();
  635. if (c == nullptr || !IsValueNode<Primitive>(c->input(0))) {
  636. continue;
  637. }
  638. if (!IsAutoParallelCareNode(c)) {
  639. continue;
  640. }
  641. (void)target_set.insert(candidate);
  642. }
  643. } else if (node->isa<Parameter>()) {
  644. // Dealing with the Parameter case
  645. MS_EXCEPTION_IF_NULL(node->func_graph());
  646. MS_EXCEPTION_IF_NULL(node->func_graph()->manager());
  647. auto candidate_set = node->func_graph()->manager()->node_users()[node];
  648. for (auto &candidate : candidate_set) {
  649. auto candidate_node = candidate.first;
  650. auto c = candidate_node->cast<CNodePtr>();
  651. if (c == nullptr || !IsValueNode<Primitive>(c->input(0))) {
  652. continue;
  653. }
  654. if (!IsAutoParallelCareNode(c)) {
  655. continue;
  656. }
  657. (void)target_set.insert(candidate);
  658. }
  659. // In this case, node is a Parameter
  660. parameter_name = node->cast<ParameterPtr>()->name();
  661. target_parameter = node;
  662. }
  663. if (target_set.size() <= 1) {
  664. continue;
  665. }
  666. // Rule out the case when a Parameter being used by a Operator, but the Operator appears in multiple CNODEs
  667. std::set<std::string> target_without_duplicate;
  668. for (auto &target : target_set) {
  669. auto target_cnode = target.first->cast<CNodePtr>();
  670. auto input_index = target.second;
  671. (void)target_without_duplicate.insert(std::to_string(input_index) + target_cnode->operator_info()->name());
  672. }
  673. if (target_without_duplicate.size() <= 1) {
  674. continue;
  675. }
  676. // Here, it is sure that this Parameter (RefKey) is being used by multiple Operators.
  677. OperatorInfoPtr tmp_identity_ptr;
  678. bool new_identity = false;
  679. std::string tmp_identity_name;
  680. auto returned_identity = entire_costgraph->FindTmpIdentityByParameterName(parameter_name);
  681. if (returned_identity != nullptr) {
  682. // In this case, the TmpIdentityInfo instance has already been created
  683. new_identity = false;
  684. tmp_identity_ptr = returned_identity;
  685. tmp_identity_name = tmp_identity_ptr->name();
  686. } else {
  687. // In the case, the TmpIdentityInfo instance has NOT been created. Thus, a new one is created.
  688. new_identity = true;
  689. // 1) extract input shape from this Parameter
  690. MS_EXCEPTION_IF_NULL(target_parameter);
  691. AbstractBasePtr abstract = target_parameter->abstract();
  692. if (abstract == nullptr) {
  693. MS_LOG(EXCEPTION) << "Failure: abstract is nullptr";
  694. }
  695. auto input_shape = dyn_cast<abstract::Shape>(abstract->GetShapeTrack());
  696. if (input_shape == nullptr) {
  697. MS_LOG(EXCEPTION) << "Failure: input_shape is nullptr";
  698. }
  699. std::vector<int> shape_int = input_shape->shape();
  700. Shape shape;
  701. (void)std::transform(shape_int.begin(), shape_int.end(), std::back_inserter(shape),
  702. [](int sub_shape) { return static_cast<int32_t>(sub_shape); });
  703. Shapes inputs_shape = {shape};
  704. Shapes outputs_shape = {shape};
  705. // 2) init the attr
  706. std::unordered_map<std::string, ValuePtr> attr = {};
  707. // Create the TmpIdentity instance
  708. tmp_identity_ptr = std::make_shared<TmpIdentityInfo>(inputs_shape, outputs_shape, attr);
  709. tmp_identity_ptr->set_name(tmp_identity_ptr->name() + std::to_string(TOTAL_OPS));
  710. TOTAL_OPS++;
  711. tmp_identity_ptr->set_refkey_parameter_name(parameter_name);
  712. // Set the parameter and type lengths for inputs and outputs
  713. std::vector<bool> is_parameter;
  714. auto casted_target_parameter = target_parameter->cast<ParameterPtr>();
  715. MS_EXCEPTION_IF_NULL(casted_target_parameter);
  716. if (casted_target_parameter->has_default()) {
  717. bool require_grad = py::cast<bool>(
  718. parse::python_adapter::GetPyObjAttr(casted_target_parameter->default_param(), "requires_grad"));
  719. is_parameter.push_back(require_grad);
  720. } else {
  721. is_parameter.push_back(false);
  722. }
  723. if (tmp_identity_ptr->set_is_parameter(is_parameter) != SUCCESS) {
  724. MS_LOG(EXCEPTION) << "Setting parameter for TmpIdentityInfo failed";
  725. }
  726. auto node_type = target_parameter->Type();
  727. if (node_type->isa<mindspore::TensorType>()) {
  728. auto input_element_type = node_type->cast<mindspore::TensorTypePtr>()->element();
  729. std::vector<size_t> type_length = {GetLengthOfDataType(input_element_type)};
  730. if (tmp_identity_ptr->SetInputAndOutputTypeLength(type_length, type_length) != SUCCESS) {
  731. MS_LOG(EXCEPTION) << "Setting input and output type length for TmpIdentityInfo failed";
  732. }
  733. } else {
  734. MS_LOG(EXCEPTION) << "Unknown type: " << node_type->type_name();
  735. }
  736. // Generate strategies for this TmpIdentityInfo instance;
  737. if (tmp_identity_ptr->GenerateStrategies(0) != SUCCESS) {
  738. MS_LOG(EXCEPTION) << "Strategy search for Operator failed : " << tmp_identity_ptr->name();
  739. }
  740. }
  741. // A flag recording whether new edges have been created or not
  742. bool add_identity_edge = false;
  743. // Create edges between this TmpIdentityInfo instance and subsequent Operator instances
  744. for (auto &target : target_set) {
  745. auto target_cnode = target.first->cast<CNodePtr>();
  746. auto prim = GetValueNode<PrimitivePtr>(target_cnode->input(0));
  747. auto input_index = target.second;
  748. std::string edge_name =
  749. std::string(IDENTITY_INFO) + OPERATOR_TO_OPERATOR_CONNECTOR + target_cnode->operator_info()->name();
  750. // If the edge between these two operators already has been added, then the edge will not be added again.
  751. if (entire_costgraph->IsEdgeInCostGraph(edge_name, 0, IntToSize(input_index - 1))) {
  752. continue;
  753. }
  754. std::shared_ptr<Edge> edge_ptr = std::make_shared<Edge>(
  755. edge_name, tmp_identity_ptr, target_cnode->operator_info(), 0, input_index - 1, false, true);
  756. if (edge_ptr->InitEdgeCost() != SUCCESS) {
  757. MS_LOG(EXCEPTION) << "Edge cost initialization failed";
  758. }
  759. target_cnode->operator_info()->AddPrevEdge(edge_ptr);
  760. tmp_identity_ptr->AddSuccEdge(edge_ptr);
  761. entire_costgraph->AddEdge(tmp_identity_ptr, target_cnode->operator_info(), edge_ptr);
  762. MS_LOG(INFO) << "Successfully adding the edge between " << tmp_identity_ptr->name() << " and "
  763. << target_cnode->operator_info()->name();
  764. add_identity_edge = true;
  765. }
  766. if (new_identity && add_identity_edge) {
  767. // Add the TmpIdentityInfo to CostGraph if BOTH two conditions are satisfied
  768. entire_costgraph->AddOperator(tmp_identity_ptr);
  769. }
  770. }
  771. }
  772. Status ParallelStrategySearch(const std::vector<AnfNodePtr> &all_nodes, const FuncGraphPtr &root) {
  773. // There are 4 meta-steps to determine the parallelization strategy for the ANF graph.
  774. // Step 1: Traverse the ANF graph, and create NODEs for costgraph:
  775. // create the OperatorInfo object for each primitive, and enumerate the parallelization strategies
  776. // for each OperatorInfo;
  777. // Step 2: Traverse the ANF graph, and create EDGES for costgraph:
  778. // create the Edge object for each pair of OperatorInfo, and enumerate the parallelization strategies
  779. // for each edge, based on the strategies of two OperatorInfos;
  780. // Step 3: Augment the costgraph:
  781. // taking care for the case of a single Parameter being used by multiple operators. Create a TmpIdentity
  782. // operator for this Parameter, and add an edge for the use of this Parameter by each
  783. // subsequent operator;
  784. // Step 3.1: Calculate memory usage
  785. // Step 4: Run the Dynamic Programming algorithm:
  786. // in this process, cost is calculated based on not only the operators, but also the edges. Here, the edge
  787. // cost is caused by the redistribution of a operator's output tensor layout to the next operator's input
  788. // tensor layout. Note that there may be several connected components in the costgraph, and the DP algorithm
  789. // runs on each of them.
  790. //
  791. // OUTPUT: the determined strategy for each operator.
  792. // Step 1
  793. if (ConstructCostGraphNodes(all_nodes, root) == SUCCESS) {
  794. MS_LOG(INFO) << "Constructing nodes for cost graph succeeded. There are " << entire_costgraph->GetOperators().size()
  795. << " operators.";
  796. } else {
  797. MS_LOG(EXCEPTION) << "Constructing nodes for cost graph failed.";
  798. }
  799. // Step 2
  800. ConstructCostGraphEdges(all_nodes);
  801. MS_LOG(INFO) << "Constructing edges for cost graph succeeded. There are " << entire_costgraph->GetOperators().size()
  802. << " operators, and " << entire_costgraph->GetNumPairs() << " edges.",
  803. // Step 3: Augment the costgraph.
  804. AugmentCostGraph(all_nodes);
  805. MS_LOG(INFO) << "After the augmenting procedure, there are " << entire_costgraph->GetOperators().size()
  806. << " operators, and " << entire_costgraph->GetNumPairs() << " edges.";
  807. // Step 3.1: Calculate the memory usage
  808. if (entire_costgraph->ComputeOpsAndEdgesParameterInvolved() == SUCCESS) {
  809. // Calculate operators' memory usage
  810. if (entire_costgraph->CalculateOpsMemoryCost() != SUCCESS) {
  811. MS_LOG(EXCEPTION) << "Calculating operators' cost for memory cost failed.";
  812. }
  813. // Calculate edges' memory usage
  814. if (entire_costgraph->CalculateEdgesMemoryCost() != SUCCESS) {
  815. MS_LOG(EXCEPTION) << "Calculating edges' cost for memory cost failed.";
  816. }
  817. // Correct memory usage caused by TmpIdentity
  818. if (entire_costgraph->CorrectOpsMemoryCost() != SUCCESS) {
  819. MS_LOG(EXCEPTION) << "Correcting operators' cost for memory cost failed.";
  820. }
  821. } else {
  822. MS_LOG(EXCEPTION) << "Computing operators' parameter_involved failed.";
  823. }
  824. // Step 4: run DP algorithm on the costgraph.
  825. if (GetStrategy(entire_costgraph) != SUCCESS) {
  826. MS_LOG(ERROR) << "Strategy search for cost-graph fails";
  827. return FAILED;
  828. }
  829. MS_LOG(INFO) << "Searching strategy succeeded.";
  830. if (entire_costgraph->InitSelectedStrategy() == SUCCESS) {
  831. MS_LOG(INFO) << "Init selected strategy succeeded.";
  832. } else {
  833. MS_LOG(EXCEPTION) << "Init selected strategy failed.";
  834. }
  835. // print the selected strategy
  836. for (auto &op : entire_costgraph->GetOperators()) {
  837. StrategyPtr s_strategy = op->selected_strategy();
  838. MS_LOG(INFO) << op->name() << " : The strategy is:";
  839. PrintStrategy(s_strategy);
  840. }
  841. return SUCCESS;
  842. }
  843. std::vector<std::vector<std::string>> RecInputTensorNames(const std::map<std::string, std::string>::iterator &it,
  844. std::vector<std::vector<std::string>> input_tensor_names) {
  845. for (size_t j = 0; j < input_tensor_names.size(); j++) {
  846. for (size_t k = 0; k < input_tensor_names[j].size(); k++) {
  847. if (it->first == input_tensor_names[j][k]) {
  848. input_tensor_names[j][k] = it->second;
  849. break;
  850. }
  851. }
  852. }
  853. return input_tensor_names;
  854. }
  855. Status ParallelStrategyRecSearch(const std::vector<AnfNodePtr> &all_nodes, const FuncGraphPtr &root) {
  856. if (ConstructCostGraphNodes(all_nodes, root) == SUCCESS) {
  857. MS_LOG(INFO) << "Constructing nodes for cost graph succeeded. There are " << entire_costgraph->GetOperators().size()
  858. << " operators.";
  859. } else {
  860. MS_LOG(ERROR) << "Constructing nodes for cost graph failed.";
  861. return FAILED;
  862. }
  863. auto ops = entire_costgraph->GetOperators();
  864. std::vector<std::vector<std::string>> input_tensor_names = entire_costgraph->get_inputs_tensor_name_list();
  865. auto tuple_getitem_list = entire_costgraph->get_tuple_getitem_list();
  866. for (auto it = tuple_getitem_list.begin(); it != tuple_getitem_list.end();) {
  867. input_tensor_names = RecInputTensorNames(it++, input_tensor_names);
  868. }
  869. std::shared_ptr<std::vector<size_t>> ops_nodes_list(new std::vector<size_t>);
  870. std::shared_ptr<Graph> graph = ParseGraph(ops, input_tensor_names);
  871. size_t num_device = g_device_manager->DeviceNum();
  872. double device_memory = entire_costgraph->GetDeviceMemory();
  873. if (PartitionForAllDevices(num_device, device_memory, graph) == SUCCESS) {
  874. MS_LOG(INFO) << "Partition Success With " << num_device << " devices.";
  875. } else {
  876. MS_LOG(ERROR) << "PartitionForAllDevices failed.";
  877. return FAILED;
  878. }
  879. bool mask_special_ops = true;
  880. GenerateStrategy(graph, mask_special_ops, ops);
  881. if (entire_costgraph->InitSelectedStrategy() == SUCCESS) {
  882. MS_LOG(INFO) << "Init selected strategy succeeded.";
  883. } else {
  884. MS_LOG(ERROR) << "Init selected strategy failed.";
  885. return FAILED;
  886. }
  887. // print the selected strategy
  888. for (auto &op : entire_costgraph->GetOperators()) {
  889. StrategyPtr s_strategy = op->selected_strategy();
  890. MS_LOG(INFO) << op->name() << " : The strategy is:";
  891. PrintStrategy(s_strategy);
  892. }
  893. return SUCCESS;
  894. }
  895. } // namespace parallel
  896. } // namespace mindspore