add param keys check add check_param num and support_param checktags/v1.1.0
| @@ -219,6 +219,7 @@ class Condition: | |||
| self._parameters = { | |||
| parameter.name: parameter for parameter in parameters | |||
| } | |||
| self.ordered_parameter_names = [parameter.name for parameter in parameters] | |||
| self._supported_target_type = supported_target_type | |||
| self.supported_platforms = supported_platforms | |||
| self.minimum_debugger_capability = minimum_debugger_capability | |||
| @@ -528,7 +528,7 @@ CONDITION_LIST = [ | |||
| optimize_phase=OptimizePhaseEnum.TENSOR_CHECK, | |||
| parameters=[ | |||
| ConditionParameter( | |||
| name="abs_update_ratio_mean_gt", | |||
| name="abs_mean_update_ratio_gt", | |||
| value_type=ValueTypeEnum.FLOAT64, | |||
| valid_test_func=check_abs_param_range, | |||
| default_value=1e-1 | |||
| @@ -552,7 +552,7 @@ CONDITION_LIST = [ | |||
| optimize_phase=OptimizePhaseEnum.TENSOR_CHECK, | |||
| parameters=[ | |||
| ConditionParameter( | |||
| name="abs_update_ratio_mean_lt", | |||
| name="abs_mean_update_ratio_lt", | |||
| value_type=ValueTypeEnum.FLOAT64, | |||
| valid_test_func=check_abs_param_range, | |||
| default_value=1e-4 | |||
| @@ -219,7 +219,7 @@ def _recommend_weight_change_too_small(condition_mgr, trainable_weight_nodes, wa | |||
| "condition": condition.id, | |||
| "params": [ | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("abs_update_ratio_mean_lt"), | |||
| parameter=condition.get_parameter_definition("abs_mean_update_ratio_lt"), | |||
| value=1.0e-4 # set default value to 1.0e-4 | |||
| ), | |||
| ] | |||
| @@ -270,8 +270,8 @@ def _recommend_weight_change_too_large(basic_info_nodes, condition_mgr, watch_po | |||
| watch_condition={ | |||
| "condition": condition.id, | |||
| "params": [_ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("abs_update_ratio_mean_gt"), | |||
| value=0.1 # set default value to 0.1 | |||
| parameter=condition.get_parameter_definition("abs_mean_update_ratio_gt"), | |||
| value=1 # set default value to 1 | |||
| )] | |||
| }, | |||
| watch_nodes=basic_info_nodes.copy(), | |||
| @@ -309,54 +309,7 @@ def _recommend_activation_range(basic_info_nodes, condition_mgr, watch_points, c | |||
| if not condition_mgr.has_condition(ConditionIdEnum.ACTIVATION_RANGE.value, condition_context): | |||
| return | |||
| condition = condition_mgr.get_condition(condition_id=ConditionIdEnum.ACTIVATION_RANGE.value) | |||
| params = [] | |||
| if activation_func == ActivationFuncEnum.TANH.value: | |||
| # The recommend params for Tanh: The percentage of value in range (tanh(-8.8), tanh(8.8)) is lower than 50.0% | |||
| params = [ | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_percentage_lt"), | |||
| value=50.0 | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_start_inclusive"), | |||
| value=math.tanh(-8.8) | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_end_inclusive"), | |||
| value=math.tanh(8.8) | |||
| )] | |||
| if activation_func == ActivationFuncEnum.SIGMOID.value: | |||
| # The recommend params for Sigmoid: | |||
| # The percentage of value in range (sigmoid(-16.2)), sigmoid(16.2)) is lower than 50.0% | |||
| params = [ | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_percentage_lt"), | |||
| value=50.0 | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_start_inclusive"), | |||
| value=_sigmoid(-16.2) | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_end_inclusive"), | |||
| value=_sigmoid(16.2) | |||
| )] | |||
| if activation_func == ActivationFuncEnum.RELU.value: | |||
| # The recommend params for ReLU: | |||
| # The percentage of value in range (float('-inf'), 0) is greater than 50.0% | |||
| params = [ | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_percentage_gt"), | |||
| value=50.0 | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_start_inclusive"), | |||
| value=float('-inf') | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_end_inclusive"), | |||
| value=0 | |||
| )] | |||
| params = _get_recommend_activation_params(condition, activation_func) | |||
| activation_range_watchpoint = _WatchPointData( | |||
| watch_condition={ | |||
| "condition": condition.id, | |||
| @@ -465,5 +418,58 @@ def _add_graph_name(nodes, graph_stream): | |||
| def _sigmoid(value): | |||
| """return sigmoid value""" | |||
| """calculate the sigmoid of value""" | |||
| return 1.0 / (1.0 + math.exp(value)) | |||
| def _get_recommend_activation_params(condition, activation_func): | |||
| """Get recommend params for tanh, sigmoid and relu activation function.""" | |||
| params = [] | |||
| if activation_func == ActivationFuncEnum.TANH.value: | |||
| # The recommend params for Tanh: The percentage of value in range (tanh(-8.8), tanh(8.8)) is lower than 0.1% | |||
| params = [ | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_percentage_lt"), | |||
| value=0.1 | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_start_inclusive"), | |||
| value=math.tanh(-8.8) | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_end_inclusive"), | |||
| value=math.tanh(8.8) | |||
| )] | |||
| if activation_func == ActivationFuncEnum.SIGMOID.value: | |||
| # The recommend params for Sigmoid: | |||
| # The percentage of value in range (sigmoid(-16.2)), sigmoid(16.2)) is lower than 0.1% | |||
| params = [ | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_percentage_lt"), | |||
| value=0.1 | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_start_inclusive"), | |||
| value=_sigmoid(-16.2) | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_end_inclusive"), | |||
| value=_sigmoid(16.2) | |||
| )] | |||
| if activation_func == ActivationFuncEnum.RELU.value: | |||
| # The recommend params for ReLU: | |||
| # The percentage of value in range (-1, 0) is greater than 99.9% | |||
| params = [ | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_percentage_gt"), | |||
| value=99.9 | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_start_inclusive"), | |||
| value=-1 | |||
| ), | |||
| _ConditionParameterValue( | |||
| parameter=condition.get_parameter_definition("range_end_inclusive"), | |||
| value=0 | |||
| )] | |||
| return params | |||
| @@ -19,6 +19,7 @@ import copy | |||
| from mindinsight.debugger.common.exceptions.exceptions import DebuggerParamValueError | |||
| from mindinsight.debugger.common.log import LOGGER as log | |||
| from mindinsight.debugger.common.utils import is_scope_type, is_cst_type | |||
| from mindinsight.debugger.conditionmgr.conditionmgr import ConditionMgr | |||
| from mindinsight.debugger.conditionmgr.common.utils import NodeBasicInfo | |||
| from mindinsight.debugger.conditionmgr.condition import ConditionIdEnum | |||
| from mindinsight.debugger.proto.debug_grpc_pb2 import SetCMD, WatchCondition | |||
| @@ -287,20 +288,29 @@ class Watchpoint: | |||
| def get_pending_cmd(self, watch_nodes): | |||
| """Return the watchpoint in proto format.""" | |||
| # construct SetCMD | |||
| condition_id = self._condition.get('id') | |||
| set_cmd = SetCMD() | |||
| set_cmd.id = self._id | |||
| set_cmd.delete = False | |||
| set_cmd.watch_condition.condition = WATCHPOINT_CONDITION_MAPPING.get( | |||
| self._condition.get('id')) | |||
| for param in self._condition.get('params'): | |||
| # at most one param is provided | |||
| param_proto = set_cmd.watch_condition.params.add() | |||
| param_proto.name = param.get('name') | |||
| param_proto.value = param.get('value') | |||
| param_proto.disabled = False | |||
| # Only one parameter of condition in current version. | |||
| set_cmd.watch_condition.value = param.get('value') | |||
| set_cmd.watch_condition.condition = WATCHPOINT_CONDITION_MAPPING.get(condition_id) | |||
| condition_mgr = ConditionMgr() | |||
| condition = condition_mgr.get_condition(condition_id) | |||
| param_dict = { | |||
| param.get('name'): param for param in self._condition.get('params') | |||
| } | |||
| for param_name in condition.ordered_parameter_names: | |||
| param = param_dict.get(param_name) | |||
| if param: | |||
| param_proto = set_cmd.watch_condition.params.add() | |||
| param_proto.name = param.get('name') | |||
| param_proto.value = param.get('value') | |||
| param_proto.disabled = False | |||
| # Only one parameter of condition in old mindspore version. | |||
| set_cmd.watch_condition.value = param.get('value') | |||
| else: | |||
| param_proto = set_cmd.watch_condition.params.add() | |||
| param_proto.name = param_name | |||
| param_proto.disabled = True | |||
| for watch_node in watch_nodes: | |||
| event_node = set_cmd.watch_nodes.add() | |||
| @@ -14,6 +14,7 @@ | |||
| # ============================================================================ | |||
| """Define the watchpoint stream handler.""" | |||
| from mindinsight.debugger.conditionmgr.condition import ValueTypeEnum | |||
| from mindinsight.debugger.conditionmgr.condition import ParamTypeEnum | |||
| from mindinsight.debugger.common.exceptions.exceptions import DebuggerParamValueError, \ | |||
| DebuggerParamTypeError | |||
| from mindinsight.debugger.common.log import LOGGER as log | |||
| @@ -540,7 +541,14 @@ def validate_watch_condition_params(condition_mgr, watch_condition): | |||
| raise DebuggerParamValueError("No param is expected.") | |||
| return | |||
| check_param_num = 0 | |||
| support_params = set() | |||
| defined_support_params = set() | |||
| for param in params: | |||
| if len(param) > 2: | |||
| log.error("Invalid param keys for condition: %s", condition_id) | |||
| raise DebuggerParamValueError("Invalid param keys.") | |||
| condition_param_name = param.get("name") | |||
| if condition_param_name not in condition.names: | |||
| log.error("Invalid name of parameter for condition: %s, available values: %s", | |||
| @@ -562,6 +570,21 @@ def validate_watch_condition_params(condition_mgr, watch_condition): | |||
| log.error("Param %s out of range for condition: %s", condition_param_name, condition_id) | |||
| raise DebuggerParamValueError("Parameter out of range.") | |||
| if condition_param.param_type == ParamTypeEnum.CHECK_PARAM.value: | |||
| if condition_param.required_params: | |||
| defined_support_params = set(condition_param.required_params) | |||
| check_param_num += 1 | |||
| else: | |||
| support_params.add(condition_param.name) | |||
| if check_param_num > 1: | |||
| log.error("Multiple check params for condition: %s", condition_id) | |||
| raise DebuggerParamValueError("Multiple check params.") | |||
| if support_params != defined_support_params: | |||
| log.error("Invalid support params for condition: %s", condition_id) | |||
| raise DebuggerParamValueError("Invalid support params.") | |||
| def set_default_param(condition_mgr, watch_condition): | |||
| """ | |||
| @@ -1 +1 @@ | |||
| {"watch_points": [{"id": 1, "watch_condition": {"id": "max_gt", "params": [{"name": "param", "value": 1.0, "disable": false}], "abbr": "MAX>"}}, {"id": 2, "watch_condition": {"id": "max_lt", "params": [{"name": "param", "value": -1.0, "disable": false}], "abbr": "MAX<"}}, {"id": 3, "watch_condition": {"id": "min_gt", "params": [{"name": "param", "value": 1e+32, "disable": false}], "abbr": "MIN>"}}, {"id": 5, "watch_condition": {"id": "max_min_gt", "params": [{"name": "param", "value": 0, "disable": false}], "abbr": "MAX-MIN>"}}, {"id": 6, "watch_condition": {"id": "max_min_lt", "params": [{"name": "param", "value": 0, "disable": false}], "abbr": "MAX-Min<"}}, {"id": 7, "watch_condition": {"id": "mean_gt", "params": [{"name": "param", "value": 0, "disable": false}], "abbr": "MEAN>"}}, {"id": 8, "watch_condition": {"id": "mean_lt", "params": [{"name": "param", "value": 0, "disable": false}], "abbr": "MEAN<"}}, {"id": 9, "watch_condition": {"id": "inf", "params": [], "abbr": "INF"}}, {"id": 10, "watch_condition": {"id": "overflow", "params": [], "abbr": "OVERFLOW"}}]} | |||
| {"watch_points": [{"id": 1, "watch_condition": {"id": "max_gt", "params": [{"name": "param", "value": 1.0}], "abbr": "MAX>"}}, {"id": 2, "watch_condition": {"id": "max_lt", "params": [{"name": "param", "value": -1.0}], "abbr": "MAX<"}}, {"id": 3, "watch_condition": {"id": "min_gt", "params": [{"name": "param", "value": 1e+32}], "abbr": "MIN>"}}, {"id": 5, "watch_condition": {"id": "max_min_gt", "params": [{"name": "param", "value": 0}], "abbr": "MAX-MIN>"}}, {"id": 6, "watch_condition": {"id": "max_min_lt", "params": [{"name": "param", "value": 0}], "abbr": "MAX-Min<"}}, {"id": 7, "watch_condition": {"id": "mean_gt", "params": [{"name": "param", "value": 0}], "abbr": "MEAN>"}}, {"id": 8, "watch_condition": {"id": "mean_lt", "params": [{"name": "param", "value": 0}], "abbr": "MEAN<"}}, {"id": 9, "watch_condition": {"id": "inf", "params": [], "abbr": "INF"}}, {"id": 10, "watch_condition": {"id": "overflow", "params": [], "abbr": "OVERFLOW"}}]} | |||
| @@ -1 +1 @@ | |||
| {"metadata": {"state": "waiting", "step": 2, "device_name": "0", "node_name": "", "backend": "GPU", "enable_recheck": false, "graph_name": ""}, "graph": {"graph_names": ["graph_0", "graph_1"], "nodes": [{"name": "graph_0", "type": "name_scope", "attr": {}, "input": {}, "output": {}, "output_i": 0, "proxy_input": {}, "proxy_output": {}, "subnode_count": 2, "independent_layout": false}, {"name": "graph_1", "type": "name_scope", "attr": {}, "input": {}, "output": {}, "output_i": 0, "proxy_input": {}, "proxy_output": {}, "subnode_count": 2, "independent_layout": false}]}, "watch_points": [{"id": 1, "watch_condition": {"id": "weight_initialization", "params": [{"name": "zero_percentage_ge", "disable": false, "value": 100}], "abbr": "WI"}}, {"id": 2, "watch_condition": {"id": "weight_change_too_large", "params": [{"name": "abs_update_ratio_mean_gt", "disable": false, "value": 0.1}], "abbr": "WCL"}}, {"id": 3, "watch_condition": {"id": "gradient_vanishing", "params": [{"name": "abs_mean_lt", "disable": false, "value": 1e-09}], "abbr": "GV"}}, {"id": 4, "watch_condition": {"id": "tensor_overflow", "params": [], "abbr": "TO"}}, {"id": 5, "watch_condition": {"id": "tensor_all_zero", "params": [{"name": "zero_percentage_ge", "disable": false, "value": 100}], "abbr": "TZ"}}]} | |||
| {"metadata": {"state": "waiting", "step": 2, "device_name": "0", "node_name": "", "backend": "GPU", "enable_recheck": false, "graph_name": ""}, "graph": {"graph_names": ["graph_0", "graph_1"], "nodes": [{"name": "graph_0", "type": "name_scope", "attr": {}, "input": {}, "output": {}, "output_i": 0, "proxy_input": {}, "proxy_output": {}, "subnode_count": 2, "independent_layout": false}, {"name": "graph_1", "type": "name_scope", "attr": {}, "input": {}, "output": {}, "output_i": 0, "proxy_input": {}, "proxy_output": {}, "subnode_count": 2, "independent_layout": false}]}, "watch_points": [{"id": 1, "watch_condition": {"id": "weight_initialization", "params": [{"name": "zero_percentage_ge", "disable": false, "value": 100}], "abbr": "WI"}}, {"id": 2, "watch_condition": {"id": "weight_change_too_large", "params": [{"name": "abs_mean_update_ratio_gt", "disable": false, "value": 0.1}], "abbr": "WCL"}}, {"id": 3, "watch_condition": {"id": "gradient_vanishing", "params": [{"name": "abs_mean_lt", "disable": false, "value": 1e-09}], "abbr": "GV"}}, {"id": 4, "watch_condition": {"id": "tensor_overflow", "params": [], "abbr": "TO"}}, {"id": 5, "watch_condition": {"id": "tensor_all_zero", "params": [{"name": "zero_percentage_ge", "disable": false, "value": 100}], "abbr": "TZ"}}]} | |||
| @@ -130,14 +130,14 @@ class TestAscendDebugger: | |||
| with self._debugger_client.get_thread_instance(): | |||
| check_waiting_state(app_client) | |||
| conditions = [ | |||
| {'id': 'max_gt', 'params': [{'name': 'param', 'value': 1.0, 'disable': False}]}, | |||
| {'id': 'max_lt', 'params': [{'name': 'param', 'value': -1.0, 'disable': False}]}, | |||
| {'id': 'min_gt', 'params': [{'name': 'param', 'value': 1e+32, 'disable': False}]}, | |||
| {'id': 'min_lt', 'params': [{'name': 'param', 'value': -1e+32, 'disable': False}]}, | |||
| {'id': 'max_min_gt', 'params': [{'name': 'param', 'value': 0, 'disable': False}]}, | |||
| {'id': 'max_min_lt', 'params': [{'name': 'param', 'value': 0, 'disable': False}]}, | |||
| {'id': 'mean_gt', 'params': [{'name': 'param', 'value': 0, 'disable': False}]}, | |||
| {'id': 'mean_lt', 'params': [{'name': 'param', 'value': 0, 'disable': False}]}, | |||
| {'id': 'max_gt', 'params': [{'name': 'param', 'value': 1.0}]}, | |||
| {'id': 'max_lt', 'params': [{'name': 'param', 'value': -1.0}]}, | |||
| {'id': 'min_gt', 'params': [{'name': 'param', 'value': 1e+32}]}, | |||
| {'id': 'min_lt', 'params': [{'name': 'param', 'value': -1e+32}]}, | |||
| {'id': 'max_min_gt', 'params': [{'name': 'param', 'value': 0}]}, | |||
| {'id': 'max_min_lt', 'params': [{'name': 'param', 'value': 0}]}, | |||
| {'id': 'mean_gt', 'params': [{'name': 'param', 'value': 0}]}, | |||
| {'id': 'mean_lt', 'params': [{'name': 'param', 'value': 0}]}, | |||
| {'id': 'inf', 'params': []}, | |||
| {'id': 'overflow', 'params': []}, | |||
| ] | |||
| @@ -1 +1 @@ | |||
| [{"id": 1, "watch_condition": {"id": "inf", "params": [], "abbr": "INF"}}, {"id": 2, "watch_condition": {"id": "inf", "params": [], "abbr": "INF"}}, {"id": 3, "watch_condition": {"id": "max_gt", "params": [{"name": "param", "value": 1, "disable": false}], "abbr": "MAX>"}}] | |||
| [{"id": 1, "watch_condition": {"id": "inf", "params": [], "abbr": "INF"}}, {"id": 2, "watch_condition": {"id": "inf", "params": [], "abbr": "INF"}}, {"id": 3, "watch_condition": {"id": "max_gt", "params": [{"name": "param", "value": 1}], "abbr": "MAX>"}}] | |||
| @@ -63,7 +63,7 @@ class TestWatchpointHandler: | |||
| watchpoints = [ | |||
| ({'id': 'inf', 'params': []}, None, None, 1), | |||
| ({'id': 'inf', 'params': []}, ["Default"], None, 2), | |||
| ({'id': 'max_gt', 'params': [{'name': 'param', 'value': 1, 'disable': False}]}, | |||
| ({'id': 'max_gt', 'params': [{'name': 'param', 'value': 1}]}, | |||
| ["Gradients/Default/network-WithLossCell/_backbone-LeNet5/relu-ReLU/gradReLU/ReluGradV2-op92"], | |||
| None, 3) | |||
| ] | |||
| @@ -233,13 +233,13 @@ def test_validate_watch_condition_type_error(): | |||
| def test_validate_watch_condition_params_except(): | |||
| """Test validate_watch_condition_params.""" | |||
| watch_condition = {'id': 'inf', 'params': [{'name': 'param', 'value': 0, 'disable': False}]} | |||
| watch_condition = {'id': 'inf', 'params': [{'name': 'param', 'value': 0}]} | |||
| conditionmgr = ConditionMgr() | |||
| with pytest.raises(DebuggerParamValueError) as err: | |||
| validate_watch_condition_params(conditionmgr, watch_condition) | |||
| assert err.value.error_code == '5054B081' | |||
| watch_condition = {'id': 'max_gt', 'params': [{'name': 'param', 'value': '0', 'disable': False}]} | |||
| watch_condition = {'id': 'max_gt', 'params': [{'name': 'param', 'value': '0'}]} | |||
| with pytest.raises(DebuggerParamValueError) as err: | |||
| validate_watch_condition_params(conditionmgr, watch_condition) | |||
| assert err.value.error_code == '5054B081' | |||