mindstudio-probe 1.1.1__py3-none-any.whl → 1.2.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.1.dist-info → mindstudio_probe-1.2.1.dist-info}/METADATA +3 -2
- {mindstudio_probe-1.1.1.dist-info → mindstudio_probe-1.2.1.dist-info}/RECORD +196 -141
- msprobe/CMakeLists.txt +5 -0
- msprobe/README.md +14 -19
- msprobe/config.json +1 -0
- msprobe/core/common/const.py +155 -6
- msprobe/core/common/exceptions.py +3 -1
- msprobe/core/common/file_utils.py +33 -7
- msprobe/core/common/inplace_ops.yaml +3 -0
- msprobe/core/common/utils.py +28 -14
- msprobe/core/common_config.py +6 -0
- msprobe/core/compare/acc_compare.py +139 -128
- msprobe/core/compare/check.py +31 -29
- msprobe/core/compare/compare_cli.py +17 -16
- msprobe/core/compare/highlight.py +186 -99
- msprobe/core/compare/layer_mapping/data_scope_parser.py +18 -7
- msprobe/core/compare/layer_mapping/layer_mapping.py +21 -14
- msprobe/core/compare/layer_mapping/postprocess_pass.py +4 -3
- msprobe/core/compare/merge_result/merge_result.py +380 -0
- msprobe/core/compare/merge_result/merge_result_cli.py +31 -0
- msprobe/core/compare/multiprocessing_compute.py +2 -2
- msprobe/core/compare/npy_compare.py +109 -147
- msprobe/core/compare/utils.py +189 -69
- msprobe/core/data_dump/data_collector.py +51 -21
- msprobe/core/data_dump/data_processor/base.py +38 -20
- msprobe/core/data_dump/data_processor/factory.py +5 -3
- msprobe/core/data_dump/data_processor/mindspore_processor.py +154 -20
- msprobe/core/data_dump/data_processor/pytorch_processor.py +118 -58
- msprobe/core/data_dump/json_writer.py +29 -1
- msprobe/core/data_dump/scope.py +19 -18
- msprobe/core/overflow_check/abnormal_scene.py +9 -5
- msprobe/core/overflow_check/checker.py +1 -1
- msprobe/core/overflow_check/utils.py +1 -1
- msprobe/docs/01.installation.md +96 -17
- msprobe/docs/02.config_introduction.md +5 -5
- msprobe/docs/05.data_dump_PyTorch.md +91 -61
- msprobe/docs/06.data_dump_MindSpore.md +57 -19
- msprobe/docs/07.accuracy_checker_PyTorch.md +18 -18
- msprobe/docs/09.accuracy_checker_MindSpore.md +4 -4
- msprobe/docs/10.accuracy_compare_PyTorch.md +99 -41
- msprobe/docs/11.accuracy_compare_MindSpore.md +249 -48
- msprobe/docs/12.overflow_check_PyTorch.md +1 -1
- msprobe/docs/19.monitor.md +120 -27
- msprobe/docs/21.visualization_PyTorch.md +115 -35
- msprobe/docs/22.visualization_MindSpore.md +138 -41
- msprobe/docs/23.generate_operator_PyTorch.md +107 -0
- msprobe/docs/24.code_mapping_Mindspore.md +28 -0
- msprobe/docs/{23.tool_function_introduction.md → 25.tool_function_introduction.md} +1 -0
- msprobe/docs/26.data_dump_PyTorch_baseline.md +37 -0
- msprobe/docs/27.dump_json_instruction.md +521 -0
- msprobe/docs/FAQ.md +26 -2
- msprobe/docs/accuracy_checker_MindSpore/accuracy_checker_MindSpore_baseline.md +14 -0
- msprobe/docs/data_dump_MindSpore/data_dump_MindSpore_baseline.md +22 -0
- msprobe/docs/img/merge_result.png +0 -0
- msprobe/docs/img/visualization/fuzzy_match_ms.png +0 -0
- msprobe/docs/img/visualization/fuzzy_match_pt.png +0 -0
- msprobe/docs/img/visualization/tensorboard_1.png +0 -0
- msprobe/docs/img/visualization/tensorboard_2.png +0 -0
- msprobe/docs/img/visualization/vis_browser_1.png +0 -0
- msprobe/docs/img/visualization/vis_browser_2.png +0 -0
- msprobe/docs/img/visualization/vis_precision_info.png +0 -0
- msprobe/docs/img/visualization/vis_search_info.png +0 -0
- msprobe/docs/img/visualization/vis_show_info.png +0 -0
- msprobe/docs/img/visualization/vis_showcase.png +0 -0
- msprobe/docs/img/visualization/vis_unmatch_info.png +0 -0
- msprobe/docs/visualization/GPTModel.png +0 -0
- msprobe/docs/visualization/ParallelMLP.png +0 -0
- msprobe/docs/visualization/layer_mapping_example.md +132 -0
- msprobe/docs/visualization/mapping.png +0 -0
- msprobe/docs/visualization/mapping1.png +0 -0
- msprobe/docs/visualization/module_name.png +0 -0
- msprobe/docs/visualization/module_name1.png +0 -0
- msprobe/docs/visualization/no_mapping.png +0 -0
- msprobe/docs/visualization/no_mapping1.png +0 -0
- msprobe/docs/visualization/no_mapping_analyze.png +0 -0
- msprobe/docs/visualization/top_layer.png +0 -0
- msprobe/mindspore/__init__.py +10 -0
- msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +57 -25
- msprobe/mindspore/api_accuracy_checker/cmd_parser.py +2 -1
- msprobe/mindspore/api_accuracy_checker/compute_element.py +5 -7
- msprobe/mindspore/api_accuracy_checker/data_manager.py +37 -0
- msprobe/mindspore/api_accuracy_checker/main.py +1 -0
- msprobe/mindspore/api_accuracy_checker/multi_api_accuracy_checker.py +12 -6
- msprobe/mindspore/api_accuracy_checker/multi_data_manager.py +3 -1
- msprobe/mindspore/code_mapping/bind.py +264 -0
- msprobe/mindspore/code_mapping/cmd_parser.py +40 -0
- msprobe/mindspore/code_mapping/graph.py +49 -0
- msprobe/mindspore/code_mapping/graph_parser.py +226 -0
- msprobe/mindspore/code_mapping/main.py +24 -0
- msprobe/mindspore/code_mapping/processor.py +34 -0
- msprobe/mindspore/common/const.py +3 -1
- msprobe/mindspore/common/utils.py +50 -5
- msprobe/mindspore/compare/distributed_compare.py +0 -2
- msprobe/mindspore/compare/ms_compare.py +105 -63
- msprobe/mindspore/compare/ms_graph_compare.py +14 -5
- msprobe/mindspore/debugger/debugger_config.py +3 -0
- msprobe/mindspore/debugger/precision_debugger.py +81 -12
- msprobe/mindspore/dump/hook_cell/api_registry.py +83 -16
- msprobe/mindspore/dump/hook_cell/hook_cell.py +60 -38
- msprobe/mindspore/dump/hook_cell/primitive_hooks.py +33 -15
- msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +11 -1
- msprobe/mindspore/dump/hook_cell/wrap_api.py +92 -1
- msprobe/mindspore/dump/kernel_dump/kernel_config.py +33 -0
- msprobe/mindspore/dump/kernel_graph_dump.py +7 -0
- msprobe/mindspore/free_benchmark/api_pynative_self_check.py +13 -4
- msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +2 -2
- msprobe/mindspore/grad_probe/grad_analyzer.py +24 -12
- msprobe/mindspore/grad_probe/hook.py +13 -4
- msprobe/mindspore/mindtorch/__init__.py +18 -0
- msprobe/mindspore/mindtorch/mindtorch_adaptor.py +255 -0
- msprobe/mindspore/ms_config.py +5 -1
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +7 -0
- msprobe/mindspore/service.py +267 -101
- msprobe/msprobe.py +24 -3
- msprobe/pytorch/__init__.py +7 -6
- msprobe/pytorch/api_accuracy_checker/common/utils.py +31 -16
- msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +41 -8
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +100 -267
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_standard.yaml +4 -1
- msprobe/pytorch/api_accuracy_checker/compare/compare.py +69 -68
- msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +54 -0
- msprobe/pytorch/api_accuracy_checker/compare/compare_input.py +51 -0
- msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +2 -4
- msprobe/pytorch/api_accuracy_checker/generate_op_script/op_generator.py +54 -30
- msprobe/pytorch/api_accuracy_checker/precision_standard/absolute_threshold.py +106 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/accumulative_error_compare.py +107 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/base_standard.py +151 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/benchmark_compare.py +226 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/binary_consistency.py +68 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/standard_config.py +218 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/standard_register.py +104 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/thousandth_standard.py +63 -0
- msprobe/pytorch/api_accuracy_checker/precision_standard/ulp_compare.py +200 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +57 -1
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +2 -1
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +42 -14
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +64 -19
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +34 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +5 -3
- msprobe/pytorch/bench_functions/npu_fusion_attention.py +42 -10
- msprobe/pytorch/common/parse_json.py +2 -1
- msprobe/pytorch/common/utils.py +45 -2
- msprobe/pytorch/compare/distributed_compare.py +17 -29
- msprobe/pytorch/compare/pt_compare.py +40 -20
- msprobe/pytorch/debugger/debugger_config.py +27 -12
- msprobe/pytorch/debugger/precision_debugger.py +42 -12
- msprobe/pytorch/dump/module_dump/__init__.py +0 -0
- msprobe/pytorch/dump/module_dump/module_dump.py +86 -0
- msprobe/pytorch/{module_processer.py → dump/module_dump/module_processer.py} +80 -6
- msprobe/pytorch/free_benchmark/common/params.py +2 -1
- msprobe/pytorch/free_benchmark/common/utils.py +3 -0
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +0 -2
- msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +31 -47
- msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +0 -4
- msprobe/pytorch/hook_module/__init__.py +1 -1
- msprobe/pytorch/hook_module/hook_module.py +14 -11
- msprobe/pytorch/hook_module/register_optimizer_hook.py +59 -0
- msprobe/pytorch/hook_module/support_wrap_ops.yaml +34 -0
- msprobe/pytorch/hook_module/wrap_distributed.py +6 -8
- msprobe/pytorch/hook_module/wrap_functional.py +0 -40
- msprobe/pytorch/monitor/anomaly_analyse.py +1 -1
- msprobe/pytorch/monitor/anomaly_detect.py +107 -22
- msprobe/pytorch/monitor/csv2tb.py +166 -0
- msprobe/pytorch/monitor/distributed/wrap_distributed.py +25 -14
- msprobe/pytorch/monitor/features.py +3 -3
- msprobe/pytorch/monitor/module_hook.py +483 -277
- msprobe/pytorch/monitor/module_metric.py +27 -48
- msprobe/pytorch/monitor/module_spec_verifier.py +3 -1
- msprobe/pytorch/monitor/optimizer_collect.py +52 -14
- msprobe/pytorch/monitor/unittest/test_monitor.py +24 -9
- msprobe/pytorch/monitor/utils.py +77 -6
- msprobe/pytorch/online_dispatch/dispatch.py +8 -2
- msprobe/pytorch/parse_tool/lib/compare.py +10 -10
- msprobe/pytorch/parse_tool/lib/config.py +5 -7
- msprobe/pytorch/parse_tool/lib/file_desc.py +15 -1
- msprobe/pytorch/parse_tool/lib/interactive_cli.py +10 -10
- msprobe/pytorch/parse_tool/lib/parse_exception.py +7 -7
- msprobe/pytorch/parse_tool/lib/parse_tool.py +11 -10
- msprobe/pytorch/parse_tool/lib/utils.py +18 -19
- msprobe/pytorch/parse_tool/lib/visualization.py +9 -10
- msprobe/pytorch/service.py +176 -106
- msprobe/visualization/builder/graph_builder.py +62 -5
- msprobe/visualization/builder/msprobe_adapter.py +24 -2
- msprobe/visualization/compare/graph_comparator.py +64 -14
- msprobe/visualization/compare/mode_adapter.py +1 -15
- msprobe/visualization/graph/base_node.py +12 -17
- msprobe/visualization/graph/distributed_analyzer.py +318 -0
- msprobe/visualization/graph/graph.py +9 -0
- msprobe/visualization/graph_service.py +97 -23
- msprobe/visualization/utils.py +14 -29
- msprobe/pytorch/functional/module_dump.py +0 -84
- {mindstudio_probe-1.1.1.dist-info → mindstudio_probe-1.2.1.dist-info}/LICENSE +0 -0
- {mindstudio_probe-1.1.1.dist-info → mindstudio_probe-1.2.1.dist-info}/WHEEL +0 -0
- {mindstudio_probe-1.1.1.dist-info → mindstudio_probe-1.2.1.dist-info}/entry_points.txt +0 -0
- {mindstudio_probe-1.1.1.dist-info → mindstudio_probe-1.2.1.dist-info}/top_level.txt +0 -0
- /msprobe/docs/{data_dump_Mindspore → data_dump_MindSpore}/dynamic_graph_quick_start_example.md +0 -0
- /msprobe/{pytorch/functional → mindspore/code_mapping}/__init__.py +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Copyright (c) 2024-2025, 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
|
+
import datetime
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
from multiprocessing import Process
|
|
19
|
+
|
|
20
|
+
import pytz
|
|
21
|
+
from torch.utils.tensorboard import SummaryWriter
|
|
22
|
+
from tqdm import tqdm
|
|
23
|
+
|
|
24
|
+
from msprobe.core.common.const import MonitorConst
|
|
25
|
+
from msprobe.core.common.file_utils import read_csv, create_directory, remove_path
|
|
26
|
+
from msprobe.core.common.utils import is_int
|
|
27
|
+
from msprobe.pytorch.common.log import logger
|
|
28
|
+
from msprobe.pytorch.monitor.utils import get_target_output_dir
|
|
29
|
+
|
|
30
|
+
all_data_type_list = ["actv", "actv_grad", "exp_avg", "exp_avg_sq", "grad_unreduced", "grad_reduced", "param"]
|
|
31
|
+
CSV_FILE_SUFFIX = r"_\d+-\d+\.csv"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def parse_step_line(data, line_id, name, ops):
|
|
35
|
+
vp_id = data["vpp_stage"][line_id]
|
|
36
|
+
module_name = data[name][line_id]
|
|
37
|
+
step = data["step"][line_id]
|
|
38
|
+
vpp_name = f"vp{vp_id}:{module_name}"
|
|
39
|
+
ops_result = {}
|
|
40
|
+
for op in ops:
|
|
41
|
+
ops_result[op] = data[op][line_id]
|
|
42
|
+
return vpp_name, step, ops_result
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def parse_step_fn(filepath):
|
|
46
|
+
data = read_csv(filepath)
|
|
47
|
+
|
|
48
|
+
header = list(data.keys())
|
|
49
|
+
name = header[MonitorConst.HEADER_NAME_INDEX]
|
|
50
|
+
ops = header[MonitorConst.OPS_START_INDEX:]
|
|
51
|
+
|
|
52
|
+
parse_step_result = {}
|
|
53
|
+
|
|
54
|
+
for line_id in range(len(data)):
|
|
55
|
+
vpp_name, step, ops_result = parse_step_line(data, line_id, name, ops)
|
|
56
|
+
if vpp_name not in parse_step_result:
|
|
57
|
+
parse_step_result[vpp_name] = {}
|
|
58
|
+
if step in parse_step_result[vpp_name]:
|
|
59
|
+
raise Exception(f"duplicated step({step})")
|
|
60
|
+
parse_step_result[vpp_name][step] = ops_result
|
|
61
|
+
return parse_step_result
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def write_step(output_dirpath, parse_step_result, rank, data_type):
|
|
65
|
+
tb_output_path = os.path.join(output_dirpath, f"rank{rank}", data_type)
|
|
66
|
+
if os.path.exists(tb_output_path):
|
|
67
|
+
remove_path(tb_output_path)
|
|
68
|
+
logger.warning(f"existing path {tb_output_path} will be recovered")
|
|
69
|
+
writer = SummaryWriter(tb_output_path)
|
|
70
|
+
for vpp_name, step_data_dict in parse_step_result.items():
|
|
71
|
+
step_data_list = [(step, ops) for step, ops in step_data_dict.items()]
|
|
72
|
+
step_data_list.sort(key=lambda x: x[0])
|
|
73
|
+
for step_data in step_data_list:
|
|
74
|
+
step = step_data[0]
|
|
75
|
+
ops = step_data[1]
|
|
76
|
+
for op, value in ops.items():
|
|
77
|
+
tag = f"{vpp_name}/{op}"
|
|
78
|
+
writer.add_scalar(tag, value, step)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def update_dict(dict1, dict2):
|
|
82
|
+
for key, value in dict2.items():
|
|
83
|
+
if key in dict1:
|
|
84
|
+
if isinstance(dict1[key], dict) and isinstance(value, dict):
|
|
85
|
+
try:
|
|
86
|
+
update_dict(dict1[key], value)
|
|
87
|
+
except Exception as e:
|
|
88
|
+
raise Exception(f"Error updating nested dict failed at key '{key}': {e}") from e
|
|
89
|
+
else:
|
|
90
|
+
raise Exception(f"duplicate key: {key}")
|
|
91
|
+
else:
|
|
92
|
+
dict1[key] = value
|
|
93
|
+
return dict1
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def csv2tb_by_step_work(target_output_dirs, output_dirpath, data_type_list):
|
|
97
|
+
for directory in tqdm(target_output_dirs):
|
|
98
|
+
dirpath = directory["path"]
|
|
99
|
+
rank = directory["rank"]
|
|
100
|
+
for data_type in data_type_list:
|
|
101
|
+
all_step_result = {}
|
|
102
|
+
for filename in os.listdir(dirpath):
|
|
103
|
+
if not re.match(f"{data_type}{CSV_FILE_SUFFIX}", filename):
|
|
104
|
+
continue
|
|
105
|
+
filepath = os.path.join(dirpath, filename)
|
|
106
|
+
try:
|
|
107
|
+
parse_step_result = parse_step_fn(filepath)
|
|
108
|
+
except Exception as e:
|
|
109
|
+
logger.error(f"csv2tensorboard parse {filepath} failed \n {e}")
|
|
110
|
+
break
|
|
111
|
+
|
|
112
|
+
all_step_result = update_dict(all_step_result, parse_step_result)
|
|
113
|
+
if all_step_result:
|
|
114
|
+
write_step(output_dirpath, all_step_result, rank, data_type)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def check_process_num(process_num):
|
|
118
|
+
if not is_int(process_num) or process_num <= 0:
|
|
119
|
+
raise ValueError(f"process_num({process_num}) is not a positive integer")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def check_data_type_list(data_type_list):
|
|
123
|
+
if data_type_list is None:
|
|
124
|
+
logger.info(f"data_type_list is None, use defualt all_data_type_list: {all_data_type_list}")
|
|
125
|
+
return
|
|
126
|
+
if not isinstance(data_type_list, list):
|
|
127
|
+
raise ValueError(f"data_type_list({data_type_list}) is not a list")
|
|
128
|
+
for data_type in data_type_list:
|
|
129
|
+
if data_type not in all_data_type_list:
|
|
130
|
+
raise ValueError(f"data type({data_type}) is not supported, supported data type: {all_data_type_list}")
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def csv2tensorboard_by_step(
|
|
134
|
+
monitor_path,
|
|
135
|
+
time_start=None,
|
|
136
|
+
time_end=None,
|
|
137
|
+
process_num=1,
|
|
138
|
+
data_type_list=None,
|
|
139
|
+
output_dirpath=None
|
|
140
|
+
):
|
|
141
|
+
check_process_num(process_num)
|
|
142
|
+
check_data_type_list(data_type_list)
|
|
143
|
+
target_output_dirs = get_target_output_dir(monitor_path, time_start, time_end)
|
|
144
|
+
target_output_dirs = [{"rank": rank, "path": path} for rank, path in target_output_dirs.items()]
|
|
145
|
+
if output_dirpath is None:
|
|
146
|
+
local_tz = pytz.timezone("Asia/Shanghai") # 根据需要调整为目标时区
|
|
147
|
+
cur_time = datetime.datetime.now(local_tz).strftime("%b%d_%H-%M-%S")
|
|
148
|
+
output_dirpath = os.path.join(monitor_path, f"{cur_time}-csv2tensorboard_by_step")
|
|
149
|
+
create_directory(output_dirpath)
|
|
150
|
+
|
|
151
|
+
task_num = len(target_output_dirs)
|
|
152
|
+
task_num_per_pro = task_num // process_num
|
|
153
|
+
target_data_type = data_type_list if data_type_list else all_data_type_list
|
|
154
|
+
|
|
155
|
+
processes = []
|
|
156
|
+
for pro_id in range(process_num):
|
|
157
|
+
task_start_id = pro_id * task_num_per_pro
|
|
158
|
+
task_end_id = (pro_id + 1) * task_num_per_pro if pro_id != process_num - 1 else task_num
|
|
159
|
+
task_dirs = target_output_dirs[task_start_id: task_end_id]
|
|
160
|
+
|
|
161
|
+
p = Process(target=csv2tb_by_step_work, args=(task_dirs, output_dirpath, target_data_type))
|
|
162
|
+
processes.append(p)
|
|
163
|
+
p.start()
|
|
164
|
+
for p in processes:
|
|
165
|
+
p.join()
|
|
166
|
+
logger.info(f"output has been saved to: {output_dirpath}")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (c) 2024-
|
|
1
|
+
# Copyright (c) 2024-2025, Huawei Technologies Co., Ltd.
|
|
2
2
|
# All rights reserved.
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
|
+
import inspect
|
|
16
17
|
import os
|
|
17
18
|
import re
|
|
18
|
-
import inspect
|
|
19
19
|
|
|
20
20
|
import torch
|
|
21
|
-
import torch.nn as nn
|
|
22
21
|
import torch.distributed as dist
|
|
22
|
+
import torch.nn as nn
|
|
23
23
|
|
|
24
|
-
from msprobe.core.common.file_utils import load_yaml
|
|
25
24
|
from msprobe.core.common.const import MonitorConst
|
|
25
|
+
from msprobe.core.common.file_utils import load_yaml
|
|
26
26
|
from msprobe.pytorch.monitor.module_metric import get_metrics, get_summary_writer_tag_name
|
|
27
27
|
|
|
28
28
|
try:
|
|
@@ -57,10 +57,13 @@ class DistributedOPTemplate(nn.Module):
|
|
|
57
57
|
super(DistributedOPTemplate, self).__init__()
|
|
58
58
|
self.op_name_ = str(op_name)
|
|
59
59
|
self.__name__ = self.op_name_
|
|
60
|
+
self.cc_hooks = []
|
|
60
61
|
for pre_hook in pre_hooks:
|
|
61
|
-
self.register_forward_pre_hook(pre_hook, with_kwargs=True)
|
|
62
|
+
handle = self.register_forward_pre_hook(pre_hook, with_kwargs=True)
|
|
63
|
+
self.cc_hooks.append(handle)
|
|
62
64
|
for hook in post_hooks:
|
|
63
|
-
self.register_forward_hook(hook, with_kwargs=True)
|
|
65
|
+
handle = self.register_forward_hook(hook, with_kwargs=True)
|
|
66
|
+
self.cc_hooks.append(handle)
|
|
64
67
|
|
|
65
68
|
def forward(self, *args, **kwargs):
|
|
66
69
|
return distributed_func.get(self.op_name_)(*args, **kwargs)
|
|
@@ -120,8 +123,11 @@ class ApiRegistry:
|
|
|
120
123
|
|
|
121
124
|
def initialize_hook(self, pre_hooks, post_hooks):
|
|
122
125
|
self.store_ori_attr(dist, get_distributed_ops(), self.distributed_attr_origin)
|
|
126
|
+
cc_hooks = []
|
|
123
127
|
for op_name in get_distributed_ops():
|
|
124
128
|
self.distributed_attr_hooked[op_name] = DistributedOPTemplate(op_name, pre_hooks, post_hooks)
|
|
129
|
+
cc_hooks.extend(self.distributed_attr_hooked[op_name].cc_hooks)
|
|
130
|
+
return cc_hooks
|
|
125
131
|
|
|
126
132
|
|
|
127
133
|
def get_process_group(process_group):
|
|
@@ -237,15 +243,20 @@ def create_hooks(context, monitor):
|
|
|
237
243
|
args = args + tuple(kwargs.values())
|
|
238
244
|
if out: # async
|
|
239
245
|
if isinstance(out, dist.Work):
|
|
240
|
-
PENDING_ASYNC_CC_BY_HANDLE[out] = create_async_callback_func(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
PENDING_ASYNC_CC_BY_HANDLE[out] = create_async_callback_func(
|
|
247
|
+
context[module.op_name_],
|
|
248
|
+
module.op_name_,
|
|
249
|
+
monitor.ops, args,
|
|
250
|
+
MonitorConst.PREFIX_POST
|
|
251
|
+
)
|
|
252
|
+
elif isinstance(out, list): # batch_isend_irecv
|
|
244
253
|
for out_element in out:
|
|
245
|
-
PENDING_ASYNC_CC_BY_HANDLE[out_element] = create_async_callback_func(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
254
|
+
PENDING_ASYNC_CC_BY_HANDLE[out_element] = create_async_callback_func(
|
|
255
|
+
context[module.op_name_],
|
|
256
|
+
module.op_name_,
|
|
257
|
+
monitor.ops, args,
|
|
258
|
+
MonitorConst.PREFIX_POST
|
|
259
|
+
)
|
|
249
260
|
return out
|
|
250
261
|
catch_data(context[module.op_name_], module.op_name_, monitor.ops, args, MonitorConst.PREFIX_POST)
|
|
251
262
|
return out
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import torch
|
|
17
17
|
from torch.autograd.functional import jacobian
|
|
18
|
-
from msprobe.
|
|
18
|
+
from msprobe.pytorch.common.log import logger
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
@torch.no_grad()
|
|
@@ -30,12 +30,12 @@ def get_min(x: torch.tensor):
|
|
|
30
30
|
|
|
31
31
|
@torch.no_grad()
|
|
32
32
|
def get_mean(x: torch.tensor):
|
|
33
|
-
return torch.mean(x)
|
|
33
|
+
return torch.mean(x.to(torch.float64))
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
@torch.no_grad()
|
|
37
37
|
def get_norm(x: torch.tensor):
|
|
38
|
-
return torch.norm(x, p=2)
|
|
38
|
+
return torch.norm(x.to(torch.float64), p=2)
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
@torch.no_grad()
|