mindstudio-probe 1.1.0__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.1.1.dist-info}/METADATA +5 -5
- mindstudio_probe-1.1.1.dist-info/RECORD +341 -0
- {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.1.1.dist-info}/WHEEL +1 -1
- {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.1.1.dist-info}/entry_points.txt +0 -1
- msprobe/README.md +39 -3
- msprobe/config.json +1 -3
- msprobe/core/advisor/advisor.py +8 -3
- msprobe/core/common/const.py +113 -13
- msprobe/core/common/exceptions.py +25 -3
- msprobe/core/common/file_utils.py +150 -26
- msprobe/core/common/inplace_op_checker.py +15 -0
- msprobe/core/common/log.py +27 -9
- msprobe/core/common/utils.py +182 -69
- msprobe/core/common_config.py +44 -15
- msprobe/core/compare/acc_compare.py +207 -142
- msprobe/core/compare/check.py +2 -5
- msprobe/core/compare/compare_cli.py +21 -4
- msprobe/core/compare/highlight.py +124 -55
- msprobe/core/compare/layer_mapping/__init__.py +19 -0
- msprobe/core/compare/layer_mapping/data_scope_parser.py +235 -0
- msprobe/core/compare/layer_mapping/layer_mapping.py +242 -0
- msprobe/core/compare/layer_mapping/postprocess_pass.py +94 -0
- msprobe/core/compare/npy_compare.py +52 -23
- msprobe/core/compare/utils.py +272 -247
- msprobe/core/data_dump/data_collector.py +13 -11
- msprobe/core/data_dump/data_processor/base.py +46 -16
- msprobe/core/data_dump/data_processor/mindspore_processor.py +4 -4
- msprobe/core/data_dump/data_processor/pytorch_processor.py +156 -59
- msprobe/core/data_dump/scope.py +113 -34
- msprobe/core/grad_probe/constant.py +27 -13
- msprobe/core/grad_probe/grad_compare.py +18 -1
- msprobe/core/grad_probe/utils.py +30 -2
- msprobe/core/overflow_check/abnormal_scene.py +185 -0
- msprobe/core/overflow_check/api_info.py +55 -0
- msprobe/core/overflow_check/checker.py +138 -0
- msprobe/core/overflow_check/filter.py +157 -0
- msprobe/core/overflow_check/ignore_rules.yaml +55 -0
- msprobe/core/overflow_check/level.py +22 -0
- msprobe/core/overflow_check/utils.py +28 -0
- msprobe/docs/01.installation.md +10 -0
- msprobe/docs/02.config_introduction.md +49 -22
- msprobe/docs/03.config_examples.md +2 -9
- msprobe/docs/04.kernel_dump_PyTorch.md +73 -0
- msprobe/docs/05.data_dump_PyTorch.md +3 -1
- msprobe/docs/06.data_dump_MindSpore.md +157 -90
- msprobe/docs/07.accuracy_checker_PyTorch.md +12 -12
- msprobe/docs/08.accuracy_checker_online_PyTorch.md +1 -6
- msprobe/docs/09.accuracy_checker_MindSpore.md +44 -8
- msprobe/docs/10.accuracy_compare_PyTorch.md +19 -13
- msprobe/docs/11.accuracy_compare_MindSpore.md +104 -13
- msprobe/docs/12.overflow_check_PyTorch.md +1 -1
- msprobe/docs/13.overflow_check_MindSpore.md +6 -6
- msprobe/docs/15.free_benchmarking_PyTorch.md +4 -5
- msprobe/docs/16.free_benchmarking_MindSpore.md +56 -37
- msprobe/docs/17.grad_probe.md +5 -6
- msprobe/docs/19.monitor.md +468 -0
- msprobe/docs/20.monitor_performance_baseline.md +52 -0
- msprobe/docs/21.visualization_PyTorch.md +386 -0
- msprobe/docs/22.visualization_MindSpore.md +384 -0
- msprobe/docs/23.tool_function_introduction.md +28 -0
- msprobe/docs/FAQ.md +3 -0
- msprobe/docs/data_dump_Mindspore/dynamic_graph_quick_start_example.md +211 -0
- msprobe/docs/img/compare_result.png +0 -0
- msprobe/docs/img/monitor/cpu_info.png +0 -0
- msprobe/mindspore/__init__.py +15 -0
- msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +113 -145
- msprobe/mindspore/api_accuracy_checker/api_info.py +21 -6
- msprobe/mindspore/api_accuracy_checker/api_runner.py +43 -18
- msprobe/mindspore/api_accuracy_checker/base_compare_algorithm.py +21 -7
- msprobe/mindspore/api_accuracy_checker/checker_support_api.yaml +77 -0
- msprobe/mindspore/api_accuracy_checker/cmd_parser.py +63 -1
- msprobe/mindspore/api_accuracy_checker/compute_element.py +59 -24
- msprobe/mindspore/api_accuracy_checker/data_manager.py +264 -0
- msprobe/mindspore/api_accuracy_checker/main.py +27 -3
- msprobe/mindspore/api_accuracy_checker/multi_api_accuracy_checker.py +206 -0
- msprobe/mindspore/api_accuracy_checker/multi_data_manager.py +58 -0
- msprobe/mindspore/api_accuracy_checker/type_mapping.py +22 -5
- msprobe/mindspore/api_accuracy_checker/utils.py +34 -17
- msprobe/mindspore/cell_processor.py +33 -12
- msprobe/mindspore/common/const.py +33 -13
- msprobe/mindspore/common/log.py +5 -9
- msprobe/mindspore/common/utils.py +43 -4
- msprobe/mindspore/compare/distributed_compare.py +22 -22
- msprobe/mindspore/compare/ms_compare.py +271 -248
- msprobe/mindspore/compare/ms_graph_compare.py +81 -47
- msprobe/mindspore/debugger/debugger_config.py +4 -1
- msprobe/mindspore/debugger/precision_debugger.py +7 -1
- msprobe/mindspore/dump/dump_tool_factory.py +3 -1
- msprobe/mindspore/dump/hook_cell/api_registry.py +12 -2
- msprobe/mindspore/dump/hook_cell/primitive_hooks.py +13 -16
- msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +25 -0
- msprobe/mindspore/dump/jit_dump.py +17 -5
- msprobe/mindspore/dump/kernel_graph_dump.py +2 -4
- msprobe/mindspore/dump/kernel_kbyk_dump.py +2 -4
- msprobe/mindspore/dym_loader/hook_dynamic_loader.cc +140 -0
- msprobe/mindspore/dym_loader/hook_dynamic_loader.h +53 -0
- msprobe/mindspore/free_benchmark/api_pynative_self_check.py +145 -39
- msprobe/mindspore/free_benchmark/common/handler_params.py +1 -2
- msprobe/mindspore/free_benchmark/common/utils.py +19 -4
- msprobe/mindspore/free_benchmark/data/support_wrap_ops.yaml +0 -204
- msprobe/mindspore/free_benchmark/handler/base_handler.py +3 -3
- msprobe/mindspore/free_benchmark/handler/check_handler.py +4 -5
- msprobe/mindspore/free_benchmark/handler/fix_handler.py +4 -4
- msprobe/mindspore/free_benchmark/handler/handler_factory.py +4 -4
- msprobe/mindspore/free_benchmark/perturbation/add_noise.py +2 -2
- msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +15 -6
- msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +4 -4
- msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +2 -2
- msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +13 -6
- msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +2 -2
- msprobe/mindspore/free_benchmark/self_check_tool_factory.py +2 -2
- msprobe/mindspore/grad_probe/global_context.py +28 -8
- msprobe/mindspore/grad_probe/grad_analyzer.py +27 -13
- msprobe/mindspore/grad_probe/grad_monitor.py +16 -1
- msprobe/mindspore/grad_probe/grad_stat_csv.py +33 -5
- msprobe/mindspore/grad_probe/hook.py +24 -10
- msprobe/mindspore/grad_probe/utils.py +18 -5
- msprobe/mindspore/ms_config.py +22 -15
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +2 -4
- msprobe/mindspore/runtime.py +15 -0
- msprobe/mindspore/service.py +36 -30
- msprobe/mindspore/task_handler_factory.py +15 -0
- msprobe/msprobe.py +24 -7
- msprobe/pytorch/__init__.py +3 -2
- msprobe/pytorch/api_accuracy_checker/common/config.py +62 -0
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +3 -4
- msprobe/pytorch/api_accuracy_checker/generate_op_script/config_op.json +9 -0
- msprobe/pytorch/api_accuracy_checker/generate_op_script/op_generator.py +454 -0
- msprobe/pytorch/api_accuracy_checker/generate_op_script/operator_replication.template +365 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +6 -1
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +19 -14
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +13 -9
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +77 -53
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +15 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +9 -24
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +4 -12
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/dump_dispatch.py +9 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +3 -11
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/utils.py +2 -2
- msprobe/pytorch/bench_functions/confusion_transpose.py +5 -1
- msprobe/pytorch/bench_functions/matmul_backward.py +12 -0
- msprobe/pytorch/bench_functions/npu_fusion_attention.py +100 -6
- msprobe/pytorch/bench_functions/rotary_mul.py +4 -0
- msprobe/pytorch/bench_functions/swiglu.py +10 -2
- msprobe/pytorch/common/parse_json.py +6 -6
- msprobe/pytorch/common/utils.py +56 -5
- msprobe/pytorch/compare/distributed_compare.py +8 -9
- msprobe/pytorch/compare/pt_compare.py +8 -6
- msprobe/pytorch/debugger/debugger_config.py +19 -15
- msprobe/pytorch/dump/kernel_dump/kernel_config.py +33 -0
- msprobe/pytorch/free_benchmark/common/constant.py +15 -0
- msprobe/pytorch/free_benchmark/common/counter.py +15 -0
- msprobe/pytorch/free_benchmark/common/enums.py +15 -0
- msprobe/pytorch/free_benchmark/common/params.py +8 -1
- msprobe/pytorch/free_benchmark/common/utils.py +26 -4
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +20 -3
- msprobe/pytorch/free_benchmark/compare/single_benchmark.py +2 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +3 -1
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +6 -4
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +2 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +4 -0
- msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +10 -0
- msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +6 -5
- msprobe/pytorch/grad_probe/grad_monitor.py +23 -6
- msprobe/pytorch/grad_probe/grad_stat_csv.py +40 -10
- msprobe/pytorch/hook_module/support_wrap_ops.yaml +1 -0
- msprobe/pytorch/hook_module/wrap_functional.py +14 -12
- msprobe/pytorch/module_processer.py +2 -5
- msprobe/pytorch/monitor/anomaly_analyse.py +201 -0
- msprobe/pytorch/monitor/anomaly_detect.py +340 -0
- msprobe/pytorch/monitor/distributed/__init__.py +0 -0
- msprobe/pytorch/monitor/distributed/distributed_ops.yaml +19 -0
- msprobe/pytorch/monitor/distributed/stack_blacklist.yaml +5 -0
- msprobe/pytorch/monitor/distributed/wrap_distributed.py +272 -0
- msprobe/pytorch/monitor/features.py +108 -0
- msprobe/pytorch/monitor/module_hook.py +870 -0
- msprobe/pytorch/monitor/module_metric.py +193 -0
- msprobe/pytorch/monitor/module_spec_verifier.py +93 -0
- msprobe/pytorch/monitor/optimizer_collect.py +295 -0
- msprobe/pytorch/monitor/unittest/__init__.py +0 -0
- msprobe/pytorch/monitor/unittest/test_monitor.py +145 -0
- msprobe/pytorch/monitor/utils.py +250 -0
- msprobe/pytorch/monitor/visualizer.py +59 -0
- msprobe/pytorch/online_dispatch/__init__.py +2 -3
- msprobe/pytorch/online_dispatch/compare.py +29 -38
- msprobe/pytorch/online_dispatch/dispatch.py +50 -25
- msprobe/pytorch/online_dispatch/dump_compare.py +21 -9
- msprobe/pytorch/online_dispatch/single_compare.py +53 -32
- msprobe/pytorch/online_dispatch/torch_ops_config.yaml +1 -1
- msprobe/pytorch/online_dispatch/utils.py +49 -21
- msprobe/pytorch/parse_tool/lib/compare.py +12 -18
- msprobe/pytorch/parse_tool/lib/config.py +1 -1
- msprobe/pytorch/parse_tool/lib/parse_tool.py +1 -2
- msprobe/pytorch/parse_tool/lib/utils.py +16 -35
- msprobe/pytorch/parse_tool/lib/visualization.py +2 -0
- msprobe/pytorch/pt_config.py +31 -8
- msprobe/pytorch/service.py +15 -5
- msprobe/visualization/__init__.py +14 -0
- msprobe/visualization/builder/__init__.py +14 -0
- msprobe/visualization/builder/graph_builder.py +165 -0
- msprobe/visualization/builder/msprobe_adapter.py +205 -0
- msprobe/visualization/compare/__init__.py +14 -0
- msprobe/visualization/compare/graph_comparator.py +130 -0
- msprobe/visualization/compare/mode_adapter.py +211 -0
- msprobe/visualization/graph/__init__.py +14 -0
- msprobe/visualization/graph/base_node.py +124 -0
- msprobe/visualization/graph/graph.py +200 -0
- msprobe/visualization/graph/node_colors.py +95 -0
- msprobe/visualization/graph/node_op.py +39 -0
- msprobe/visualization/graph_service.py +214 -0
- msprobe/visualization/utils.py +232 -0
- mindstudio_probe-1.1.0.dist-info/RECORD +0 -287
- msprobe/docs/04.acl_config_examples.md +0 -78
- msprobe/mindspore/compare/layer_mapping.py +0 -146
- msprobe/mindspore/compare/modify_mapping.py +0 -107
- msprobe/mindspore/free_benchmark/decorator/dec_forward.py +0 -57
- msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +0 -122
- {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.1.1.dist-info}/LICENSE +0 -0
- {mindstudio_probe-1.1.0.dist-info → mindstudio_probe-1.1.1.dist-info}/top_level.txt +0 -0
- /msprobe/{mindspore/free_benchmark/decorator → pytorch/monitor}/__init__.py +0 -0
|
@@ -102,8 +102,13 @@ class GradSaver:
|
|
|
102
102
|
def check_grad_input(self, origin_grad, new_grad_index):
|
|
103
103
|
if self.perturbed_grad_input is None:
|
|
104
104
|
raise FreeBenchmarkException(
|
|
105
|
-
FreeBenchmarkException.
|
|
106
|
-
f"grad not exists
|
|
105
|
+
FreeBenchmarkException.InvalidPerturbedOutput,
|
|
106
|
+
f"perturbed grad not exists for {self.api_name}.",
|
|
107
|
+
)
|
|
108
|
+
if len(self.perturbed_grad_input) <= new_grad_index:
|
|
109
|
+
raise FreeBenchmarkException(
|
|
110
|
+
FreeBenchmarkException.InvalidPerturbedOutput,
|
|
111
|
+
f"perturbed grad index {new_grad_index} is out of bounds for {self.api_name}.",
|
|
107
112
|
)
|
|
108
113
|
with torch.no_grad():
|
|
109
114
|
perturbed_grad = self.perturbed_grad_input[new_grad_index].to(
|
|
@@ -111,7 +116,7 @@ class GradSaver:
|
|
|
111
116
|
)
|
|
112
117
|
if origin_grad.shape != perturbed_grad.shape:
|
|
113
118
|
raise FreeBenchmarkException(
|
|
114
|
-
FreeBenchmarkException.
|
|
119
|
+
FreeBenchmarkException.InvalidPerturbedOutput,
|
|
115
120
|
f"grad shapes are inconsistent. api:{self.handler_params.api_name}."
|
|
116
121
|
f"origin:{origin_grad.shape}, perturbation: {perturbed_grad.shape}",
|
|
117
122
|
)
|
|
@@ -164,6 +169,18 @@ class GradSaver:
|
|
|
164
169
|
index_ = 0
|
|
165
170
|
for object_ in inner_args:
|
|
166
171
|
if object_ is CommonField.HOLD_PLACE:
|
|
172
|
+
if index_ >= len(inputs):
|
|
173
|
+
err_msg = (
|
|
174
|
+
f"[msprobe] Free benchmark: When getting input from vjp, "
|
|
175
|
+
f" the input index ({index_}) is out of bounds ({len(inputs)})."
|
|
176
|
+
)
|
|
177
|
+
logger.error_log_with_exp(
|
|
178
|
+
err_msg,
|
|
179
|
+
FreeBenchmarkException(
|
|
180
|
+
FreeBenchmarkException.InvalidGrad,
|
|
181
|
+
error_info=err_msg,
|
|
182
|
+
),
|
|
183
|
+
)
|
|
167
184
|
_real_input.append(inputs[index_])
|
|
168
185
|
index_ += 1
|
|
169
186
|
else:
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import math
|
|
17
17
|
|
|
18
18
|
import torch
|
|
19
|
+
from msprobe.core.common.utils import recursion_depth_decorator
|
|
19
20
|
from msprobe.pytorch.free_benchmark import logger
|
|
20
21
|
from msprobe.pytorch.free_benchmark.common.constant import ThresholdConfig
|
|
21
22
|
from msprobe.pytorch.free_benchmark.common.utils import TorchC
|
|
@@ -67,6 +68,7 @@ class SingleCompare:
|
|
|
67
68
|
return False
|
|
68
69
|
return True
|
|
69
70
|
|
|
71
|
+
@recursion_depth_decorator("FreeBenchmark: SingleCompare.compare_seq")
|
|
70
72
|
def compare_seq(self, actual, golden):
|
|
71
73
|
if isinstance(golden, torch.Tensor):
|
|
72
74
|
return self.compare_tensor_seq(actual, golden)
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
16
|
import torch
|
|
17
|
+
from msprobe.core.common.utils import recursion_depth_decorator
|
|
17
18
|
from msprobe.pytorch.free_benchmark import logger
|
|
18
19
|
from msprobe.pytorch.free_benchmark.common.constant import ThresholdConfig
|
|
19
20
|
from msprobe.pytorch.free_benchmark.common.enums import PerturbationMode
|
|
@@ -26,6 +27,7 @@ from msprobe.pytorch.free_benchmark.perturbed_layers.npu.npu_base_layser import
|
|
|
26
27
|
|
|
27
28
|
class AddNoiseLayer(NpuBaseLayer):
|
|
28
29
|
|
|
30
|
+
@recursion_depth_decorator("FreeBenchmark: AddNoiseLayer.add_noise")
|
|
29
31
|
def add_noise(self, tensor_obj):
|
|
30
32
|
if isinstance(tensor_obj, torch.Tensor):
|
|
31
33
|
self.perturbed_value = ThresholdConfig.PERTURBATION_VALUE_DICT.get(
|
|
@@ -99,7 +101,7 @@ class AddNoiseLayer(NpuBaseLayer):
|
|
|
99
101
|
if max_val < abs_tol:
|
|
100
102
|
logger.warning_on_rank_0(
|
|
101
103
|
f"[msprobe] Free Benchmark: For {self.api_name}, "
|
|
102
|
-
f"Maximun value is less than the
|
|
104
|
+
f"Maximun value is less than the minimun threshold. Cancel add noise."
|
|
103
105
|
)
|
|
104
106
|
return False
|
|
105
107
|
return True
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
16
|
import torch
|
|
17
|
+
from msprobe.core.common.utils import recursion_depth_decorator
|
|
17
18
|
from msprobe.pytorch.free_benchmark import logger
|
|
18
19
|
from msprobe.pytorch.free_benchmark.common.constant import ThresholdConfig
|
|
19
20
|
from msprobe.pytorch.free_benchmark.common.enums import PerturbationMode
|
|
@@ -31,6 +32,7 @@ class BitNoiseLayer(NpuBaseLayer):
|
|
|
31
32
|
self.bit_tail: int = 1
|
|
32
33
|
self.bit_type = None
|
|
33
34
|
|
|
35
|
+
@recursion_depth_decorator("FreeBenchmark: BitNoiseLayer.add_bit_noise")
|
|
34
36
|
def add_bit_noise(self, tensor_obj):
|
|
35
37
|
"""
|
|
36
38
|
对输入添加噪声
|
|
@@ -79,14 +81,14 @@ class BitNoiseLayer(NpuBaseLayer):
|
|
|
79
81
|
判断是否需要添加扰动, bit翻转
|
|
80
82
|
"""
|
|
81
83
|
if not self.bit_type:
|
|
82
|
-
logger.
|
|
84
|
+
logger.warning_on_rank_0(
|
|
83
85
|
f"[msprobe] Free Benchmark: For {self.api_name}, "
|
|
84
86
|
f"dtype unsupported. Cancel perturbation."
|
|
85
87
|
)
|
|
86
88
|
return False
|
|
87
89
|
if tensor_obj.numel() == 0:
|
|
88
90
|
logger.warning_on_rank_0(
|
|
89
|
-
f"[msprobe] Free benchmark: For {self.api_name}, tensor shape must > 0"
|
|
91
|
+
f"[msprobe] Free benchmark: For {self.api_name}, tensor shape must > 0."
|
|
90
92
|
f" Cancel adding noise."
|
|
91
93
|
)
|
|
92
94
|
return False
|
|
@@ -102,9 +104,9 @@ class BitNoiseLayer(NpuBaseLayer):
|
|
|
102
104
|
)
|
|
103
105
|
max_val = TorchC.max(TorchC.abs(tensor_obj.to(torch.float32))).item()
|
|
104
106
|
if max_val < abs_tol:
|
|
105
|
-
logger.
|
|
107
|
+
logger.warning_on_rank_0(
|
|
106
108
|
f"[msprobe] Free Benchmark: For {self.api_name}, "
|
|
107
|
-
f"Maximun value is less than the
|
|
109
|
+
f"Maximun value is less than the minimun threshold. Cancel add noise."
|
|
108
110
|
)
|
|
109
111
|
return False
|
|
110
112
|
return True
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
16
|
import torch
|
|
17
|
+
from msprobe.core.common.utils import recursion_depth_decorator
|
|
17
18
|
from msprobe.pytorch.free_benchmark import logger
|
|
18
19
|
from msprobe.pytorch.free_benchmark.common.enums import PerturbationMode
|
|
19
20
|
from msprobe.pytorch.free_benchmark.common.params import DataParams
|
|
@@ -29,6 +30,7 @@ class ChangeValueLayer(NpuBaseLayer):
|
|
|
29
30
|
self.head: int = 0
|
|
30
31
|
self.tail: int = -1
|
|
31
32
|
|
|
33
|
+
@recursion_depth_decorator("FreeBenchmark: ChangeValueLayer.change_value")
|
|
32
34
|
def change_value(self, tensor_obj):
|
|
33
35
|
"""
|
|
34
36
|
交换张量首尾
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import torch
|
|
17
17
|
from msprobe.core.common.const import Const
|
|
18
|
+
from msprobe.core.common.utils import recursion_depth_decorator
|
|
18
19
|
from msprobe.pytorch.free_benchmark import logger
|
|
19
20
|
from msprobe.pytorch.free_benchmark.common.constant import CommonField
|
|
20
21
|
from msprobe.pytorch.free_benchmark.common.enums import PerturbationMode
|
|
@@ -26,6 +27,9 @@ from msprobe.pytorch.free_benchmark.perturbed_layers.npu.npu_base_layser import
|
|
|
26
27
|
|
|
27
28
|
class ImprovePrecisionLayer(NpuBaseLayer):
|
|
28
29
|
|
|
30
|
+
@recursion_depth_decorator(
|
|
31
|
+
"FreeBenchmark: ImprovePrecisionLayer.improve_tensor_precision"
|
|
32
|
+
)
|
|
29
33
|
def improve_tensor_precision(self, tensor_obj):
|
|
30
34
|
if (
|
|
31
35
|
isinstance(tensor_obj, torch.Tensor)
|
|
@@ -20,6 +20,7 @@ from typing import Any, Optional, Tuple
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
import torch
|
|
22
22
|
from msprobe.core.common.const import Const
|
|
23
|
+
from msprobe.core.common.exceptions import FreeBenchmarkException
|
|
23
24
|
from msprobe.pytorch.free_benchmark import logger
|
|
24
25
|
from msprobe.pytorch.free_benchmark.common.constant import ThresholdConfig
|
|
25
26
|
from msprobe.pytorch.free_benchmark.common.enums import (
|
|
@@ -113,6 +114,14 @@ class FuzzHandler(ABC):
|
|
|
113
114
|
origin_output_chunks, perturbed_output_chunks = (
|
|
114
115
|
self.tensor_split_for_error_calculate(origin_output, perturbed_output)
|
|
115
116
|
)
|
|
117
|
+
if len(origin_output_chunks) != len(perturbed_output_chunks):
|
|
118
|
+
err_msg = (
|
|
119
|
+
f"For {self.params.api_name}, the number of compare tensor chunks is different: "
|
|
120
|
+
f"{len(origin_output_chunks)} != {len(perturbed_output_chunks)}. please check!"
|
|
121
|
+
)
|
|
122
|
+
raise FreeBenchmarkException(
|
|
123
|
+
FreeBenchmarkException.OutputIndexError, err_msg
|
|
124
|
+
)
|
|
116
125
|
norm1 = -np.inf
|
|
117
126
|
norm2 = -np.inf
|
|
118
127
|
norm3 = np.inf
|
|
@@ -189,6 +198,7 @@ class FuzzHandler(ABC):
|
|
|
189
198
|
f"[msprobe] Free Benchmark: For {self.params.api_name} "
|
|
190
199
|
f"The compare for output type {type(perturbed_output)} is not supported"
|
|
191
200
|
)
|
|
201
|
+
return True, 1
|
|
192
202
|
|
|
193
203
|
threshold = self.get_threshold(Tools.get_first_tensor_dtype(origin_output))
|
|
194
204
|
ratio = self.ratio_calculate(
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
|
|
16
16
|
from typing import Any
|
|
17
17
|
|
|
18
|
+
from msprobe.core.common.exceptions import FreeBenchmarkException
|
|
19
|
+
from msprobe.pytorch.free_benchmark import logger
|
|
18
20
|
from msprobe.pytorch.free_benchmark.common.params import DataParams
|
|
19
21
|
from msprobe.pytorch.free_benchmark.common.utils import Tools
|
|
20
22
|
from msprobe.pytorch.free_benchmark.result_handlers.base_handler import FuzzHandler
|
|
21
|
-
from msprobe.pytorch.free_benchmark import logger
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
class FixHandler(FuzzHandler):
|
|
@@ -31,9 +32,9 @@ class FixHandler(FuzzHandler):
|
|
|
31
32
|
return Tools.convert_fuzz_output_to_origin(
|
|
32
33
|
data_params.original_result, data_params.perturbed_result
|
|
33
34
|
)
|
|
34
|
-
except
|
|
35
|
-
logger.
|
|
35
|
+
except FreeBenchmarkException as e:
|
|
36
|
+
logger.warning(
|
|
36
37
|
f"[msprobe] Free Benchmark: For {self.params.api_name} "
|
|
37
|
-
f"Fix output failed
|
|
38
|
+
f"Fix output failed because of: \n{e}"
|
|
38
39
|
)
|
|
39
|
-
|
|
40
|
+
return data_params.original_result
|
|
@@ -1,15 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2024-2024, Huawei Technologies Co., Ltd.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
1
16
|
import os
|
|
2
17
|
from collections import defaultdict
|
|
3
18
|
|
|
4
19
|
import torch
|
|
5
|
-
|
|
6
|
-
from torch.optim.optimizer import register_optimizer_step_pre_hook
|
|
7
|
-
from msprobe.pytorch.grad_probe.grad_stat_csv import GradStatCsv
|
|
8
|
-
from msprobe.core.grad_probe.utils import check_numeral_list_ascend, data_in_list_target
|
|
20
|
+
from msprobe.core.common.file_utils import remove_path, save_npy, write_csv, create_directory
|
|
9
21
|
from msprobe.core.grad_probe.constant import level_adp
|
|
22
|
+
from msprobe.core.grad_probe.utils import check_numeral_list_ascend, data_in_list_target
|
|
10
23
|
from msprobe.pytorch.common.log import logger
|
|
11
|
-
from msprobe.core.common.file_utils import remove_path, save_npy, write_csv, create_directory
|
|
12
24
|
from msprobe.pytorch.common.utils import get_rank_id, print_rank_0
|
|
25
|
+
from msprobe.pytorch.grad_probe.grad_stat_csv import GradStatCsv
|
|
26
|
+
|
|
27
|
+
if int(torch.__version__.split('.')[0]) >= 2:
|
|
28
|
+
from torch.optim.optimizer import register_optimizer_step_pre_hook
|
|
13
29
|
|
|
14
30
|
|
|
15
31
|
class GradientMonitor:
|
|
@@ -75,7 +91,7 @@ class GradientMonitor:
|
|
|
75
91
|
output_lines.append(grad_info)
|
|
76
92
|
if self._level_adp["have_grad_direction"]:
|
|
77
93
|
GradientMonitor.save_grad_direction(param_name, grad,
|
|
78
|
-
|
|
94
|
+
f'{self._output_path}/rank{self._rank}/step{self._step}')
|
|
79
95
|
output_dirpath = os.path.join(self._output_path, f"rank{getattr(self, '_rank')}")
|
|
80
96
|
if not os.path.isdir(output_dirpath):
|
|
81
97
|
create_directory(output_dirpath)
|
|
@@ -87,5 +103,6 @@ class GradientMonitor:
|
|
|
87
103
|
output_lines.insert(0, header_result)
|
|
88
104
|
write_csv(output_lines, output_path)
|
|
89
105
|
logger.info(f"write grad data to {output_path}")
|
|
106
|
+
|
|
90
107
|
if int(torch.__version__.split('.')[0]) >= 2:
|
|
91
108
|
register_optimizer_step_pre_hook(optimizer_pre_step_hook)
|
|
@@ -1,11 +1,27 @@
|
|
|
1
|
+
# Copyright (c) 2024-2024, Huawei Technologies Co., Ltd.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
1
16
|
from abc import ABC, abstractmethod
|
|
2
17
|
from collections import namedtuple
|
|
3
18
|
import hashlib
|
|
19
|
+
from functools import wraps
|
|
4
20
|
import torch
|
|
5
21
|
from msprobe.core.grad_probe.constant import GradConst
|
|
6
22
|
|
|
7
|
-
|
|
8
|
-
|
|
23
|
+
CsvHeaderInput = namedtuple("CsvHeaderInput", ["bounds"])
|
|
24
|
+
CsvContentInput = namedtuple("CsvContentInput", ["grad", "bounds"])
|
|
9
25
|
|
|
10
26
|
|
|
11
27
|
class GradStatCsv:
|
|
@@ -15,7 +31,7 @@ class GradStatCsv:
|
|
|
15
31
|
def generate_csv_header(level, bounds):
|
|
16
32
|
header = ["param_name"]
|
|
17
33
|
for key in level["header"]:
|
|
18
|
-
csv_header_input =
|
|
34
|
+
csv_header_input = CsvHeaderInput(bounds=bounds)
|
|
19
35
|
header.extend(GradStatCsv.csv[key].generate_csv_header(csv_header_input))
|
|
20
36
|
return header
|
|
21
37
|
|
|
@@ -23,7 +39,7 @@ class GradStatCsv:
|
|
|
23
39
|
def generate_csv_line(param_name, level, grad, bounds):
|
|
24
40
|
line = [param_name]
|
|
25
41
|
for key in level["header"]:
|
|
26
|
-
csv_content_input =
|
|
42
|
+
csv_content_input = CsvContentInput(grad=grad, bounds=bounds)
|
|
27
43
|
line.extend(GradStatCsv.csv[key].generate_csv_content(csv_content_input))
|
|
28
44
|
return line
|
|
29
45
|
|
|
@@ -37,20 +53,24 @@ def register_csv_item(key, cls=None):
|
|
|
37
53
|
|
|
38
54
|
|
|
39
55
|
class CsvItem(ABC):
|
|
56
|
+
@staticmethod
|
|
40
57
|
@abstractmethod
|
|
41
58
|
def generate_csv_header(csv_header_input):
|
|
42
59
|
pass
|
|
43
60
|
|
|
61
|
+
@staticmethod
|
|
44
62
|
@abstractmethod
|
|
45
63
|
def generate_csv_content(csv_content_input):
|
|
46
64
|
pass
|
|
47
65
|
|
|
48
66
|
|
|
49
67
|
@register_csv_item(GradConst.MD5)
|
|
50
|
-
class
|
|
68
|
+
class CsvMd5(CsvItem):
|
|
69
|
+
@staticmethod
|
|
51
70
|
def generate_csv_header(csv_header_input):
|
|
52
71
|
return ["MD5"]
|
|
53
72
|
|
|
73
|
+
@staticmethod
|
|
54
74
|
def generate_csv_content(csv_content_input):
|
|
55
75
|
grad = csv_content_input.grad
|
|
56
76
|
tensor_bytes = grad.cpu().detach().float().numpy().tobytes()
|
|
@@ -59,7 +79,8 @@ class CSV_md5(CsvItem):
|
|
|
59
79
|
|
|
60
80
|
|
|
61
81
|
@register_csv_item(GradConst.DISTRIBUTION)
|
|
62
|
-
class
|
|
82
|
+
class CsvDistribution(CsvItem):
|
|
83
|
+
@staticmethod
|
|
63
84
|
def generate_csv_header(csv_header_input):
|
|
64
85
|
bounds = csv_header_input.bounds
|
|
65
86
|
intervals = []
|
|
@@ -73,6 +94,7 @@ class CSV_distribution(CsvItem):
|
|
|
73
94
|
|
|
74
95
|
return intervals
|
|
75
96
|
|
|
97
|
+
@staticmethod
|
|
76
98
|
def generate_csv_content(csv_content_input):
|
|
77
99
|
grad = csv_content_input.grad
|
|
78
100
|
bounds = csv_content_input.bounds
|
|
@@ -90,40 +112,48 @@ class CSV_distribution(CsvItem):
|
|
|
90
112
|
|
|
91
113
|
|
|
92
114
|
@register_csv_item(GradConst.MAX)
|
|
93
|
-
class
|
|
115
|
+
class CsvMax(CsvItem):
|
|
116
|
+
@staticmethod
|
|
94
117
|
def generate_csv_header(csv_header_input):
|
|
95
118
|
return ["max"]
|
|
96
119
|
|
|
120
|
+
@staticmethod
|
|
97
121
|
def generate_csv_content(csv_content_input):
|
|
98
122
|
grad = csv_content_input.grad
|
|
99
123
|
return [torch.max(grad).cpu().detach().float().numpy().tolist()]
|
|
100
124
|
|
|
101
125
|
|
|
102
126
|
@register_csv_item(GradConst.MIN)
|
|
103
|
-
class
|
|
127
|
+
class CsvMin(CsvItem):
|
|
128
|
+
@staticmethod
|
|
104
129
|
def generate_csv_header(csv_header_input):
|
|
105
130
|
return ["min"]
|
|
106
131
|
|
|
132
|
+
@staticmethod
|
|
107
133
|
def generate_csv_content(csv_content_input):
|
|
108
134
|
grad = csv_content_input.grad
|
|
109
135
|
return [torch.min(grad).cpu().detach().float().numpy().tolist()]
|
|
110
136
|
|
|
111
137
|
|
|
112
138
|
@register_csv_item(GradConst.NORM)
|
|
113
|
-
class
|
|
139
|
+
class CsvNorm(CsvItem):
|
|
140
|
+
@staticmethod
|
|
114
141
|
def generate_csv_header(csv_header_input):
|
|
115
142
|
return ["norm"]
|
|
116
143
|
|
|
144
|
+
@staticmethod
|
|
117
145
|
def generate_csv_content(csv_content_input):
|
|
118
146
|
grad = csv_content_input.grad
|
|
119
147
|
return [torch.norm(grad).cpu().detach().float().numpy().tolist()]
|
|
120
148
|
|
|
121
149
|
|
|
122
150
|
@register_csv_item(GradConst.SHAPE)
|
|
123
|
-
class
|
|
151
|
+
class CsvShape(CsvItem):
|
|
152
|
+
@staticmethod
|
|
124
153
|
def generate_csv_header(csv_header_input):
|
|
125
154
|
return ["shape"]
|
|
126
155
|
|
|
156
|
+
@staticmethod
|
|
127
157
|
def generate_csv_content(csv_content_input):
|
|
128
158
|
grad = csv_content_input.grad
|
|
129
159
|
return [list(grad.shape)]
|
|
@@ -30,32 +30,34 @@ def remove_dropout():
|
|
|
30
30
|
from torch import _VF
|
|
31
31
|
from torch.overrides import has_torch_function_unary, handle_torch_function
|
|
32
32
|
|
|
33
|
-
def function_dropout(
|
|
33
|
+
def function_dropout(input_tensor: torch.Tensor, p: float = 0.5, training: bool = True,
|
|
34
34
|
inplace: bool = False) -> torch.Tensor:
|
|
35
|
-
if has_torch_function_unary(
|
|
35
|
+
if has_torch_function_unary(input_tensor):
|
|
36
36
|
return handle_torch_function(
|
|
37
|
-
function_dropout, (
|
|
37
|
+
function_dropout, (input_tensor,), input_tensor, p=0., training=training, inplace=inplace)
|
|
38
38
|
if p < 0.0 or p > 1.0:
|
|
39
39
|
raise ValueError("dropout probability has to be between 0 and 1, " "but got {}".format(p))
|
|
40
|
-
return _VF.dropout_(
|
|
40
|
+
return _VF.dropout_(input_tensor, 0., training) if inplace else _VF.dropout(input_tensor, 0., training)
|
|
41
41
|
|
|
42
|
-
def function_dropout2d(
|
|
42
|
+
def function_dropout2d(input_tensor: torch.Tensor, p: float = 0.5, training: bool = True,
|
|
43
43
|
inplace: bool = False) -> torch.Tensor:
|
|
44
|
-
if has_torch_function_unary(
|
|
44
|
+
if has_torch_function_unary(input_tensor):
|
|
45
45
|
return handle_torch_function(
|
|
46
|
-
function_dropout2d, (
|
|
46
|
+
function_dropout2d, (input_tensor,), input_tensor, p=0., training=training, inplace=inplace)
|
|
47
47
|
if p < 0.0 or p > 1.0:
|
|
48
48
|
raise ValueError("dropout probability has to be between 0 and 1, " "but got {}".format(p))
|
|
49
|
-
return _VF.feature_dropout_(
|
|
49
|
+
return _VF.feature_dropout_(input_tensor, 0., training) if inplace else _VF.feature_dropout(input_tensor,
|
|
50
|
+
0., training)
|
|
50
51
|
|
|
51
|
-
def function_dropout3d(
|
|
52
|
+
def function_dropout3d(input_tensor: torch.Tensor, p: float = 0.5, training: bool = True,
|
|
52
53
|
inplace: bool = False) -> torch.Tensor:
|
|
53
|
-
if has_torch_function_unary(
|
|
54
|
+
if has_torch_function_unary(input_tensor):
|
|
54
55
|
return handle_torch_function(
|
|
55
|
-
function_dropout3d, (
|
|
56
|
+
function_dropout3d, (input_tensor,), input_tensor, p=0., training=training, inplace=inplace)
|
|
56
57
|
if p < 0.0 or p > 1.0:
|
|
57
58
|
raise ValueError("dropout probability has to be between 0 and 1, " "but got {}".format(p))
|
|
58
|
-
return _VF.feature_dropout_(
|
|
59
|
+
return _VF.feature_dropout_(input_tensor, 0., training) if inplace else _VF.feature_dropout(input_tensor,
|
|
60
|
+
0., training)
|
|
59
61
|
|
|
60
62
|
F.dropout = function_dropout
|
|
61
63
|
F.dropout2d = function_dropout2d
|
|
@@ -17,7 +17,7 @@ from functools import wraps
|
|
|
17
17
|
|
|
18
18
|
import torch
|
|
19
19
|
from msprobe.core.common.const import Const
|
|
20
|
-
from msprobe.core.data_dump.scope import ModuleRangeScope
|
|
20
|
+
from msprobe.core.data_dump.scope import ModuleRangeScope, MixRangeScope
|
|
21
21
|
from torch.utils.hooks import BackwardHook
|
|
22
22
|
|
|
23
23
|
torch_version_above_or_equal_2 = torch.__version__.split('+')[0] >= '2.0'
|
|
@@ -30,10 +30,7 @@ class ModuleProcesser:
|
|
|
30
30
|
module_node = {}
|
|
31
31
|
|
|
32
32
|
def __init__(self, scope):
|
|
33
|
-
if isinstance(scope, ModuleRangeScope)
|
|
34
|
-
self.scope = scope
|
|
35
|
-
else:
|
|
36
|
-
self.scope = None
|
|
33
|
+
self.scope = scope if isinstance(scope, (ModuleRangeScope, MixRangeScope)) else None
|
|
37
34
|
BackwardHook.setup_input_hook = ModuleProcesser.clone_return_value(BackwardHook.setup_input_hook)
|
|
38
35
|
BackwardHook.setup_output_hook = ModuleProcesser.clone_return_value(BackwardHook.setup_output_hook)
|
|
39
36
|
BackwardHook.setup_output_hook = ModuleProcesser.filter_tensor_and_tuple(BackwardHook.setup_output_hook)
|