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.

function_block.cc 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /**
  2. * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
  3. *
  4. * Copyright 2019-2021 Huawei Technologies Co., Ltd
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "pipeline/jit/parse/function_block.h"
  19. #include <string>
  20. #include <memory>
  21. #include "pybind11/pybind11.h"
  22. #include "pipeline/jit/parse/resolve.h"
  23. #include "pipeline/jit/parse/parse.h"
  24. #include "frontend/operator/ops.h"
  25. #include "utils/info.h"
  26. #include "debug/trace.h"
  27. #include "utils/utils.h"
  28. namespace mindspore {
  29. namespace py = pybind11;
  30. namespace parse {
  31. FunctionBlock::FunctionBlock(const Parser &parser) : parser_(parser) {
  32. func_graph_ = std::make_shared<FuncGraph>();
  33. matured_ = false;
  34. }
  35. void FunctionBlock::AddPrevBlock(const FunctionBlockPtr &block) { prev_blocks_.push_back(block.get()); }
  36. static bool CanBeIsolatedNode(const std::string &var_name, const AnfNodePtr &node) {
  37. auto cnode = dyn_cast<CNode>(node);
  38. if (cnode == nullptr || cnode->inputs().empty()) {
  39. // Not a valid cnode, can not be isolate node.
  40. return false;
  41. }
  42. auto prim = GetValueNode<PrimitivePtr>(cnode->inputs().at(0));
  43. if (prim == nullptr) {
  44. // Not a primitive cnode, it may have side effects or not,
  45. // We add it as an isolate node if its name is not '_' or empty.
  46. // this means that code like:
  47. // _ = func_call()
  48. // will be ignored even if func_call() has side effects.
  49. return !var_name.empty() && var_name != "_";
  50. }
  51. // For primitive cnode, only those with side effects can be isolate nodes.
  52. auto effect_info = GetPrimEffectInfo(prim);
  53. bool has_effects = (effect_info.memory || effect_info.io);
  54. return has_effects;
  55. }
  56. // Write variable records the variable name to corresponding node
  57. void FunctionBlock::WriteVariable(const std::string &var_name, const AnfNodePtr &node) {
  58. MS_LOG(DEBUG) << func_graph_->ToString() << " write var " << var_name << " with node " << node->DebugString();
  59. auto [iter, is_new_name] = vars_.emplace(var_name, std::make_pair(node, false));
  60. if (!is_new_name) {
  61. // If a cnode variable with same name already existed but not used,
  62. // add it as an isolate node. for example:
  63. // a = print(x)
  64. // a = print(y)
  65. // When we write variable 'a = print(y)',
  66. // the cnode 'print(x)' should added as an isolate node.
  67. auto is_used = iter->second.second;
  68. auto hidden_node = iter->second.first;
  69. auto is_isolated = CanBeIsolatedNode(var_name, hidden_node);
  70. if (!is_used && is_isolated) {
  71. MS_LOG(INFO) << "Isolated node found(Hidden), hidden_node: " << hidden_node->DebugString(2) << " is hidden by "
  72. << node->DebugString(2) << " with the same name, var_name: " << var_name << ", block: " << this
  73. << "/" << (func_graph() ? func_graph()->ToString() : "FG(Null)")
  74. << ", Line: " << trace::GetDebugInfo(hidden_node->debug_info(), "", kSourceLineTipDiscard);
  75. AddIsolatedNode(hidden_node);
  76. }
  77. iter->second = std::make_pair(node, false);
  78. }
  79. }
  80. // Read variable from predecessors
  81. AnfNodePtr FunctionBlock::ReadVariable(const std::string &var) {
  82. // Get var node if it is found
  83. auto found = vars_.find(var);
  84. if (found != vars_.end()) {
  85. auto &node = found->second.first;
  86. MS_EXCEPTION_IF_NULL(node);
  87. // Mark the variable as used.
  88. found->second.second = true;
  89. auto iter = resolve_to_removable_phis_.find(node);
  90. if (iter != resolve_to_removable_phis_.end()) {
  91. return iter->second;
  92. }
  93. return node;
  94. }
  95. // Get var from predecessor block ,if can't get the make a resolve node to it
  96. if (matured_) {
  97. // If only one predecessor block, read the definition of var from it.
  98. if (prev_blocks_.size() == 1) {
  99. auto block = prev_blocks_[0];
  100. MS_EXCEPTION_IF_NULL(block);
  101. return block->ReadVariable(var);
  102. } else if (prev_blocks_.empty()) {
  103. // Get namespace and make Resolve
  104. auto it = var_to_resolve_.find(var);
  105. if (it != var_to_resolve_.end()) {
  106. return it->second;
  107. }
  108. auto tmp_node = MakeResolveSymbol(var);
  109. var_to_resolve_[var] = tmp_node;
  110. return tmp_node;
  111. }
  112. }
  113. // If have more than one predecessor blocks then build a phi node.
  114. auto debug_info = std::make_shared<NodeDebugInfo>();
  115. debug_info->set_name(var);
  116. TraceGuard guard(std::make_shared<TracePhi>(debug_info));
  117. ParameterPtr phi_param = std::make_shared<Parameter>(func_graph());
  118. MS_LOG(DEBUG) << func_graph_->ToString() << " generate phi node " << phi_param->ToString() << " for " << var;
  119. func_graph()->add_parameter(phi_param);
  120. phi_nodes_[phi_param] = var;
  121. WriteVariable(var, phi_param);
  122. if (matured_) {
  123. SetPhiArgument(phi_param);
  124. }
  125. return phi_param;
  126. }
  127. // Resolve Ast operator node
  128. AnfNodePtr FunctionBlock::MakeResolveAstOp(const py::object &op) {
  129. auto ast = parser_.ast();
  130. MS_EXCEPTION_IF_NULL(ast);
  131. TraceGuard trace_guard(parser_.GetLocation(op));
  132. py::tuple namespace_var = ast->CallParseModFunction(PYTHON_PARSE_GET_AST_NAMESPACE_SYMBOL, op);
  133. if (namespace_var.size() != 2) {
  134. MS_LOG(EXCEPTION) << "Resolve ast op failed, get namespace tuple size=" << namespace_var.size();
  135. }
  136. NameSpacePtr name_space = std::make_shared<NameSpace>(RESOLVE_NAMESPACE_NAME_AST, namespace_var[0]);
  137. SymbolPtr symbol = std::make_shared<Symbol>(namespace_var[1].cast<std::string>());
  138. return MakeResolve(name_space, symbol);
  139. }
  140. // Resolve class member, two possible: method, member variable
  141. AnfNodePtr FunctionBlock::MakeResolveClassMember(const std::string &attr) {
  142. py::object namespace_var =
  143. parser_.ast()->CallParseModFunction(PYTHON_MOD_GET_MEMBER_NAMESPACE_SYMBOL, parser_.ast()->obj());
  144. NameSpacePtr name_space = std::make_shared<NameSpace>(RESOLVE_NAMESPACE_NAME_CLASS_MEMBER, namespace_var);
  145. SymbolPtr symbol = std::make_shared<Symbol>(attr);
  146. return MakeResolve(name_space, symbol);
  147. }
  148. // Make a resolve node for symbol string
  149. AnfNodePtr FunctionBlock::MakeResolveSymbol(const std::string &value) {
  150. if (value.compare(0, strlen("self"), "self") == 0) {
  151. auto start = value.find_first_of('.') + 1;
  152. if (start >= value.size()) {
  153. MS_LOG(ERROR) << "Find invalid resolve symbol str: " << value;
  154. return nullptr;
  155. }
  156. auto bits_str = value.substr(start);
  157. return MakeResolveClassMember(bits_str);
  158. }
  159. py::tuple namespace_info = parser_.ast()->CallParserObjMethod(PYTHON_PARSE_GET_NAMESPACE_SYMBOL, value);
  160. // If namespace is None, the symbol is an undefined name or an unsupported builtin function.
  161. if (namespace_info[0].is_none()) {
  162. // If the size of namespace_var is greater than or equal to 3, the error information is stored in namespace_var[2].
  163. if (namespace_info.size() >= 3) {
  164. MS_EXCEPTION(NameError) << namespace_info[2].cast<std::string>();
  165. }
  166. // If the size of namespace_var is less than 3, the default error information is used.
  167. MS_EXCEPTION(NameError) << "The name \'" << value << "\' is not defined.";
  168. }
  169. NameSpacePtr name_space = std::make_shared<NameSpace>(RESOLVE_NAMESPACE_NAME_SYMBOL_STR, namespace_info[0]);
  170. SymbolPtr symbol = std::make_shared<Symbol>(namespace_info[1].cast<std::string>());
  171. return MakeResolve(name_space, symbol);
  172. }
  173. AnfNodePtr FunctionBlock::MakeResolveOperation(const std::string &value) {
  174. py::tuple namespace_var = parser_.ast()->CallParseModFunction(PYTHON_PARSE_GET_OPERATION_NAMESPACE_SYMBOL, value);
  175. NameSpacePtr name_space = std::make_shared<NameSpace>(RESOLVE_NAMESPACE_NAME_COMMON_OPS, namespace_var[0]);
  176. SymbolPtr symbol = std::make_shared<Symbol>(namespace_var[1].cast<std::string>());
  177. return MakeResolve(name_space, symbol);
  178. }
  179. AnfNodePtr FunctionBlock::MakeResolve(const NameSpacePtr &name_space, const SymbolPtr &resolve_symbol) {
  180. MS_LOG(DEBUG) << "MakeResolve for " << ((std::string)py::str(name_space->obj())) << " , "
  181. << ((std::string)resolve_symbol->symbol());
  182. ValueNodePtr module_node = NewValueNode(name_space);
  183. ValueNodePtr symbol_node = NewValueNode(resolve_symbol);
  184. auto node = func_graph()->NewCNodeInOrder({NewValueNode(prim::kPrimResolve), module_node, symbol_node});
  185. return node;
  186. }
  187. // Add input for the block's phi parameter
  188. void FunctionBlock::SetPhiArgument(const ParameterPtr &phi) {
  189. TraceGuard trace_guard(std::make_shared<TraceResolve>(phi->debug_info()));
  190. std::string var = phi_nodes_[phi];
  191. MS_LOG(DEBUG) << "graph " << func_graph_->ToString() << " set phi " << phi->ToString() << " for var " << var;
  192. auto removable = CollectRemovablePhi(phi);
  193. // If the phi node is not necessary, not need to add to jumps_ of the prev blocks.
  194. if (removable) {
  195. MS_LOG(DEBUG) << "remove the phi when call graph " << func_graph_->ToString() << " var " << var;
  196. return;
  197. }
  198. for (auto &pred : prev_blocks_) {
  199. MS_EXCEPTION_IF_NULL(pred);
  200. MS_LOG(DEBUG) << "graph " << func_graph_->ToString() << " pred_blocks_ " << pred->func_graph_->ToString();
  201. AnfNodePtr arg_node = pred->ReadVariable(var);
  202. CNodePtr jump = pred->jumps_[this];
  203. jump->add_input(arg_node);
  204. }
  205. }
  206. AnfNodePtr FunctionBlock::SearchReplaceNode(const std::string &var, const ParameterPtr &phi) {
  207. AnfNodePtr arg_node = nullptr;
  208. for (auto &prev : prev_blocks_) {
  209. MS_EXCEPTION_IF_NULL(prev);
  210. AnfNodePtr temp_node = prev->ReadVariable(var);
  211. MS_LOG(DEBUG) << "graph " << prev->func_graph_->ToString() << " phi " << phi->ToString() << " for var " << var
  212. << " is " << temp_node->DebugString();
  213. if (temp_node != phi) {
  214. if (arg_node == nullptr) {
  215. arg_node = temp_node;
  216. MS_LOG(DEBUG) << "graph " << prev->func_graph_->ToString() << " phi " << phi->ToString()
  217. << " may be replaced by node " << arg_node->DebugString();
  218. } else if (temp_node == arg_node) {
  219. MS_LOG(DEBUG) << "graph " << prev->func_graph_->ToString() << " phi " << phi->ToString() << " is same as node "
  220. << arg_node->DebugString();
  221. } else {
  222. MS_LOG(DEBUG) << "phi " << phi->ToString()
  223. << " cannot be removed as it assigns to different node. node1: " << arg_node->DebugString()
  224. << ", node2: " << temp_node->DebugString();
  225. return nullptr;
  226. }
  227. }
  228. }
  229. return arg_node;
  230. }
  231. // Check if there is removable unnecessary phi node in this graph.
  232. // As per the FIRM TR 3.2, a phi node can be remove if:
  233. // <Quote>
  234. // If all arguments of a φ-function are the same value s or the φfunction itself,
  235. // then we remove the φ-function and let all users directly uses. We call such a
  236. // φ-function obviously unnecessary.
  237. // When we removed a φ-function p, then we recursively try to apply this simplification
  238. // rule with all (former) users of p, because they may have become obviously unnecessary
  239. // due to the removal of p
  240. // <Quote>
  241. // phi node in graph will be removed after the whole function is parsed in a DFS visit
  242. // of that graph.The reason is :
  243. // 1. when this function is called, not all usage of this phi node had bound to the
  244. // graph of this function block, some may stay in vars_ in other blocks.
  245. // 2. it's costly to iterate the graph to replace the phi for each phi.
  246. // Args :
  247. // phi : This parameter node is functioning as a phi node.
  248. bool FunctionBlock::CollectRemovablePhi(const ParameterPtr &phi) {
  249. MS_EXCEPTION_IF_NULL(phi);
  250. std::string var = phi_nodes_[phi];
  251. MS_LOG(DEBUG) << "check phi " << phi->DebugString() << " for " << var;
  252. if (prev_blocks_.empty()) {
  253. MS_LOG(DEBUG) << "no phi " << phi->DebugString() << " for var " << var;
  254. return false;
  255. }
  256. AnfNodePtr arg_node = SearchReplaceNode(var, phi);
  257. if (arg_node != nullptr) {
  258. arg_node->set_debug_info(phi->debug_info());
  259. MS_LOG(DEBUG) << "graph " << func_graph_->ToString() << " phi " << phi->ToString() << " can be replaced with "
  260. << arg_node->DebugString();
  261. // Replace var with new one. This equal to statement in TR "v0 is immediately replaced by v1."
  262. WriteVariable(var, arg_node);
  263. removable_phis_[phi] = arg_node;
  264. resolve_to_removable_phis_[arg_node] = phi;
  265. // The following equal to statement "The φ-function defining v1, which now reads φ(v2, v1), is optimized
  266. // recursively". check if phi1 is assigned with this phi before, then phi1 can be replaced with arg_node.
  267. for (auto &prev : prev_blocks_) {
  268. MS_EXCEPTION_IF_NULL(prev);
  269. if (!prev->matured_) {
  270. continue;
  271. }
  272. for (auto &phi_iter : prev->removable_phis_) {
  273. MS_EXCEPTION_IF_NULL(phi_iter.second);
  274. if (phi_iter.second->isa<Parameter>()) {
  275. const auto &param = phi_iter.second->cast<ParameterPtr>();
  276. if (param == phi) {
  277. MS_LOG(DEBUG) << "graph " << prev->func_graph_->ToString() << " var " << phi_iter.first->DebugString()
  278. << " can be replaced from " << param->DebugString() << " with " << arg_node->DebugString()
  279. << " in graph " << arg_node->func_graph()->ToString();
  280. prev->removable_phis_[phi_iter.first] = arg_node;
  281. }
  282. }
  283. }
  284. }
  285. return true;
  286. }
  287. return false;
  288. }
  289. // A block should be marked matured if its predecessor blocks have been processed
  290. void FunctionBlock::Mature() {
  291. const auto &graphParamVec = func_graph_->parameters();
  292. for (auto &paramItr : graphParamVec) {
  293. MS_EXCEPTION_IF_NULL(paramItr);
  294. auto param = paramItr->cast<ParameterPtr>();
  295. if (phi_nodes_.find(param) != phi_nodes_.cend()) {
  296. SetPhiArgument(param);
  297. }
  298. }
  299. matured_ = true;
  300. }
  301. // Force the conditIon node to bool using bool operation
  302. CNodePtr FunctionBlock::ForceToBoolNode(const AnfNodePtr &cond) {
  303. TraceGuard trace_guard(std::make_shared<TraceForceBool>(cond->debug_info()));
  304. CNodePtr op_apply_node = func_graph()->NewCNodeInOrder({MakeResolveOperation(NAMED_PRIMITIVE_BOOL), cond});
  305. return op_apply_node;
  306. }
  307. CNodePtr FunctionBlock::ForceToWhileCond(const AnfNodePtr &cond) {
  308. TraceGuard trace_guard(std::make_shared<TraceForceWhileCond>(cond->debug_info()));
  309. CNodePtr op_apply_node = func_graph()->NewCNodeInOrder({MakeResolveOperation("while_cond"), cond});
  310. return op_apply_node;
  311. }
  312. // Perform a jump from this block to target block
  313. void FunctionBlock::Jump(const FunctionBlockPtr &target_block, const AnfNodePtr &node) {
  314. if (func_graph()->get_return() != nullptr) {
  315. MS_LOG(EXCEPTION) << "Failure: have return node! NodeInfo: "
  316. << trace::GetDebugInfo(func_graph()->get_return()->debug_info());
  317. }
  318. std::vector<AnfNodePtr> input_nodes;
  319. input_nodes.emplace_back(NewValueNode(target_block->func_graph()));
  320. if (node != nullptr) {
  321. input_nodes.emplace_back(node);
  322. }
  323. CNodePtr jump = func_graph()->NewCNodeInOrder(input_nodes);
  324. jumps_[target_block.get()] = jump;
  325. target_block->AddPrevBlock(shared_from_this());
  326. func_graph()->set_output(jump);
  327. }
  328. // Perform a conditional jump using switch operation.
  329. // The first CNode select graph with condition, and than execute this graph
  330. void FunctionBlock::ConditionalJump(AnfNodePtr condNode, const FunctionBlockPtr &true_block,
  331. const FunctionBlockPtr &false_block, bool unroll_loop) {
  332. if (func_graph()->get_return() != nullptr) {
  333. MS_LOG(EXCEPTION) << "Failure: have return node! NodeInfo: "
  334. << trace::GetDebugInfo(func_graph()->get_return()->debug_info());
  335. }
  336. CNodePtr switch_app =
  337. func_graph()->NewCNodeInOrder({NewValueNode(prim::kPrimSwitch), condNode, NewValueNode(true_block->func_graph()),
  338. NewValueNode(false_block->func_graph())});
  339. CNodePtr switch_app_new = func_graph()->NewCNodeInOrder({switch_app});
  340. func_graph()->set_output(switch_app_new);
  341. }
  342. // Create cnode for the assign statement like 'self.target = source'.
  343. // convert it to 'P.Assign(self.target, source)' and then add the cnode as isolate node.
  344. void FunctionBlock::SetStateAssign(const AnfNodePtr &target, const AnfNodePtr &source) {
  345. const std::string primitive_name("assign");
  346. const std::string module_name("mindspore.ops.functional");
  347. ValueNodePtr assign_op = NewValueNode(prim::GetPythonOps(primitive_name, module_name, true));
  348. auto assign_node = func_graph_->NewCNodeInOrder({assign_op, target, source});
  349. MS_LOG(DEBUG) << "Isolated node found(Assign), assign_node: " << assign_node->DebugString(2) << ", block: " << this
  350. << "/" << (func_graph() ? func_graph()->ToString() : "FG(Null)")
  351. << ", Line: " << trace::GetDebugInfo(assign_node->debug_info(), "", kSourceLineTipDiscard);
  352. AddIsolatedNode(assign_node);
  353. }
  354. void FunctionBlock::FindIsolatedNodes() {
  355. //
  356. // Search isolate nodes from variables, for example,
  357. // variable 'a' is an isolate node in below code:
  358. //
  359. // def construct(self, x, y):
  360. // a = print(x) # isolate node
  361. // return x + y
  362. //
  363. std::set<AnfNodePtr> used;
  364. // Find used variables.
  365. for (const auto &var : vars_) {
  366. auto &node = var.second.first;
  367. if (node == nullptr) {
  368. continue;
  369. }
  370. bool is_used = var.second.second;
  371. if (is_used) {
  372. used.emplace(node);
  373. }
  374. }
  375. // Add isolated nodes which is unused var but not found in used set.
  376. for (const auto &var : vars_) {
  377. auto &node = var.second.first;
  378. bool is_used = var.second.second;
  379. if (node == nullptr || is_used) {
  380. continue;
  381. }
  382. auto &var_name = var.first;
  383. if (used.find(node) == used.end() && CanBeIsolatedNode(var_name, node)) {
  384. MS_LOG(INFO) << "Isolated node found(NoUse), node: " << node->DebugString(2) << ", var_name: " << var_name
  385. << ", block: " << this << "/" << (func_graph() ? func_graph()->ToString() : "FG(Null)")
  386. << ", Line: " << trace::GetDebugInfo(node->debug_info(), "", kSourceLineTipDiscard);
  387. AddIsolatedNode(node);
  388. }
  389. }
  390. }
  391. void FunctionBlock::AddIsolatedNode(const AnfNodePtr &target) { isolated_nodes_.add(target); }
  392. void FunctionBlock::AttachIsolatedNodesBeforeReturn() {
  393. if (isolated_nodes_.empty()) {
  394. return;
  395. }
  396. std::vector<AnfNodePtr> states;
  397. states.emplace_back(NewValueNode(prim::kPrimMakeTuple));
  398. for (auto &node : isolated_nodes_) {
  399. MS_LOG(DEBUG) << "Adding dependency, node: " << node->DebugString(2) << " in " << func_graph()->ToString();
  400. if (node->func_graph() == func_graph()) {
  401. states.emplace_back(node);
  402. } else {
  403. MS_LOG(INFO) << "Ignored FV dependency, node: " << node->DebugString(2) << " in " << func_graph()->ToString();
  404. }
  405. }
  406. isolated_nodes_.clear();
  407. AnfNodePtr state = nullptr;
  408. if (states.size() == 1) {
  409. // Only MakeTuple, no state left.
  410. return;
  411. } else if (states.size() == 2) {
  412. // If there are only MakeTuple and another node in states(the states size is 2),
  413. // do not need to MakeTuple, just use the node.
  414. state = states[1];
  415. } else {
  416. state = func_graph()->NewCNode(states);
  417. }
  418. AnfNodePtr old_output = nullptr;
  419. auto return_node = func_graph()->get_return();
  420. if (return_node) {
  421. if (return_node->inputs().empty()) {
  422. MS_LOG(EXCEPTION) << "Length of inputs of output node is less than 2";
  423. }
  424. old_output = return_node->input(1);
  425. } else {
  426. old_output = NewValueNode(kNone);
  427. }
  428. AnfNodePtr stop_grad_node = func_graph()->NewCNode({NewValueNode(prim::kPrimStopGradient), state});
  429. CNodePtr depend_node = func_graph()->NewCNode({NewValueNode(prim::kPrimDepend), old_output, stop_grad_node});
  430. // We add this attribute for @constexpr use scene, since we must infer them before other nodes.
  431. // That means isolated nodes will be evaluated first. It's not complete, but works in most scenes.
  432. depend_node->AddAttr(kAttrTopoSortRhsFirst, MakeValue(true));
  433. MS_LOG(INFO) << "Attached for side-effect nodes, depend_node: " << depend_node->DebugString()
  434. << ", state: " << state->DebugString(2);
  435. func_graph()->set_output(depend_node, true);
  436. }
  437. } // namespace parse
  438. } // namespace mindspore