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.

watchpoint_handler.py 25 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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 watchpoint stream handler."""
  16. from mindinsight.debugger.conditionmgr.condition import ValueTypeEnum
  17. from mindinsight.debugger.conditionmgr.condition import ParamTypeEnum
  18. from mindinsight.debugger.common.exceptions.exceptions import DebuggerParamValueError, \
  19. DebuggerParamTypeError
  20. from mindinsight.debugger.common.log import LOGGER as log
  21. from mindinsight.debugger.common.utils import is_scope_type
  22. from mindinsight.debugger.proto.debug_grpc_pb2 import SetCMD
  23. from mindinsight.debugger.stream_cache.watchpoint import Watchpoint, WatchpointHit, \
  24. WatchNodeTree
  25. from mindinsight.debugger.stream_handler.base_handler import StreamHandlerBase
  26. RANGE_START = 'range_start_inclusive'
  27. RANGE_END = 'range_end_inclusive'
  28. class WatchpointHandler(StreamHandlerBase):
  29. """Watchpoint Handler."""
  30. def __init__(self):
  31. self._watchpoints = {}
  32. # list of ids of new created watchpoints
  33. self._created_watchpoints = []
  34. # list of SetCMD of watchpoints to be deleted
  35. self._deleted_watchpoints = []
  36. # dict of <id, Watchpoint> of watchpoints to be updated
  37. self._updated_watchpoints = {}
  38. # the collection of watched node full names, which have been sent to MindSpore
  39. self._latest_id = 0
  40. self._cache_set_cmd = {}
  41. # whether the watchpoint list has been changed since last step
  42. self._outdated = False
  43. def put(self, value):
  44. """
  45. Put Watchpoint into watchpoint handler.
  46. Args:
  47. value (Watchpoint): The name of nodes that have been chosen.
  48. """
  49. new_id = value.watchpoint_id
  50. self._watchpoints[new_id] = value
  51. self._created_watchpoints.append(new_id)
  52. self._updated_watchpoints[new_id] = value
  53. self._latest_id = new_id
  54. log.debug("Put watchpoint %d into cache.", new_id)
  55. def sync_set_cmd(self, set_cmds):
  56. """Clean temp watchpoints."""
  57. self._outdated = False
  58. self._created_watchpoints = []
  59. self._deleted_watchpoints = []
  60. self._updated_watchpoints = {}
  61. for set_cmd in set_cmds:
  62. self._cache_set_cmd[set_cmd.id] = set_cmd
  63. def clean_cache_set_cmd(self, set_cmd):
  64. """Clean cache set command."""
  65. self._cache_set_cmd.pop(set_cmd.id, None)
  66. def get_watchpoint_by_id(self, watchpoint_id):
  67. """Get watchpoint by watchpoint id."""
  68. res = self.get(watchpoint_id)
  69. watchpoint = res.get('watch_points')[0]
  70. return watchpoint
  71. def get(self, filter_condition=None):
  72. """
  73. Get the watchpoints.
  74. Args:
  75. filter_condition (Union[None, int]): The filter conditions. Get watchpoint by
  76. id. If None, return all watchpoint. Default: None.
  77. Returns:
  78. dict, the watchpoint list.
  79. """
  80. reply = []
  81. if not filter_condition:
  82. # get watch condition list
  83. for _, watchpoint in self._watchpoints.items():
  84. watchpoint_info = watchpoint.get_watch_condition_info()
  85. reply.append(watchpoint_info)
  86. else:
  87. self.validate_watchpoint_id(filter_condition)
  88. reply = [self._watchpoints.get(filter_condition)]
  89. log.debug("get the watch points with filter_condition:%s", filter_condition)
  90. return {'watch_points': reply}
  91. def get_pending_commands(self, graph_stream):
  92. """
  93. Get all watchpoint in SetCMD proto format.
  94. Args:
  95. graph_stream (GraphHandler): Graph handler.
  96. Returns:
  97. list[SetCMD], updated watchpoint to be sent to MindSpore.
  98. """
  99. newly_set_cmds = []
  100. for _, watchpoint in self._updated_watchpoints.items():
  101. # construct set command with leaf nodes
  102. watch_nodes = watchpoint.get_watch_nodes()
  103. leaf_watch_nodes = self._expand_to_leaf_nodes(graph_stream, watch_nodes)
  104. newly_set_cmds.append(watchpoint.get_pending_cmd(leaf_watch_nodes))
  105. newly_set_cmds.extend(self._deleted_watchpoints)
  106. self.sync_set_cmd(newly_set_cmds)
  107. return list(self._cache_set_cmd.values())
  108. @staticmethod
  109. def _expand_to_leaf_nodes(graph_stream, watch_nodes):
  110. """
  111. Get all leaf node basic info according to watch nodes.
  112. Args:
  113. graph_stream (GraphHandler): Graph handler.
  114. watch_nodes (list[NodeBasicInfo]): The list of watch node basic infos.
  115. Returns:
  116. list[NodeBasicInfo], expanded leaf basic node infos.
  117. """
  118. leaf_watch_nodes = []
  119. for node in watch_nodes:
  120. if is_scope_type(node.type):
  121. pure_node_name = None
  122. if len(node.name.split('/')) > 1:
  123. graph_name, pure_node_name = node.name.split('/', 1)
  124. else:
  125. graph_name = node.name
  126. search_node_infos = graph_stream.get_node_basic_info_by_scope(pure_node_name, graph_name=graph_name)
  127. leaf_watch_nodes.extend(search_node_infos)
  128. else:
  129. leaf_watch_nodes.append(node)
  130. return leaf_watch_nodes
  131. def is_recheckable(self):
  132. """
  133. Check if current status is able to recheck.
  134. Returns:
  135. bool, if enable to recheck.
  136. """
  137. return self._outdated
  138. def set_watch_nodes(self, graph, graph_stream, watch_point_id, graph_name=None):
  139. """
  140. set watch nodes for graph.
  141. Args:
  142. graph (dict): The graph with list of nodes.
  143. graph_stream (GraphHandler): The graph handler.
  144. watch_point_id (int): The id of watchpoint.
  145. graph_name (str): The graph name.
  146. """
  147. if not (watch_point_id and graph):
  148. return
  149. log.debug("add watch flags")
  150. watchpoint = self._watchpoints.get(watch_point_id)
  151. self._set_watch_status_recursively(graph, graph_stream, watchpoint, graph_name)
  152. def _set_watch_status_recursively(self, graph, graph_stream, watchpoint, graph_name=None):
  153. """Set watch status to graph."""
  154. if graph.get('children'):
  155. self._set_watch_status_recursively(
  156. graph.get('children'), graph_stream, watchpoint, graph_name)
  157. if graph.get('nodes'):
  158. _ = self._set_watch_state_for_nodes(graph['nodes'], graph_stream, watchpoint, graph_name)
  159. def _set_watch_state_for_nodes(self, nodes, graph_stream, watchpoint, graph_name):
  160. """
  161. Set watch state for nodes.
  162. Args:
  163. nodes (list[Node]): List of node info.
  164. Returns:
  165. int, the number of all watched nodes.
  166. """
  167. all_watched_num = 0
  168. valid_node_num = len(nodes)
  169. # initialize the state of current node.
  170. state = WatchNodeTree.NOT_WATCH
  171. for node in nodes:
  172. node_name = node.get('name')
  173. # search result could have `nodes` in nodes object
  174. if node.get('nodes'):
  175. flag = self._set_watch_state_for_nodes(node.get('nodes'), graph_stream, watchpoint, graph_name)
  176. else:
  177. full_name = graph_stream.get_full_name(node_name, graph_name)
  178. new_node_name = node_name if graph_name is None else '/'.join([graph_name, node_name])
  179. flag = watchpoint.get_node_status(new_node_name, node.get('type'), full_name)
  180. node['watched'] = flag
  181. if flag == WatchNodeTree.NOT_WATCH:
  182. continue
  183. state = WatchNodeTree.PARTIAL_WATCH
  184. if flag == WatchNodeTree.INVALID:
  185. valid_node_num -= 1
  186. elif flag == WatchNodeTree.TOTAL_WATCH:
  187. all_watched_num += 1
  188. # update the watch status of current node
  189. if not valid_node_num:
  190. state = WatchNodeTree.INVALID
  191. elif all_watched_num == valid_node_num:
  192. state = WatchNodeTree.TOTAL_WATCH
  193. return state
  194. def create_watchpoint(self, condition_mgr, watch_condition, watch_nodes=None, watch_point_id=None, name=None):
  195. """
  196. Create watchpoint.
  197. Args:
  198. condition_mgr (ConditionMgr): Instance of ConditionMgr.
  199. watch_condition (dict): The watch condition.
  200. "condition": {
  201. id: "tensor_too_large",
  202. "params": [
  203. {
  204. "name": "abs_mean_gt",
  205. "value": 1.1
  206. }
  207. ]
  208. }
  209. - id (str): Id of condition.
  210. - param (list[dict]): The list of param for this condition.
  211. watch_nodes (list[NodeBasicInfo]): The list of node basic info.
  212. watch_point_id (int): The id of watchpoint.
  213. name (str): The name of watchpoint.
  214. Returns:
  215. int, the new id of watchpoint.
  216. """
  217. validate_watch_condition(condition_mgr, watch_condition)
  218. watch_condition = set_default_param(condition_mgr, watch_condition)
  219. new_id = self._latest_id + 1
  220. watchpoint = Watchpoint(new_id, watch_condition, name)
  221. if watch_nodes:
  222. watchpoint.add_nodes(watch_nodes)
  223. elif watch_point_id:
  224. self.validate_watchpoint_id(watch_point_id)
  225. watchpoint.copy_nodes_from(self._watchpoints.get(watch_point_id))
  226. self.put(watchpoint)
  227. self._outdated = True
  228. return new_id
  229. def update_watchpoint(self, watch_point_id, watch_nodes, watched=False):
  230. """
  231. Update watchpoint.
  232. Args:
  233. watch_point_id (int): The id of watchpoint.
  234. watch_nodes (list[NodeBasicInfo]): The list of node basic info.
  235. watched (bool): The update operator on nodes. If False, remove nodes from watch nodes.
  236. If True, add nodes to watch nodes. Default: False.
  237. """
  238. self.validate_watchpoint_id(watch_point_id)
  239. watchpoint = self._watchpoints.get(watch_point_id)
  240. if watched:
  241. watchpoint.add_nodes(watch_nodes)
  242. else:
  243. watchpoint.remove_nodes(watch_nodes)
  244. self._updated_watchpoints[watch_point_id] = watchpoint
  245. self._outdated = True
  246. log.debug("Update watchpoint %d in cache.", watch_point_id)
  247. def delete_watchpoint(self, watch_point_id=None):
  248. """
  249. Delete watchpoint.
  250. Args:
  251. watch_point_id (Union[None, int]): The id of watchpoint.
  252. If None, delete all watchpoints. Default: None.
  253. """
  254. if watch_point_id is None:
  255. watch_point_ids = [sub_id for sub_id, _ in self._watchpoints.items()]
  256. else:
  257. self.validate_watchpoint_id(watch_point_id)
  258. watch_point_ids = [watch_point_id]
  259. for single_id in watch_point_ids:
  260. self._delete_single_watchpoint(single_id)
  261. self._outdated = True
  262. def _delete_single_watchpoint(self, watch_point_id):
  263. """
  264. Delete single watchpoint.
  265. Args:
  266. watch_point_id (int): The id of watchpoint.
  267. """
  268. self._watchpoints.pop(watch_point_id)
  269. # if the watchpoint has not been created by MindSpore, clean the relative cache directly
  270. if watch_point_id in self._created_watchpoints:
  271. self._created_watchpoints.remove(watch_point_id)
  272. self._updated_watchpoints.pop(watch_point_id)
  273. log.debug("Cancel create watchpoint %d in cache.", watch_point_id)
  274. return
  275. set_cmd = SetCMD()
  276. set_cmd.id = watch_point_id
  277. set_cmd.delete = True
  278. self._deleted_watchpoints.append(set_cmd)
  279. log.debug("Delete watchpoint %d in cache.", watch_point_id)
  280. def validate_watchpoint_id(self, watch_point_id):
  281. """Validate watchpoint id."""
  282. if not isinstance(watch_point_id, int):
  283. log.error("Invalid watchpoint id %s. The watch point id should be int.", watch_point_id)
  284. raise DebuggerParamTypeError("Watchpoint id should be int type.")
  285. if watch_point_id and watch_point_id not in self._watchpoints:
  286. log.error("Invalid watchpoint id: %d.", watch_point_id)
  287. raise DebuggerParamValueError("Invalid watchpoint id: {}".format(watch_point_id))
  288. class WatchpointHitHandler(StreamHandlerBase):
  289. """Watchpoint hit handler."""
  290. def __init__(self):
  291. # dict of <ui node_name, dict of <slot, WatchpointHit>>,
  292. self._hits = {}
  293. @property
  294. def empty(self):
  295. """Whether the watchpoint hit is empty."""
  296. return not self._hits
  297. def put(self, value):
  298. """
  299. Put value into watchpoint hit cache. Called by grpc server.
  300. Args:
  301. value (dict): The watchpoint hit info.
  302. - tensor_proto (TensorProto): The message about hit tensor.
  303. - watchpoint (Watchpoint): The Watchpoint that a node hit.
  304. - node_name (str): The UI node name.
  305. - graph_name (str): The graph name.
  306. """
  307. watchpoint_hit = WatchpointHit(
  308. tensor_proto=value.get('tensor_proto'),
  309. watchpoint=value.get('watchpoint'),
  310. node_name=value.get('node_name'),
  311. graph_name=value.get('graph_name')
  312. )
  313. if 'error_code' in value.keys():
  314. watchpoint_hit.error_code = value.get('error_code')
  315. # get all hit watchpoints according to node name ans tensor slot
  316. watchpoint_hits = self._get_watchpoints_by_tensor_name(watchpoint_hit.node_name,
  317. watchpoint_hit.slot)
  318. if watchpoint_hit not in watchpoint_hits:
  319. watchpoint_hits.append(watchpoint_hit)
  320. def _get_watchpoints_by_tensor_name(self, node_name, slot):
  321. """
  322. Get hit tensors according to ui node name and slot.
  323. Args:
  324. node_name (str): The node name.
  325. slot (str): The tensor slot.
  326. Returns:
  327. list, list of watchpoints.
  328. """
  329. hit_node = self._hits.get(node_name)
  330. if hit_node is None:
  331. hit_node = {}
  332. self._hits[node_name] = hit_node
  333. hit_tensors = hit_node.get(slot)
  334. if hit_tensors is None:
  335. hit_tensors = []
  336. hit_node[slot] = hit_tensors
  337. return hit_tensors
  338. def get(self, filter_condition=None):
  339. """
  340. Get watchpoint hit list.
  341. Args:
  342. filter_condition (str): Get the watchpoint hit according to specified node name.
  343. If not given, get all watchpoint hits. Default: None.
  344. Returns:
  345. dict, the watchpoint hit list.
  346. """
  347. if filter_condition is None:
  348. log.debug("Get all watchpoint hit list.")
  349. reply = self.get_watchpoint_hits()
  350. else:
  351. log.debug("Get the watchpoint for node: <%s>.", filter_condition)
  352. reply = self._hits.get(filter_condition)
  353. return reply
  354. def get_watchpoint_hits(self):
  355. """Return the list of watchpoint hits."""
  356. watch_point_hits = []
  357. for node_name, watchpoint_hits in self._hits.items():
  358. tensors = []
  359. graph_name = None
  360. for slot, tensor_hits in watchpoint_hits.items():
  361. if graph_name is None:
  362. graph_name = tensor_hits[0].graph_name
  363. tensor_info = self._get_tensor_hit_info(slot, tensor_hits)
  364. tensors.append(tensor_info)
  365. watch_point_hits.append({
  366. 'node_name': node_name,
  367. 'tensors': tensors,
  368. 'graph_name': graph_name
  369. })
  370. return {'watch_point_hits': watch_point_hits}
  371. @staticmethod
  372. def _get_tensor_hit_info(slot, tensor_hits):
  373. """
  374. Get watchpoint hit info of specified tensor.
  375. Args:
  376. slot (str): Slot id.
  377. tensor_hits (list): A list of watchpoint hit objects that the tensor hit.
  378. Returns:
  379. dict, tensor hit info.
  380. """
  381. res = {}
  382. watch_points = []
  383. for tensor_hit in tensor_hits:
  384. error_code = tensor_hit.error_code
  385. error_list = _get_error_list(error_code)
  386. watchpoint = tensor_hit.watchpoint
  387. watchpoint['error_code'] = error_code
  388. watchpoint['error_list'] = error_list
  389. watch_points.append(watchpoint)
  390. if watch_points:
  391. watch_points.sort(key=lambda watch_point: watch_point.get('id'))
  392. res = {
  393. 'slot': slot,
  394. 'watch_points': watch_points
  395. }
  396. return res
  397. def _is_tensor_hit(self, tensor_name):
  398. """
  399. Check if the tensor is record in hit cache.
  400. Args:
  401. tensor_name (str): The name of ui tensor name.
  402. Returns:
  403. bool, if the tensor is hit.
  404. """
  405. node_name, slot = tensor_name.rsplit(':', 1)
  406. watchpoint_hits = self._hits.get(node_name, {}).get(slot)
  407. return bool(watchpoint_hits)
  408. def update_tensor_history(self, tensor_history):
  409. """
  410. Add hit flag to tensor history.
  411. Args:
  412. tensor_history (dict): The tensor history.
  413. """
  414. if not self._hits:
  415. return
  416. # add hit tensor names to `tensor_names`
  417. for tensor_info in tensor_history.get('tensor_history'):
  418. tensor_name = tensor_info['name']
  419. hit_flag = self._is_tensor_hit(tensor_name)
  420. tensor_info['is_hit'] = hit_flag
  421. def get_tensor_hit_infos(self, tensor_name):
  422. """
  423. Get all hit information of a tensor.
  424. Args:
  425. tensor_name (str): Tensor name showed on UI.
  426. Returns:
  427. dict, tensor hit info.
  428. """
  429. tensor_hit_info = {}
  430. if self._is_tensor_hit(tensor_name):
  431. node_name, slot = tensor_name.rsplit(':', 1)
  432. tensor_hits = self._get_watchpoints_by_tensor_name(node_name, slot)
  433. tensor_hit_info = self._get_tensor_hit_info(slot, tensor_hits)
  434. return tensor_hit_info
  435. def validate_watch_condition(condition_mgr, watch_condition):
  436. """Validate watch condition."""
  437. if not isinstance(watch_condition, dict):
  438. log.error("<watch_condition> should be dict. %s received.", watch_condition)
  439. raise DebuggerParamTypeError("<watch_condition> should be dict.")
  440. # validate condition_id
  441. condition_id = watch_condition.get('id')
  442. if condition_id not in condition_mgr.conditions.keys():
  443. log.error("Invalid watch condition. Acceptable values are <%s>. %s received.",
  444. str(condition_mgr.conditions.keys()), condition_id)
  445. raise DebuggerParamValueError("Invalid watch condition value.")
  446. # validate param
  447. validate_watch_condition_params(condition_mgr, watch_condition)
  448. def validate_watch_condition_params(condition_mgr, watch_condition):
  449. """
  450. Validate watch condition parameters.
  451. Args:
  452. condition_mgr (ConditionMgr): Instance of ConditionMgr.
  453. watch_condition (dict): Watch condition.
  454. - id (str): Condition id. Should be in WATCHPOINT_CONDITION_MAPPING.
  455. - param (list): Condition value. Should be given for comparison condition. The value
  456. will be translated to np.float32.
  457. """
  458. condition_id = watch_condition.get('id')
  459. params = watch_condition.get('params')
  460. condition = condition_mgr.get_condition(condition_id)
  461. if condition_id in condition_mgr.get_no_param_condition():
  462. if params:
  463. log.error("No param is expected for %s condition", condition_id)
  464. raise DebuggerParamValueError("No param is expected.")
  465. return
  466. check_param_num = 0
  467. support_params = set()
  468. defined_support_params = set()
  469. range_param = {RANGE_START: None, RANGE_END: None}
  470. for param in params:
  471. if len(param) > 2:
  472. log.error("Invalid param keys for condition: %s", condition_id)
  473. raise DebuggerParamValueError("Invalid param keys.")
  474. condition_param_name = param.get("name")
  475. if condition_param_name not in condition.names:
  476. log.error("Invalid name of parameter for condition: %s, available values: %s",
  477. condition_id, condition.names)
  478. raise DebuggerParamValueError("Invalid name of parameter.")
  479. condition_param = condition.get_parameter_definition(condition_param_name)
  480. if condition_param.type.name in (ValueTypeEnum.FLOAT64.name, ValueTypeEnum.INT64.name) \
  481. and not isinstance(param.get("value"), (float, int)):
  482. log.error("Number param should be given for condition: %s", condition_id)
  483. raise DebuggerParamValueError("Number param should be given.")
  484. if condition_param.type.name == ValueTypeEnum.BOOL.name \
  485. and not isinstance(param.get("value"), bool):
  486. log.error("Bool param should be given for condition: %s", condition_id)
  487. raise DebuggerParamValueError("Bool param should be given.")
  488. if not condition_param.is_valid(param.get("value")):
  489. log.error("Param %s out of range for condition: %s", condition_param_name, condition_id)
  490. raise DebuggerParamValueError("Parameter out of range.")
  491. if condition_param.param_type == ParamTypeEnum.CHECK_PARAM.value:
  492. if condition_param.required_params:
  493. defined_support_params = set(condition_param.required_params)
  494. check_param_num += 1
  495. else:
  496. support_params.add(condition_param.name)
  497. if condition_param_name in range_param:
  498. range_param[condition_param_name] = param.get("value")
  499. if check_param_num > 1:
  500. log.error("Multiple check params for condition: %s", condition_id)
  501. raise DebuggerParamValueError("Multiple check params.")
  502. if support_params != defined_support_params:
  503. log.error("Invalid support params for condition: %s", condition_id)
  504. raise DebuggerParamValueError("Invalid support params.")
  505. if range_param.get(RANGE_START) is not None and \
  506. range_param.get(RANGE_END) is not None and range_param.get(RANGE_START) > \
  507. range_param.get(RANGE_END):
  508. log.error("Invalid support params for condition: %s", condition_id)
  509. raise DebuggerParamValueError("Invalid support params.")
  510. def set_default_param(condition_mgr, watch_condition):
  511. """
  512. Set default param.
  513. Args:
  514. condition_mgr (ConditionMgr): Instance of ConditionMgr.
  515. watch_condition (dict): The watch condition.
  516. "condition": {
  517. id: "tensor_too_large",
  518. "params": [
  519. {
  520. "name": "abs_mean_gt",
  521. "value": 1.1
  522. }
  523. ]
  524. }
  525. - id (str): Id of condition.
  526. - param (list[dict]): The list of param for this condition.
  527. Returns:
  528. dict, the new watch_condition.
  529. """
  530. condition_id = watch_condition.get('id')
  531. condition = condition_mgr.get_condition(condition_id)
  532. for param in condition.parameters:
  533. if not param.visible_on_ui and not param.support_disable:
  534. watch_condition["params"].append({
  535. "name": param.name,
  536. "value": param.default_value
  537. })
  538. watch_condition["abbr"] = condition.abbr
  539. return watch_condition
  540. def _get_error_list(error_code):
  541. """
  542. Get error list.
  543. Args:
  544. error_code (int): the code of errors.
  545. Returns:
  546. list, the error list.
  547. """
  548. all_error_list = ["nan", "inf", "no_prev_tensor"]
  549. error_list = []
  550. for i, error_str in enumerate(all_error_list):
  551. error = (error_code >> i) & 1
  552. if error == 1:
  553. error_list.append(error_str)
  554. return error_list