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.

graph_handler.py 26 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Define the graph stream handler."""
  16. from mindinsight.conditionmgr.common.utils import NodeBasicInfo
  17. from mindinsight.conditionmgr.condition import TargetTypeEnum as CategoryTypeEnum
  18. from mindinsight.debugger.common.exceptions.exceptions import DebuggerParamValueError, \
  19. DebuggerNodeNotInGraphError, DebuggerGraphNotExistError
  20. from mindinsight.debugger.common.log import LOGGER as log
  21. from mindinsight.debugger.common.utils import is_scope_type
  22. from mindinsight.debugger.stream_cache.debugger_graph import DebuggerGraph
  23. from mindinsight.debugger.stream_cache.debugger_multigraph import DebuggerMultiGraph
  24. from mindinsight.debugger.stream_handler.base_handler import StreamHandlerBase
  25. class GraphHandler(StreamHandlerBase):
  26. """Metadata Handler."""
  27. def __init__(self):
  28. # dict of <graph_name, GraphProto object>
  29. self._graph_proto = {}
  30. # dict of <graph_name, DebuggerGraph object>
  31. self._graph = {}
  32. self._searched_node_list = {}
  33. # list of node names in bfs order
  34. self.bfs_order = []
  35. # dict of <node full name, graph_name>
  36. self.graph_node_map = {}
  37. # dict of <node ui name, Node object> for all graphs
  38. self._all_leaf_nodes = {}
  39. # the whole graph
  40. self._whole_graph = None
  41. @property
  42. def whole_graph(self):
  43. """The property of whole_graph."""
  44. return self._whole_graph
  45. @property
  46. def graph(self):
  47. """The property of graph."""
  48. return self._graph_proto
  49. @property
  50. def graph_names(self):
  51. """The property of graph names."""
  52. return list(self._graph)
  53. @property
  54. def debugger_graph_obj(self):
  55. """The property of graph object."""
  56. return self._graph
  57. def put(self, value):
  58. """
  59. Put value into graph cache. Called by grpc server.
  60. Args:
  61. value (GraphProto): The Graph proto message.
  62. """
  63. log.info("Put graph into cache.")
  64. for graph_name, graph_value in value.items():
  65. self._graph_proto[graph_name] = graph_value
  66. # build sub graph
  67. graph = DebuggerGraph()
  68. graph.build_graph(graph_value)
  69. self._graph[graph_name] = graph
  70. self.bfs_order.extend(graph.get_bfs_order())
  71. leaf_nodes = graph.leaf_nodes
  72. self._all_leaf_nodes.update(leaf_nodes)
  73. for _, node in leaf_nodes.items():
  74. self.graph_node_map[node.full_name] = graph_name
  75. # build whole graph
  76. graph = DebuggerMultiGraph()
  77. graph.add_graph(self._graph)
  78. self._whole_graph = graph
  79. def get(self, filter_condition=None):
  80. """
  81. Get the graph of specific node.
  82. Args:
  83. filter_condition (dict):
  84. - name (str): The full debug node name.
  85. - graph_name (str): The relative graph_name of the node.
  86. - single_node (bool): If True, return the graph from root
  87. to the specific node; else, return the sublayer of the
  88. graph. Default: False.
  89. Returns:
  90. dict, the metadata.
  91. """
  92. try:
  93. self._graph_exists()
  94. except DebuggerGraphNotExistError:
  95. log.warning('The graph is empty. To view a graph, '
  96. 'please start the training script first.')
  97. return {'graph': {}}
  98. graph = {}
  99. if filter_condition is None:
  100. filter_condition = {}
  101. graph = {'graph_names': self.graph_names}
  102. single_node = filter_condition.get('single_node', False)
  103. name = filter_condition.get('name')
  104. graph_name = filter_condition.get('graph_name')
  105. if single_node is True:
  106. nodes = self._get_single_node(name, graph_name)
  107. else:
  108. nodes = self._list_nodes(name, graph_name)
  109. graph.update(nodes)
  110. return {'graph': graph}
  111. def _get_single_node(self, name, graph_name=None):
  112. """
  113. Search node, and return every layer nodes until this node.
  114. Args:
  115. graph_name(str): The graph_name.
  116. name (str): The name of node.
  117. Returns:
  118. dict, every layer nodes until this node.
  119. """
  120. if graph_name:
  121. graph = self._get_graph(graph_name=graph_name)
  122. searched_graph = graph.search_single_node(name)
  123. else:
  124. searched_graph = self._whole_graph.search_single_node(name)
  125. return searched_graph
  126. def _list_nodes(self, scope, graph_name):
  127. """
  128. Get the nodes of every layer in graph.
  129. Args:
  130. scope (str): The name of a scope.
  131. graph_name(str): The graph name.
  132. Returns:
  133. TypedDict{'nodes': ['Node_1', ...], 'graph_names': ['graph_name_1', ...]},
  134. format is {'nodes': [<NodeObject>], 'graph_names': [<str>]}.
  135. example:
  136. {
  137. "nodes" : [
  138. {
  139. "attr" :
  140. {
  141. "index" : "i: 0\n"
  142. },
  143. "input" : {},
  144. "name" : "input_tensor",
  145. "output" :
  146. {
  147. "Default/TensorAdd-op17" :
  148. {
  149. "edge_type" : "data",
  150. "scope" : "name_scope",
  151. "shape" : [1, 16, 128, 128]
  152. }
  153. },
  154. "output_i" : -1,
  155. "proxy_input" : {},
  156. "proxy_output" : {},
  157. "independent_layout" : False,
  158. "subnode_count" : 0,
  159. "type" : "Data"
  160. }
  161. ]
  162. }
  163. """
  164. if graph_name:
  165. graph = self._get_graph(graph_name, scope)
  166. nodes = graph.list_node_by_scope(scope=scope)
  167. res = {'nodes': nodes}
  168. else:
  169. nodes = self._whole_graph.list_node_by_scope(scope=scope)
  170. res = {'nodes': nodes}
  171. return res
  172. def get_tensor_history(self, node_name, graph_name=None, depth=0):
  173. """
  174. Get the tensor history of a specified node.
  175. Args:
  176. node_name (str): The debug name of the node.
  177. graph_name (str): The graph_name. Default: None.
  178. depth (int): The number of layers the user
  179. wants to trace. Default is 0.
  180. Returns:
  181. dict, basic tensor history, only including tensor name and tensor type and node type.
  182. """
  183. graph_name, node_name = self._parse_node_name(node_name, graph_name)
  184. graph = self._get_graph(graph_name=graph_name, node_name=node_name)
  185. # validate node type, scope node has no tensor history
  186. node_type = graph.get_node_type(node_name)
  187. if is_scope_type(node_type):
  188. log.error("Scope type node has no tensor history.")
  189. raise DebuggerParamValueError("Invalid leaf node name.")
  190. # get tensor history
  191. tensor_history, cur_outputs_nums = graph.get_tensor_history(node_name, depth)
  192. # add the tensor type for tensor history
  193. self._update_tensor_history(tensor_history[0:cur_outputs_nums], 'output', graph_name)
  194. self._update_tensor_history(tensor_history[cur_outputs_nums:], 'input', graph_name)
  195. log.debug("Get %d tensors in tensor history for node <%s>.", len(tensor_history), node_name)
  196. return {'tensor_history': tensor_history}
  197. @staticmethod
  198. def _update_tensor_history(tensor_history, tensor_type, graph_name):
  199. """
  200. Add tensor source type for tensor history.
  201. Args:
  202. tensor_history (list[dict]): Tensor history from Graph stream. Each element has two
  203. keys: `node_type` and `name`. `node_type` refers to the type of the node which
  204. the tensor come from. `name` refers to the tensor name.
  205. tensor_type (str): The source type of the tensor. `input` or `output`.
  206. graph_name (str): The graph name.
  207. """
  208. for single_tensor_info in tensor_history:
  209. single_tensor_info['type'] = tensor_type
  210. single_tensor_info['graph_name'] = graph_name
  211. def search_nodes(self, pattern):
  212. """
  213. Search nodes by given pattern.
  214. Args:
  215. pattern (dict): Filter condition.
  216. - name (str): The name pattern.
  217. - graph_name (str): The graph name.
  218. - node_category (str): The node_category. Default: None
  219. - condition (dict): The additional filter condition.
  220. Returns:
  221. dict, the searched node.
  222. """
  223. graph_name = pattern.pop('graph_name', None)
  224. search_nodes = self.get_searched_nodes(pattern, graph_name)
  225. # construct to search tree
  226. if not self._has_graph_scope(graph_name):
  227. for graph_name, searched_node_list in search_nodes.items():
  228. graph = self._get_graph(graph_name=graph_name)
  229. format_nodes = graph.get_nodes(searched_node_list)
  230. return {'nodes': format_nodes}
  231. # deal with graph_name is None
  232. res = []
  233. for graph_name, graph in self._graph.items():
  234. format_nodes = graph.get_nodes(search_nodes.get(graph_name, []))
  235. if not format_nodes:
  236. continue
  237. self._add_graph_scope_for_nodes(format_nodes, graph_name)
  238. search_graph = {
  239. 'name': graph_name,
  240. 'type': 'name_scope',
  241. 'nodes': format_nodes
  242. }
  243. res.append(search_graph)
  244. return {'nodes': res}
  245. def get_searched_node_list(self, pattern, graph_name):
  246. """Get searched node list in single graph."""
  247. searched_nodes = self.get_searched_nodes(pattern, graph_name)
  248. return searched_nodes.get(graph_name, [])
  249. def get_searched_nodes(self, pattern, graph_name=None):
  250. """
  251. Search nodes by given pattern.
  252. Args:
  253. pattern (dict): Filter condition.
  254. - name (str): The name pattern.
  255. - node_category (str): The node_category. Default: None
  256. - condition (dict): The additional filter condition.
  257. graph_name (str): The graph name. If not given, search in all sub graphs. Default: None.
  258. Returns:
  259. dict, the searched nodes. The format is dict of <graph_name, list[Node]>.
  260. """
  261. if not graph_name:
  262. graph_names = self.graph_names
  263. else:
  264. graph_names = [graph_name]
  265. search_nodes = {}
  266. for sub_graph_name in graph_names:
  267. search_nodes[sub_graph_name] = self._search_in_single_graph(pattern, sub_graph_name)
  268. return search_nodes
  269. def _search_in_single_graph(self, pattern, graph_name=None):
  270. """
  271. Search nodes by given pattern.
  272. Args:
  273. pattern (dict): Filter condition.
  274. - name (str): The name pattern.
  275. - node_category (str): The node_category. Default: None.
  276. - condition (dict): The additional filter condition.
  277. graph_name (str): The graph name.
  278. Returns:
  279. list, the searched node list.
  280. """
  281. temp_node_list = []
  282. node_category = pattern.get('node_category')
  283. if graph_name:
  284. graph = self._get_graph(graph_name=graph_name)
  285. else:
  286. graph = self._whole_graph
  287. # filter nodes by name
  288. if pattern.get('name'):
  289. if node_category:
  290. # get leaf nodes for forward filter
  291. temp_node_list = graph.search_leaf_nodes_by_pattern(pattern.get('name'))
  292. else:
  293. # optimize search nodes
  294. temp_node_list = graph.search_nodes_by_pattern(pattern.get('name'))
  295. if not temp_node_list:
  296. log.debug("No node named %s", pattern.get('name'))
  297. return []
  298. # filter nodes by category
  299. if node_category:
  300. node_category = self._get_inner_node_category(node_category)
  301. condition = pattern['condition'].copy() if pattern.get('condition') else {}
  302. condition['search_range'] = temp_node_list
  303. temp_node_list = graph.search_nodes_by_category(node_category, condition=condition)
  304. return temp_node_list
  305. @staticmethod
  306. def _get_inner_node_category(node_category):
  307. """
  308. Get inner node category.
  309. Args:
  310. node_category (str): The node category supported in
  311. mindinsight.conditionmgr.condition.TargetTypeEnum.
  312. Returns:
  313. CategoryTypeEnum, the translated value.
  314. """
  315. try:
  316. res = CategoryTypeEnum(node_category)
  317. except ValueError as err:
  318. log.error("Invalid node category. %s", err)
  319. raise DebuggerParamValueError("Invalid node_category.")
  320. return res
  321. def get_nodes_by_scope(self, scope_name, graph_name):
  322. """
  323. Get node by a given scope name.
  324. Args:
  325. scope_name (str): The name of scope.
  326. graph_name (str): The relative graph_name of the watched node. Default: None.
  327. Returns:
  328. list[Node], a list of node.
  329. """
  330. if graph_name:
  331. graph = self._get_graph(graph_name)
  332. else:
  333. graph = self._whole_graph
  334. return graph.search_leaf_nodes_by_pattern(scope_name)
  335. def get_graph_id_by_name(self, node_name):
  336. """
  337. Get graph id by full name.
  338. Args:
  339. node_name (str): The name of the node.
  340. Returns:
  341. str, the graph name of the node.
  342. Raises:
  343. DebuggerNodeNotInGraphError: If can not find the node in all graphs.
  344. """
  345. if node_name:
  346. for graph_name, sub_graph in self._graph.items():
  347. if sub_graph.exist_node(name=node_name):
  348. return graph_name
  349. log.error('Failed to find node %s in graph. Please make sure the graph has been sent and '
  350. 'the node name is correct, and try again.', node_name)
  351. raise DebuggerGraphNotExistError
  352. def get_graph_id_by_full_name(self, node_name):
  353. """
  354. Get graph id by full name.
  355. Args:
  356. node_name (str): The full name of the node.
  357. Returns:
  358. str, the graph name of the node.
  359. Raises:
  360. DebuggerNodeNotInGraphError: If can not find the node in all graphs.
  361. """
  362. graph_id = self.graph_node_map.get(node_name) if node_name else None
  363. if not graph_id:
  364. log.error("Failed to get graph id by full name: %s", node_name)
  365. raise DebuggerNodeNotInGraphError(node_name)
  366. return graph_id
  367. def get_node_type(self, node_name, graph_name=None):
  368. """
  369. Get the type of the specified node.
  370. Args:
  371. node_name (str): The debug name of the node.
  372. graph_name (str): The relative graph_name of the node. Default: None.
  373. Returns:
  374. A string of the node type, name_scope or leaf.
  375. """
  376. if graph_name:
  377. graph = self._get_graph(node_name=node_name, graph_name=graph_name)
  378. else:
  379. graph = self._whole_graph
  380. node_type = graph.get_node_type(node_name)
  381. return node_type
  382. def get_full_name(self, node_name, graph_name=None):
  383. """Get full name according to ui node name."""
  384. full_name = ''
  385. if node_name:
  386. if graph_name:
  387. graph = self._get_graph(node_name=node_name, graph_name=graph_name)
  388. else:
  389. graph = self._whole_graph
  390. full_name = graph.get_full_name_by_node_name(node_name)
  391. return full_name
  392. def get_node_basic_info(self, node_name, graph_name):
  393. """Get node basic info with graph scope."""
  394. graph_name, node_name = self._parse_node_name(node_name=node_name, graph_name=graph_name)
  395. graph = self._get_graph(graph_name, node_name)
  396. full_name = graph.get_full_name_by_node_name(node_name)
  397. node_type = graph.get_node_type(node_name)
  398. return self.construct_node_basic_info(full_name, graph_name, node_name, node_type)
  399. def get_tensor_graph(self, tensor_name, graph_name):
  400. """
  401. Get tensor graph according to node name.
  402. Args:
  403. tensor_name (str): Tensor name, format is "node_name:<node_value>".
  404. graph_name (str): The relative graph_name of the node. Default: None.
  405. Returns:
  406. dict, relative node.
  407. """
  408. node_name, _ = tensor_name.rsplit(':', 1)
  409. graph = self._get_graph(graph_name=graph_name, node_name=node_name)
  410. tensor_graph = graph.get_tensor_graph(node_name)
  411. return {'graph': tensor_graph}
  412. @staticmethod
  413. def construct_node_basic_info(full_name, graph_name, node_name, node_type):
  414. """Construct node basic info."""
  415. node_name_with_graph_scope = '/'.join([graph_name, node_name]) if node_name else graph_name
  416. return NodeBasicInfo(name=node_name_with_graph_scope, full_name=full_name, type=node_type)
  417. def get_node_basic_info_by_scope(self, scope_name, graph_name):
  418. """
  419. Get node by a given scope name.
  420. Args:
  421. scope_name (str): The name of scope.
  422. graph_name (str): The relative graph_name of the watched node. Default: None.
  423. Returns:
  424. list[NodeBasicInfo], a list of node.
  425. """
  426. graph_name, node_name = self._parse_node_name(scope_name, graph_name)
  427. graph = self._get_graph(graph_name)
  428. nodes = graph.search_leaf_nodes_by_pattern(node_name)
  429. res = [self.construct_node_basic_info(full_name=node.full_name,
  430. graph_name=graph_name,
  431. node_name=node.name,
  432. node_type=node.type) for node in nodes]
  433. return res
  434. def get_node_name_by_full_name(self, full_name, graph_name):
  435. """Get UI node name by full name and graph name."""
  436. if graph_name and full_name:
  437. graph = self._get_graph(graph_name)
  438. node_name = graph.get_node_name_by_full_name(full_name)
  439. else:
  440. node_name = ''
  441. log.debug("Get empty full name.")
  442. return node_name
  443. def get_node_by_bfs_order(self, node_name=None, ascend=True):
  444. """
  445. Traverse the graph in order of breath-first search by given node.
  446. Args:
  447. node_name (str): The name of current chosen leaf node.
  448. ascend (bool): If True, traverse the input nodes;
  449. If False, traverse the output nodes. Default is True.
  450. Returns:
  451. Union[None, dict], the next node object in dict type or None.
  452. """
  453. bfs_order = self.bfs_order
  454. length = len(bfs_order)
  455. if not bfs_order:
  456. log.error('Cannot get the BFS order of the graph!')
  457. msg = 'Cannot get the BFS order of the graph!'
  458. raise DebuggerParamValueError(msg)
  459. if node_name is None:
  460. if ascend is False:
  461. next_node = None
  462. else:
  463. next_node = bfs_order[0]
  464. else:
  465. try:
  466. index = bfs_order.index(node_name)
  467. log.debug("The index of the node in BFS list is: %d", index)
  468. except ValueError as err:
  469. log.error('Cannot find the node: %s. Please check '
  470. 'the node name: %s', node_name, err)
  471. msg = f'Cannot find the node: {node_name}. ' \
  472. f'Please check the node name {err}.'
  473. raise DebuggerParamValueError(msg)
  474. next_node = self._get_next_node_in_bfs(index, length, ascend)
  475. return next_node
  476. def _get_next_node_in_bfs(self, index, length, ascend):
  477. """
  478. Get the next node in bfs order.
  479. Args:
  480. index (int): The current index.
  481. length (int): The number of all leaf nodes.
  482. ascend (bool): Whether get the node in ascend order or not.
  483. Returns:
  484. Union[None, dict], the next node object in dict type or None.
  485. """
  486. next_node = None
  487. if 0 <= index < length:
  488. if ascend is True and index < length - 1:
  489. next_node = self.bfs_order[index + 1]
  490. elif ascend is False and index > 0:
  491. next_node = self.bfs_order[index - 1]
  492. return next_node
  493. def _graph_exists(self):
  494. """
  495. Check if the graph has been loaded in the debugger cache.
  496. Raises:
  497. DebuggerGraphNotExistError: If the graph does not exist.
  498. """
  499. if not self._graph:
  500. log.error('The graph does not exist. Please start the '
  501. 'training script and try again.')
  502. raise DebuggerGraphNotExistError
  503. def _get_graph(self, graph_name=None, node_name=None):
  504. """
  505. Get the graph object according to graph name and node name.
  506. Args:
  507. graph_name (str): The graph name.
  508. node_name (str): The node name.
  509. Returns:
  510. DebuggerGraph, the graph object.
  511. Raises:
  512. DebuggerGraphNotExistError: If the graph does not exist.
  513. """
  514. if not graph_name and not node_name and len(self._graph) == 1:
  515. # get the graph if there is only one graph
  516. return list(self._graph.values())[0]
  517. graph_name = graph_name if graph_name else self.get_graph_id_by_name(node_name)
  518. graph = self._graph.get(graph_name) if graph_name else None
  519. # get graph according to graph name and check the node
  520. if graph and (not node_name or graph.exist_node(name=node_name)):
  521. return graph
  522. log.error('The graph %s does not exist node %s.', graph_name, node_name)
  523. raise DebuggerGraphNotExistError
  524. def _has_graph_scope(self, graph_name):
  525. """Check if query with graph_scope."""
  526. return bool(graph_name is None and len(self._graph) > 1)
  527. def validate_graph_name(self, graph_name):
  528. """Validate graph_name."""
  529. if graph_name and self._graph.get(graph_name) is None:
  530. log.error("No graph named %s in debugger cache.", graph_name)
  531. raise DebuggerGraphNotExistError
  532. if not graph_name and len(self._graph) == 1:
  533. graph_name = self.graph_names[0]
  534. return graph_name
  535. def _add_graph_scope_for_nodes(self, nodes, graph_name):
  536. """
  537. Add graph scope for nodes.
  538. Args:
  539. nodes (list[Node]): List of nodes object.
  540. graph_name (str): The graph name.
  541. """
  542. def _get_updated_node_info(cur_node, node_type):
  543. """Add graph scope in key."""
  544. old_node = cur_node.get(node_type)
  545. if not old_node:
  546. return
  547. new_values = {}
  548. for old_name, node_info in old_node.items():
  549. new_name = '/'.join([graph_name, old_name]) if old_name else graph_name
  550. new_values[new_name] = node_info
  551. cur_node[node_type] = new_values
  552. for node in nodes:
  553. node['name'] = '/'.join([graph_name, node['name']]) if node['name'] else graph_name
  554. _get_updated_node_info(node, 'input')
  555. _get_updated_node_info(node, 'output')
  556. if node.get('nodes'):
  557. self._add_graph_scope_for_nodes(node.get('nodes'), graph_name)
  558. def _parse_node_name(self, node_name, graph_name):
  559. """
  560. Check if the node name should have graph scope.
  561. Args:
  562. node_name (str): The ui node name.
  563. graph_name (str): The graph name.
  564. Returns:
  565. str, parsed graph name.
  566. str, parsed node name.
  567. """
  568. node_name = '' if node_name is None else node_name
  569. if self._has_graph_scope(graph_name):
  570. names = node_name.split("/", 1)
  571. graph_name = names[0]
  572. node_name = names[1] if len(names) == 2 else ''
  573. if graph_name is None and len(self._graph) == 1:
  574. graph_name = self.graph_names[0]
  575. return graph_name, node_name
  576. def validate_node_name(self, node_name, graph_name):
  577. """
  578. Validate the graph exist the specified node.
  579. Args:
  580. node_name (str): The ui node name.
  581. graph_name (str): The graph name.
  582. Raises:
  583. DebuggerNodeNotInGraphError: If can not find the node in all graphs.
  584. """
  585. graph = self._get_graph(graph_name=graph_name)
  586. if not graph.exist_node(name=node_name):
  587. log.error("graph %s doesn't find node: %s.", graph_name, node_name)
  588. raise DebuggerNodeNotInGraphError(node_name)