已合并
refactor: correct English grammar, spelling, and style in log/warning messages #44119
wanglijun55创建于 8月8日
refactor: correct English grammar, spelling, and style in log/warning messages #44119
已合并
wanglijun55创建于 8月8日
38 个文件变更+384-264
@@ -32059,5 +32059,14 @@
32059 "test_upsampling_bfloat16 (__main__.TestNN)": ["", [""]],32059 "test_upsampling_bfloat16 (__main__.TestNN)": ["", [""]],
32060 "test_data_parallel_rnn (__main__.TestDataParallel)": ["", ["Disabled during A1 to A2 chip transition"]],32060 "test_data_parallel_rnn (__main__.TestDataParallel)": ["", ["Disabled during A1 to A2 chip transition"]],
32061 "test_alltoall_single_2p_size_dist (__main__.HcclAlltoAllSingleTest)": ["", ["Disabled during A1 to A2 chip transition"]],32061 "test_alltoall_single_2p_size_dist (__main__.HcclAlltoAllSingleTest)": ["", ["Disabled during A1 to A2 chip transition"]],
32062- "test_stream (__main__.StreamintoDynamoTests)": ["", ["Dynamo Stream support incomplete: wait_stream() not properly handled. Introduced by commit d3be6fdfa"]]32062+ "test_stream (__main__.StreamintoDynamoTests)": ["", ["Dynamo Stream support incomplete: wait_stream() not properly handled. Introduced by commit d3be6fdfa"]],
32063+ "test_function_event_metadata (__main__.TestExperimentalUtils)": ["", [""]],
32064+ "test_export_chrome_trace_escapes_names (__main__.TestProfiler)": ["", [""]],
32065+ "test_with_modules_deprecated (__main__.TestProfiler)": ["", [""]],
32066+ "test_basic_profile_npu (__main__.TestProfilerDevicePRIVATEUSE1)": ["", [""]],
32067+ "test_dynamic_toggle_npu (__main__.TestProfilerDevicePRIVATEUSE1)": ["", [""]],
32068+ "test_kineto_kernel_metadata_in_trace_npu (__main__.TestProfilerDevicePRIVATEUSE1)": ["", [""]],
32069+ "test_memory_profiler_npu (__main__.TestProfilerDevicePRIVATEUSE1)": ["", [""]],
32070+ "test_profile_all_threads_npu (__main__.TestProfilerDevicePRIVATEUSE1)": ["", [""]],
32071+ "test_profiler_npu (__main__.TestProfilerDevicePRIVATEUSE1)": ["", [""]]
32063}32072}
@@ -74,7 +74,7 @@ def _load_triton_backend():
74 has_triton = torch.utils._triton.has_triton()74 has_triton = torch.utils._triton.has_triton()
75 if not has_triton:75 if not has_triton:
76 import warnings76 import warnings
77- warnings.warn("triton-ascend is not installed, install it first.")77+ warnings.warn("triton-ascend is not installed. Please install it first.")
78 return78 return
79 import logging79 import logging
80 log = logging.getLogger(__name__)80 log = logging.getLogger(__name__)
@@ -284,7 +284,7 @@ def _load_triton_experimental_backend():
284 has_triton = torch.utils._triton.has_triton()284 has_triton = torch.utils._triton.has_triton()
285 if not has_triton:285 if not has_triton:
286 import warnings286 import warnings
287- warnings.warn("triton-ascend is not installed, install it first.")287+ warnings.warn("triton-ascend is not installed. Please install it first.")
288 return288 return
289 # Decomposition / dispatcher / SDPA overrides live in the shared289 # Decomposition / dispatcher / SDPA overrides live in the shared
290 # decomposition.py alongside the other backends' registrars; call it directly290 # decomposition.py alongside the other backends' registrars; call it directly
@@ -148,7 +148,7 @@ class MulitprocessCompileFuture(CodeCacheFuture):
148 future.result(timeout=timeout)148 future.result(timeout=timeout)
149 except Exception as e:149 except Exception as e:
150 err_msg = str(e)150 err_msg = str(e)
151- logger.warning("Error detected when multiprocess compile, error message: %s", err_msg)151+ logger.warning("Error detected during multiprocess compilation. Error message: %s", err_msg)
152 errors.append(e)152 errors.append(e)
153 153 
154 if len(errors) < len(self.futures):154 if len(errors) < len(self.futures):
@@ -2009,7 +2009,7 @@ def fallback_handler(kernel, add_to_fallback_set=True):
2009@functools.lru_cache(None)2009@functools.lru_cache(None)
2010def _warn_complex_not_supported():2010def _warn_complex_not_supported():
2011 warnings.warn(2011 warnings.warn(
2012- "Torchinductor does not support code generation for complex operators. Performance may be worse than eager."2012+ "TorchInductor does not support code generation for complex operators. Performance may be worse than eager."
2013 )2013 )
2014 2014 
2015 2015 
@@ -393,7 +393,7 @@ class NpuMlirCompiler(MetaCompiler):
393 except Exception as e:393 except Exception as e:
394 if suppress_error:394 if suppress_error:
395 error_msg = str(e)395 error_msg = str(e)
396- logger.warning("compile args %s fail, err msg: %s", cargs, error_msg)396+ logger.warning("Failed to compile args %s. Error: %s", cargs, error_msg)
397 else:397 else:
398 raise e398 raise e
399 399 
@@ -696,7 +696,7 @@ class AkgCompiler(MetaCompiler):
696 self.register_fx_fallback(self.kernel_meta)696 self.register_fx_fallback(self.kernel_meta)
697 error_msg = str(e)697 error_msg = str(e)
698 logger.warning(698 logger.warning(
699- "AKG compile failed for %s, fallback to FX. reason: %s",699+ "AKG compilation failed for %s; falling back to FX. Reason: %s",
700 self.kernel_name,700 self.kernel_name,
701 error_msg,701 error_msg,
702 )702 )
@@ -75,7 +75,7 @@ def register_mlir_codegen_backend() -> None:
75 import torch_mlir # noqa: F40175 import torch_mlir # noqa: F401
76 register_backend_for_device("npu", AkgScheduling, NpuMlirWrapperCodeGen)76 register_backend_for_device("npu", AkgScheduling, NpuMlirWrapperCodeGen)
77 except ImportError:77 except ImportError:
78- logger.warning("akg not found, fallback to torch-mlir for compilation.")78+ logger.warning("AKG not found; falling back to torch-mlir for compilation.")
79 register_backend_for_device("npu", NpuMlirScheduling, NpuMlirWrapperCodeGen)79 register_backend_for_device("npu", NpuMlirScheduling, NpuMlirWrapperCodeGen)
80 else:80 else:
81 register_backend_for_device("npu", NpuMlirScheduling, NpuMlirWrapperCodeGen)81 register_backend_for_device("npu", NpuMlirScheduling, NpuMlirWrapperCodeGen)
@@ -747,7 +747,7 @@ class {module_name}(torch.nn.Module):
747 747 
748 if len(blobified_modules) > 0:748 if len(blobified_modules) > 0:
749 warnings.warn(749 warnings.warn(
750- "Was not able to save the following children modules as reprs -"750+ "Was not able to save the following children modules as reprs - "
751 f"saved as pickled files instead: {blobified_modules}"751 f"saved as pickled files instead: {blobified_modules}"
752 )752 )
753 753 
@@ -55,7 +55,7 @@ class TileAutotune:
55 def init_l1_l0_size(self, arch_type):55 def init_l1_l0_size(self, arch_type):
56 if arch_type not in self._supported_archs:56 if arch_type not in self._supported_archs:
57 warnings.warn(57 warnings.warn(
58- f"Unknown arch type to get specific tile size: {arch_type}."58+ f"Unknown arch type for tile size selection: {arch_type}. "
59 f"Will use the default tile size to generate tile configs."59 f"Will use the default tile size to generate tile configs."
60 )60 )
61 arch_type = Arch.AtlasA261 arch_type = Arch.AtlasA2
@@ -98,7 +98,7 @@ class StaticKernelCompiler:
98 log.info("Starting static kernel compilation process...")98 log.info("Starting static kernel compilation process...")
99 debug_dirs = [d for d in self.result_root.iterdir() if d.is_dir() and d.name.endswith("_debug")]99 debug_dirs = [d for d in self.result_root.iterdir() if d.is_dir() and d.name.endswith("_debug")]
100 if not debug_dirs:100 if not debug_dirs:
101- log.error("Can not find json of ops, skipping op_compiler.")101+ log.error("Cannot find json of ops, skipping op_compiler.")
102 return102 return
103 103 
104 debug_dir = max(debug_dirs, key=lambda d: d.stat().st_mtime)104 debug_dir = max(debug_dirs, key=lambda d: d.stat().st_mtime)
@@ -19,7 +19,7 @@ def _configure_interactive_mode():
19 os.environ["TASK_QUEUE_ENABLE"] = "0"19 os.environ["TASK_QUEUE_ENABLE"] = "0"
20 warnings.warn(20 warnings.warn(
21 "On the interactive interface, the value of TASK_QUEUE_ENABLE is set to 0 by default. "21 "On the interactive interface, the value of TASK_QUEUE_ENABLE is set to 0 by default. "
22- "Do not set it to 1 to prevent some unknown errors"22+ "Do not set it to 1 to avoid unexpected errors."
23 )23 )
24 24 
25 25 
@@ -6,11 +6,11 @@ from torch_npu._init.patches.patch_manager import PatchManager
6 6 
7_WARN_MSG = {7_WARN_MSG = {
8 "DropoutWithByteMask": (8 "DropoutWithByteMask": (
9- "torch.nn.DropoutWithByteMask is deprecated and will be removed in future version. "9+ "torch.nn.DropoutWithByteMask is deprecated and will be removed in a future version. "
10 "Use torch_npu.contrib.module.DropoutWithByteMask instead."10 "Use torch_npu.contrib.module.DropoutWithByteMask instead."
11 ),11 ),
12 "dropout_with_byte_mask": (12 "dropout_with_byte_mask": (
13- "torch.nn.functional.dropout_with_byte_mask is deprecated and will be removed in future version. "13+ "torch.nn.functional.dropout_with_byte_mask is deprecated and will be removed in a future version. "
14 "Use torch_npu.contrib.function.dropout_with_byte_mask instead."14 "Use torch_npu.contrib.function.dropout_with_byte_mask instead."
15 ),15 ),
16}16}
@@ -16,7 +16,6 @@ from ._silent_fault_data import SilentFaultData, SilentFaultDataV2
16 16 
17__all__ = []17__all__ = []
18 18 
19- 
20loggerSilent = logging.getLogger("torch_npu.silent_check")19loggerSilent = logging.getLogger("torch_npu.silent_check")
21 20 
22 21 
@@ -27,6 +26,7 @@ def _Singleton(cls):
27 if cls not in _instances:26 if cls not in _instances:
28 _instances[cls] = cls(*args, **kwargs)27 _instances[cls] = cls(*args, **kwargs)
29 return _instances[cls]28 return _instances[cls]
29+ 
30 return _singleton30 return _singleton
31 31 
32 32 
@@ -75,13 +75,15 @@ class _SilentFaultDetector:
75 step_tensor = self.high_step75 step_tensor = self.high_step
76 76 
77 torch_npu._npu_silent_check(grad, val, sfda.pre_val, sfda.min_val, sfda.max_val, step_tensor, self.min_step,77 torch_npu._npu_silent_check(grad, val, sfda.pre_val, sfda.min_val, sfda.max_val, step_tensor, self.min_step,
78- sfda.upper_thresh[0], sfda.sigma_thresh[0], sfda.upper_thresh[1], sfda.sigma_thresh[1])78+ sfda.upper_thresh[0], sfda.sigma_thresh[0], sfda.upper_thresh[1],
79+ sfda.sigma_thresh[1])
79 80 
80 def silent_fault_check_hook(self, weight):81 def silent_fault_check_hook(self, weight):
81 def hook(grad):82 def hook(grad):
82 self.idx = id(weight)83 self.idx = id(weight)
83 self.silent_fault_check(grad)84 self.silent_fault_check(grad)
84 return85 return
86+ 
85 return hook87 return hook
86 88 
87 89 
@@ -136,7 +138,8 @@ class _SilentFaultDetectorV2:
136 138 
137 sfda = self.silent_data_dict[idx]139 sfda = self.silent_data_dict[idx]
138 140 
139- torch_npu._npu_silent_check_v2(val, grad, sfda.check_tensor, sfda.step_tensor, self.min_step, sfda.upper_thresh[0],141+ torch_npu._npu_silent_check_v2(val, grad, sfda.check_tensor, sfda.step_tensor, self.min_step,
142+ sfda.upper_thresh[0],
140 sfda.sigma_thresh[0], sfda.upper_thresh[1], sfda.sigma_thresh[1], asd_flag)143 sfda.sigma_thresh[0], sfda.upper_thresh[1], sfda.sigma_thresh[1], asd_flag)
141 144 
142 145 
@@ -147,17 +150,20 @@ IS_IN_BACKWARD = False
147def _input_hook(idx, asd_flag):150def _input_hook(idx, asd_flag):
148 def hook(grad):151 def hook(grad):
149 global IS_IN_BACKWARD152 global IS_IN_BACKWARD
150- loggerSilent.debug(f"input_hook: IS_IN_BACKWARD is {IS_IN_BACKWARD}, will change to False. idx is {idx}, flag is {asd_flag}")153+ loggerSilent.debug(
154+ "input_hook: IS_IN_BACKWARD is %s, will change to False. idx is %s, flag is %s",
155+ IS_IN_BACKWARD, idx, asd_flag)
151 IS_IN_BACKWARD = False156 IS_IN_BACKWARD = False
152 torch_npu._C._npu_set_call_state("forward")157 torch_npu._C._npu_set_call_state("forward")
153 _silent_fault_detector_v2.silent_fault_check(idx, asd_flag, grad)158 _silent_fault_detector_v2.silent_fault_check(idx, asd_flag, grad)
154 return159 return
160+ 
155 return hook161 return hook
156 162 
157 163 
158def _output_hook(grad):164def _output_hook(grad):
159 global IS_IN_BACKWARD165 global IS_IN_BACKWARD
160- loggerSilent.debug(f"output_hook: IS_IN_BACKWARD is {IS_IN_BACKWARD}, will change to True.")166+ loggerSilent.debug("output_hook: IS_IN_BACKWARD is %s, will change to True.", IS_IN_BACKWARD)
161 IS_IN_BACKWARD = True167 IS_IN_BACKWARD = True
162 torch_npu._C._npu_set_call_state("backward")168 torch_npu._C._npu_set_call_state("backward")
163 return grad169 return grad
@@ -235,15 +241,17 @@ class _SilentCheckState:
235 if self.last_weight is not None and self.first_weight is not None:241 if self.last_weight is not None and self.first_weight is not None:
236 # Otherwise, there is only one weight in the outer module242 # Otherwise, there is only one weight in the outer module
237 if self.first_weight_id != self.last_weight_id:243 if self.first_weight_id != self.last_weight_id:
238- loggerSilent.debug(f"init_all_hook: module init, first_module_id is {self.first_module_id}.")244+ loggerSilent.debug("init_all_hook: module init, first_module_id is %s.", self.first_module_id)
239 if self.last_weight_hook_handles.get(self.first_module_id, None) is None:245 if self.last_weight_hook_handles.get(self.first_module_id, None) is None:
240 last_weight_handle = self.last_weight.register_hook(_output_hook)246 last_weight_handle = self.last_weight.register_hook(_output_hook)
241 self.last_weight_hook_handles[self.first_module_id] = last_weight_handle247 self.last_weight_hook_handles[self.first_module_id] = last_weight_handle
242 if self.weight_hook_handles.get(self.first_module_id, None) is None:248 if self.weight_hook_handles.get(self.first_module_id, None) is None:
243- first_weight_handle = self.first_weight.register_hook(_input_hook(self.first_module_id, self.check_enable))249+ first_weight_handle = self.first_weight.register_hook(
250+ _input_hook(self.first_module_id, self.check_enable))
244 self.weight_hook_handles[self.first_module_id] = first_weight_handle251 self.weight_hook_handles[self.first_module_id] = first_weight_handle
245 else:252 else:
246- loggerSilent.debug(f"init_all_hook: module only have one weight, first_module_id is {self.first_module_id}.")253+ loggerSilent.debug("init_all_hook: module only have one weight, first_module_id is %s.",
254+ self.first_module_id)
247 self.init_marks[self.first_module_id] = True255 self.init_marks[self.first_module_id] = True
248 256 
249 257 
@@ -274,7 +282,7 @@ def _silent_check_decorator(func):
274 if value is not None:282 if value is not None:
275 value.remove()283 value.remove()
276 silent_check.set_check_enable(0)284 silent_check.set_check_enable(0)
277- warnings.warn(f"Warning: Module has unsupported dtype tensor, silent check will be closed.")285+ warnings.warn("Module has an unsupported-dtype tensor; silent check will be closed.")
278 286 
279 tmp = func(self, *args, **kwargs)287 tmp = func(self, *args, **kwargs)
280 288 
@@ -292,6 +300,7 @@ def _silent_check_decorator(func):
292 self.outer = False300 self.outer = False
293 301 
294 return tmp302 return tmp
303+ 
295 return wrapper304 return wrapper
296 305 
297 306 
@@ -330,12 +339,12 @@ class _MatmulSilentCheck:
330 self.invalid_grad_sum = 0339 self.invalid_grad_sum = 0
331 # Threshold340 # Threshold
332 self.with_checksum = False341 self.with_checksum = False
333- self.cooldown = 5 # default 5 min cooldown342+ self.cooldown = 5 # default 5 min cooldown
334- self.strikes_num = 3 # default 3 times343+ self.strikes_num = 3 # default 3 times
335- self.strikes_window = 480 # default 480 min344+ self.strikes_window = 480 # default 480 min
336- self.checksum_cooldown = 180 # default 180 min345+ self.checksum_cooldown = 180 # default 180 min
337- self.upper_thresh1 = 1000000 # default 1000000346+ self.upper_thresh1 = 1000000 # default 1000000
338- self.upper_thresh2 = 100 # default 100347+ self.upper_thresh2 = 100 # default 100
339 self.store = None348 self.store = None
340 self.rank = None349 self.rank = None
341 350 
@@ -446,7 +455,8 @@ class _MatmulSilentCheck:
446 else:455 else:
447 self.invalid_grad_sum += 1456 self.invalid_grad_sum += 1
448 if self.invalid_grad_sum > max(10, len(self.registered_modules)):457 if self.invalid_grad_sum > max(10, len(self.registered_modules)):
449- warnings.warn(f"There is no available grad for detection, and the silent check feature may not take effect.")458+ warnings.warn(
459+ "There is no available grad for detection, and the silent check feature may not take effect.")
450 self.invalid_grad_sum = 0460 self.invalid_grad_sum = 0
451 461 
452 def _detect_grad(self, grad, name):462 def _detect_grad(self, grad, name):
@@ -467,7 +477,7 @@ class _MatmulSilentCheck:
467 else:477 else:
468 self.statistic_value.fill_(torch.pow(torch.norm(grad, float('inf')), 2).detach().float())478 self.statistic_value.fill_(torch.pow(torch.norm(grad, float('inf')), 2).detach().float())
469 479 
470- #Asynchronously copy the value to host480+ # Asynchronously copy the value to host
471 self.lock.acquire()481 self.lock.acquire()
472 self.statistic_cpu_value[self.tail_index].copy_(self.statistic_value.data, non_blocking=True)482 self.statistic_cpu_value[self.tail_index].copy_(self.statistic_value.data, non_blocking=True)
473 self.name_list[self.tail_index] = name483 self.name_list[self.tail_index] = name
@@ -495,9 +505,13 @@ class _MatmulSilentCheck:
495 val = self.statistic_cpu_value[self.head_index].item()505 val = self.statistic_cpu_value[self.head_index].item()
496 name = self.name_list[self.head_index]506 name = self.name_list[self.head_index]
497 while val != -1 and name != "":507 while val != -1 and name != "":
498- loggerSilent.debug(f"[silent data] name:{name}, val: {val}, pre_val: {self.check_stat[name]['pre_val']}, avg: {self.check_stat[name]['avg']}, bp time: {self.check_stat[name]['step']}, none_zero_step: {self.check_stat[name]['none_zero_step']}")508+ loggerSilent.debug(
509+ "[silent data] name:%s, val: %s, pre_val: %s, avg: %s, bp time: %s, none_zero_step: %s",
510+ name, val, self.check_stat[name]['pre_val'], self.check_stat[name]['avg'],
511+ self.check_stat[name]['step'], self.check_stat[name]['none_zero_step'])
499 result, self.check_stat[name]['avg'], self.check_stat[name]['none_zero_step'] = self._silent_check(512 result, self.check_stat[name]['avg'], self.check_stat[name]['none_zero_step'] = self._silent_check(
500- val, self.check_stat[name]['pre_val'], self.check_stat[name]['avg'], self.check_stat[name]['none_zero_step'],513+ val, self.check_stat[name]['pre_val'], self.check_stat[name]['avg'],
514+ self.check_stat[name]['none_zero_step'],
501 self.upper_thresh1, self.upper_thresh2515 self.upper_thresh1, self.upper_thresh2
502 )516 )
503 517 
@@ -559,7 +573,7 @@ class _MatmulSilentCheck:
559 if self.with_checksum:573 if self.with_checksum:
560 self.checksum_state = 1574 self.checksum_state = 1
561 if not self.matmul_with_bf16:575 if not self.matmul_with_bf16:
562- warnings.warn(f"Warning: Module has no supported dtype grad, checksum will not to be linked.")576+ warnings.warn("Module has no supported dtype grad; checksum will not be linked.")
563 return577 return
564 while i >= 0:578 while i >= 0:
565 old_abnormal = self.history_abnormal_list[i]579 old_abnormal = self.history_abnormal_list[i]
@@ -574,7 +588,7 @@ class _MatmulSilentCheck:
574 if self.with_checksum:588 if self.with_checksum:
575 self.checksum_state = 1589 self.checksum_state = 1
576 if not self.matmul_with_bf16:590 if not self.matmul_with_bf16:
577- warnings.warn(f"Warning: Module has no supported dtype grad, checksum will not to be linked.")591+ warnings.warn("Module has no supported dtype grad; checksum will not be linked.")
578 break592 break
579 counting_abnormal_pos.append(i)593 counting_abnormal_pos.append(i)
580 i -= 1594 i -= 1
@@ -585,7 +599,9 @@ class _MatmulSilentCheck:
585 if len(counting_abnormal_pos) == self.strikes_num - 1:599 if len(counting_abnormal_pos) == self.strikes_num - 1:
586 break600 break
587 i -= 1601 i -= 1
588- if len(counting_abnormal_pos) == self.strikes_num - 1 and abs(new_abnormal['time'] - old_abnormal['time']) <= self.strikes_window * 60:602+ if (len(counting_abnormal_pos) == self.strikes_num - 1
603+ and abs(new_abnormal['time'] - old_abnormal['time'])
604+ <= self.strikes_window * 60):
589 # Three strikes605 # Three strikes
590 self._generate_warning_log(counting_abnormal_pos, new_abnormal)606 self._generate_warning_log(counting_abnormal_pos, new_abnormal)
591 for index in counting_abnormal_pos:607 for index in counting_abnormal_pos:
@@ -595,7 +611,7 @@ class _MatmulSilentCheck:
595 if self.with_checksum:611 if self.with_checksum:
596 self.checksum_state = 1612 self.checksum_state = 1
597 if not self.matmul_with_bf16:613 if not self.matmul_with_bf16:
598- warnings.warn(f"Warning: Module has no supported dtype grad, checksum will not to be linked.")614+ warnings.warn("Module has no supported dtype grad; checksum will not be linked.")
599 break615 break
600 elif not old_abnormal['counted']:616 elif not old_abnormal['counted']:
601 # Keep tracing the last counted abnormal617 # Keep tracing the last counted abnormal
@@ -616,38 +632,73 @@ class _MatmulSilentCheck:
616 del self.history_abnormal_list[:first_expired_index]632 del self.history_abnormal_list[:first_expired_index]
617 633 
618 def _generate_event_log(self, new_abnormal):634 def _generate_event_log(self, new_abnormal):
619- info_str = f"[Event][{new_abnormal['time_str']}] [Rank {new_abnormal['rank']}]: A grad-norm spike may happen, "635+ info_str = (
620- info_str = info_str + f"param name {new_abnormal['name']}, abnormal value {new_abnormal['val']}, previous value {new_abnormal['pre_val']}, "636+ f"[Event][{new_abnormal['time_str']}] [Rank {new_abnormal['rank']}]: "
621- info_str = info_str + f"history avg {new_abnormal['avg']}, bp time {new_abnormal['step']}, normal count {new_abnormal['none_zero_step']}."637+ f"A grad-norm spike may happen, "
638+ f"param name {new_abnormal['name']}, "
639+ f"abnormal value {new_abnormal['val']}, "
640+ f"previous value {new_abnormal['pre_val']}, ")
641+ info_str = (
642+ info_str
643+ + f"history avg {new_abnormal['avg']}, "
644+ + f"bp time {new_abnormal['step']}, "
645+ + f"normal count {new_abnormal['none_zero_step']}.")
622 loggerSilent.info(info_str)646 loggerSilent.info(info_str)
623 if self.store is not None and self.rank is not None and self.rank != 0:647 if self.store is not None and self.rank is not None and self.rank != 0:
624 current_log = self.store.get(f"rank_{self.rank}_info_log").decode()648 current_log = self.store.get(f"rank_{self.rank}_info_log").decode()
625- self.store.set(f"rank_{self.rank}_info_log", current_log + "\n" + info_str if current_log != "" else info_str)649+ self.store.set(f"rank_{self.rank}_info_log",
650+ current_log + "\n" + info_str if current_log != "" else info_str)
626 651 
627 def _generate_warning_log(self, counting_abnormal_pos, new_abnormal):652 def _generate_warning_log(self, counting_abnormal_pos, new_abnormal):
628- warning_str = f"[Warning][{new_abnormal['time_str']}] [Rank {new_abnormal['rank']}]: feature detection detects abnormal results!"653+ warning_str = (
654+ f"[Warning][{new_abnormal['time_str']}] [Rank {new_abnormal['rank']}]: "
655+ f"feature detection detects abnormal results!")
629 index = 0656 index = 0
630 for pos in reversed(counting_abnormal_pos):657 for pos in reversed(counting_abnormal_pos):
631- warning_str = warning_str + "\n" + f"Grad-norm spike: index {index}, time {self.history_abnormal_list[pos]['time_str']}, param name {self.history_abnormal_list[pos]['name']}, abnormal value {self.history_abnormal_list[pos]['val']}, previous value {self.history_abnormal_list[pos]['pre_val']}, "658+ warning_str = (
632- warning_str = warning_str + f"history avg {self.history_abnormal_list[pos]['avg']}, bp time {self.history_abnormal_list[pos]['step']}, normal count {self.history_abnormal_list[pos]['none_zero_step']}."659+ warning_str + "\n"
660+ + f"Grad-norm spike: index {index}, "
661+ + f"time {self.history_abnormal_list[pos]['time_str']}, "
662+ + f"param name {self.history_abnormal_list[pos]['name']}, "
663+ + f"abnormal value {self.history_abnormal_list[pos]['val']}, "
664+ + f"previous value {self.history_abnormal_list[pos]['pre_val']}, ")
665+ warning_str = (
666+ warning_str
667+ + f"history avg {self.history_abnormal_list[pos]['avg']}, "
668+ + f"bp time {self.history_abnormal_list[pos]['step']}, "
669+ + f"normal count {self.history_abnormal_list[pos]['none_zero_step']}.")
633 index += 1670 index += 1
634- warning_str = warning_str + "\n" + f"Grad-norm spike: index {index}, time {new_abnormal['time_str']}, param name {new_abnormal['name']}, abnormal value {new_abnormal['val']}, previous value {new_abnormal['pre_val']}, "671+ warning_str = (
635- warning_str = warning_str + f"history avg {new_abnormal['avg']}, bp time {new_abnormal['step']}, normal count {new_abnormal['none_zero_step']}."672+ warning_str + "\n"
673+ + f"Grad-norm spike: index {index}, "
674+ + f"time {new_abnormal['time_str']}, "
675+ + f"param name {new_abnormal['name']}, "
676+ + f"abnormal value {new_abnormal['val']}, "
677+ + f"previous value {new_abnormal['pre_val']}, ")
678+ warning_str = (
679+ warning_str
680+ + f"history avg {new_abnormal['avg']}, "
681+ + f"bp time {new_abnormal['step']}, "
682+ + f"normal count {new_abnormal['none_zero_step']}.")
636 loggerSilent.warning(warning_str)683 loggerSilent.warning(warning_str)
637 if self.store is not None and self.rank is not None and self.rank != 0:684 if self.store is not None and self.rank is not None and self.rank != 0:
638 current_log = self.store.get(f"rank_{self.rank}_warn_log").decode()685 current_log = self.store.get(f"rank_{self.rank}_warn_log").decode()
639- self.store.set(f"rank_{self.rank}_warn_log", current_log + "\n" + warning_str if current_log != "" else warning_str)686+ self.store.set(f"rank_{self.rank}_warn_log",
687+ current_log + "\n" + warning_str if current_log != "" else warning_str)
640 688 
641 def _generate_silent_log(self):689 def _generate_silent_log(self):
642 warning_str = f"[Warning][Rank {self.rank}]: The result of Matmul checksum is abnormal!"690 warning_str = f"[Warning][Rank {self.rank}]: The result of Matmul checksum is abnormal!"
643 loggerSilent.warning(warning_str)691 loggerSilent.warning(warning_str)
644 if self.store is not None and self.rank is not None and self.rank != 0:692 if self.store is not None and self.rank is not None and self.rank != 0:
645 current_log = self.store.get(f"rank_{self.rank}_warn_log").decode()693 current_log = self.store.get(f"rank_{self.rank}_warn_log").decode()
646- self.store.set(f"rank_{self.rank}_warn_log", current_log + "\n" + warning_str if current_log != "" else warning_str)694+ self.store.set(f"rank_{self.rank}_warn_log",
695+ current_log + "\n" + warning_str if current_log != "" else warning_str)
647 696 
648 def _tcp_comm_checksum_state(self):697 def _tcp_comm_checksum_state(self):
649 while self.checksum_state_thread_running:698 while self.checksum_state_thread_running:
650- if hasattr(torch, "npu") and torch.npu.is_initialized() and torch.distributed.is_initialized() and self.store is not None:699+ if (hasattr(torch, "npu") and torch.npu.is_initialized()
700+ and torch.distributed.is_initialized()
701+ and self.store is not None):
651 break702 break
652 time.sleep(10)703 time.sleep(10)
653 if not self.checksum_state_thread_running:704 if not self.checksum_state_thread_running:
@@ -689,7 +740,8 @@ class _MatmulSilentCheck:
689 if global_state:740 if global_state:
690 now_time = time.time()741 now_time = time.time()
691 if last_checksum_time is None or abs(now_time - last_checksum_time) > self.checksum_cooldown * 60:742 if last_checksum_time is None or abs(now_time - last_checksum_time) > self.checksum_cooldown * 60:
692- loggerSilent.info(f'[Info] Rank {self.rank}: feature detection detects abnormal results, checksum is on.')743+ loggerSilent.info('[Info] Rank %s: feature detection detects abnormal results, checksum is on.',
744+ self.rank)
693 last_checksum_time = now_time745 last_checksum_time = now_time
694 if self.checksum_result is None:746 if self.checksum_result is None:
695 self.checksum_result = torch.tensor(False, dtype=torch.bool, device='npu')747 self.checksum_result = torch.tensor(False, dtype=torch.bool, device='npu')
@@ -700,7 +752,7 @@ class _MatmulSilentCheck:
700 if self.checksum_result:752 if self.checksum_result:
701 self._generate_silent_log()753 self._generate_silent_log()
702 self.checksum_enable = False754 self.checksum_enable = False
703- loggerSilent.info(f'[Info] Rank {self.rank}: checksum is off')755+ loggerSilent.info('[Info] Rank %s: checksum is off', self.rank)
704 self.checksum_state = 0756 self.checksum_state = 0
705 self.store.add('counter2', 1)757 self.store.add('counter2', 1)
706 758 
@@ -765,6 +817,7 @@ def _trigger_matmul_decorator(func):
765 checksum = torch_npu.matmul_checksum(a, b, result)817 checksum = torch_npu.matmul_checksum(a, b, result)
766 matmul_check.checksum_result.logical_or_(checksum)818 matmul_check.checksum_result.logical_or_(checksum)
767 return result819 return result
820+ 
768 return wrapper821 return wrapper
769 822 
770 823 
@@ -777,6 +830,7 @@ def _trigger_tensor_matmul_decorator(func):
777 checksum = torch_npu.matmul_checksum(self, other, result)830 checksum = torch_npu.matmul_checksum(self, other, result)
778 matmul_check.checksum_result.logical_or_(checksum)831 matmul_check.checksum_result.logical_or_(checksum)
779 return result832 return result
833+ 
780 return wrapper834 return wrapper
781 835 
782 836 
@@ -806,7 +860,9 @@ def _matmul_silent_check_decorator(func):
806 for name, module in self.named_modules():860 for name, module in self.named_modules():
807 if matmul_check.get_matmul_hook_enable() == 0:861 if matmul_check.get_matmul_hook_enable() == 0:
808 break862 break
809- if len(module._modules) == 0 and name not in matmul_check.registered_modules and id(module) not in matmul_check.visited_modules_id:863+ if (len(module._modules) == 0
864+ and name not in matmul_check.registered_modules
865+ and id(module) not in matmul_check.visited_modules_id):
810 matmul_check.visited_modules_id.append(id(module))866 matmul_check.visited_modules_id.append(id(module))
811 for _, param in module.named_parameters():867 for _, param in module.named_parameters():
812 if not isinstance(param, torch.Tensor) or param.dim() < 2:868 if not isinstance(param, torch.Tensor) or param.dim() < 2:
@@ -833,4 +889,5 @@ def _matmul_silent_check_decorator(func):
833 self.matmul_check_outer = False889 self.matmul_check_outer = False
834 890 
835 return tmp891 return tmp
892+ 
836 return wrapper893 return wrapper
@@ -28,32 +28,35 @@ def _is_format_matched(input_list):
28 28 
29 29 
30@_exec_once30@_exec_once
31-def _check_compatibility_once(hidden_states,31+def _check_compatibility_once(
32- attention_mask,32+ hidden_states,
33- query_kernel,33+ attention_mask,
34- key_kernel,34+ query_kernel,
35- value_kernel,35+ key_kernel,
36- query_bias,36+ value_kernel,
37- key_bias,37+ query_bias,
38- value_bias,38+ key_bias,
39- gamma=None,39+ value_bias,
40- beta=None):40+ gamma=None,
41+ beta=None,
42+):
41 if not _is_format_matched(43 if not _is_format_matched(
42- [hidden_states, attention_mask, query_kernel, key_kernel, value_kernel, query_bias, key_bias, value_bias]):44+ [hidden_states, attention_mask, query_kernel, key_kernel, value_kernel,
45+ query_bias, key_bias, value_bias]):
43 raise RuntimeError(46 raise RuntimeError(
44- 'fused attention check compatibility failed, format not matches' + ops_error(ErrCode.VALUE))47+ 'fused attention check compatibility failed, format not matches'
48+ + ops_error(ErrCode.VALUE))
45 if gamma is not None and beta is not None:49 if gamma is not None and beta is not None:
46 if torch_npu.get_npu_format(gamma) != 2 or torch_npu.get_npu_format(50 if torch_npu.get_npu_format(gamma) != 2 or torch_npu.get_npu_format(
47 beta) != 2:51 beta) != 2:
48 raise RuntimeError(52 raise RuntimeError(
49- 'fused attention check compatibility failed, gamma or beta format not matches' +53+ 'fused attention check compatibility failed, gamma or beta format not matches'
50- ops_error(ErrCode.VALUE)54+ + ops_error(ErrCode.VALUE))
51- )55+ if (len(hidden_states.size()) != 2 or hidden_states.shape[0] % 32 != 0
52- if len(hidden_states.size()) != 2 or hidden_states.shape[56+ or hidden_states.shape[1] not in (1024, 768)):
53- 0] % 32 != 0 or hidden_states.shape[1] not in (1024, 768):
54 raise RuntimeError(57 raise RuntimeError(
55- 'fused attention check compatibility failed, shape of hidden_states not matches' + ops_error(ErrCode.VALUE)58+ 'fused attention check compatibility failed, shape of hidden_states not matches'
56- )59+ + ops_error(ErrCode.VALUE))
57 if len(attention_mask.size()) != 4 or attention_mask.shape[1] != 1 or (60 if len(attention_mask.size()) != 4 or attention_mask.shape[1] != 1 or (
58 attention_mask.shape[2] != attention_mask.shape[3]):61 attention_mask.shape[2] != attention_mask.shape[3]):
59 raise RuntimeError(62 raise RuntimeError(
@@ -89,11 +92,12 @@ class _FusedAttentionWithLayerNorm(torch.autograd.Function):
89 scale=1,92 scale=1,
90 keep_prob=0):93 keep_prob=0):
91 warnings.warn("torch_npu.contrib.npu_fused_attention_with_layernorm is deprecated and "94 warnings.warn("torch_npu.contrib.npu_fused_attention_with_layernorm is deprecated and "
92- "will be removed in future version. Use torch_npu.npu_fusion_attention and "95+ "will be removed in a future version. Use torch_npu.npu_fusion_attention and "
93 "torch.nn.LayerNorm instead.", FutureWarning)96 "torch.nn.LayerNorm instead.", FutureWarning)
94- _check_compatibility_once(hidden_states, attention_mask, query_kernel,97+ _check_compatibility_once(
95- key_kernel, value_kernel, query_bias,98+ hidden_states, attention_mask, query_kernel,
96- key_bias, value_bias, gamma, beta)99+ key_kernel, value_kernel, query_bias,
100+ key_bias, value_bias, gamma, beta)
97 101 
98 ctx.bsnc = [102 ctx.bsnc = [
99 attention_mask.shape[0],103 attention_mask.shape[0],
@@ -149,9 +153,10 @@ class _FusedAttention(torch.autograd.Function):
149 value_bias,153 value_bias,
150 scale=1,154 scale=1,
151 keep_prob=0):155 keep_prob=0):
152- _check_compatibility_once(hidden_states, attention_mask, query_kernel,156+ _check_compatibility_once(
153- key_kernel, value_kernel, query_bias,157+ hidden_states, attention_mask, query_kernel,
154- key_bias, value_bias, None, None)158+ key_kernel, value_kernel, query_bias,
159+ key_bias, value_bias, None, None)
155 160 
156 ctx.bsnc = [161 ctx.bsnc = [
157 attention_mask.shape[0],162 attention_mask.shape[0],
@@ -56,7 +56,7 @@ def npu_iou(boxes1,
56 Tensor: IoU, sized [N,M].56 Tensor: IoU, sized [N,M].
57 """57 """
58 warnings.warn("torch_npu.contrib.npu_iou is deprecated. "58 warnings.warn("torch_npu.contrib.npu_iou is deprecated. "
59- "Please use torch_npu.npu_iou or torch_npu.npu_ptiou for replacement.", FutureWarning)59+ "Please use torch_npu.npu_iou or torch_npu.npu_ptiou as a replacement.", FutureWarning)
60 60 
61 if mode not in ["iou", "ptiou"]:61 if mode not in ["iou", "ptiou"]:
62 raise ValueError("Expected mode in [iou, ptiou]" + ops_error(ErrCode.VALUE))62 raise ValueError("Expected mode in [iou, ptiou]" + ops_error(ErrCode.VALUE))
@@ -120,7 +120,7 @@ def npu_giou(boxes1,
120 Tensor: IoU, sized [n, 1].120 Tensor: IoU, sized [n, 1].
121 """121 """
122 warnings.warn("torch_npu.contrib.npu_giou is deprecated. "122 warnings.warn("torch_npu.contrib.npu_giou is deprecated. "
123- "Please use torch_npu.npu_giou for replacement.", FutureWarning)123+ "Please use torch_npu.npu_giou as a replacement.", FutureWarning)
124 124 
125 if boxes1.shape != boxes2.shape:125 if boxes1.shape != boxes2.shape:
126 raise ValueError("Expected boxes1.shape == boxes2.shape" + ops_error(ErrCode.VALUE))126 raise ValueError("Expected boxes1.shape == boxes2.shape" + ops_error(ErrCode.VALUE))
@@ -137,30 +137,30 @@ def npu_giou(boxes1,
137 return out137 return out
138 138 
139 139 
140-def npu_diou(boxes1, 140+def npu_diou(boxes1,
141- boxes2, 141+ boxes2,
142- trans=True, 142+ trans=True,
143- is_cross=False, 143+ is_cross=False,
144 mode=0144 mode=0
145 ):145 ):
146 """ Applies an NPU based DIOU operation.146 """ Applies an NPU based DIOU operation.
147 147 
148- Taking into account the distance between the targets, 148+ Taking into account the distance between the targets,
149 the overlap rate of the distance and the range, different targets or boundaries will tend to be stable.149 the overlap rate of the distance and the range, different targets or boundaries will tend to be stable.
150 150 
151 Compute Function:151 Compute Function:
152 iou = overlap_area / union_area152 iou = overlap_area / union_area
153 diou = iou - p * p(b,bgt) / c * c153 diou = iou - p * p(b,bgt) / c * c
154- 154+ 
155- Among them, b and bgt represent the center points of the predicted frame and the real frame, respectively, 155+ Among them, b and bgt represent the center points of the predicted frame and the real frame, respectively,
156- and ρ represents the Euclidean distance between the two center points. c represents the diagonal distance 156+ and ρ represents the Euclidean distance between the two center points. c represents the diagonal distance
157 of the smallest closure region that can contain both the predicted box and the ground-truth box.157 of the smallest closure region that can contain both the predicted box and the ground-truth box.
158 158 
159 .. note::159 .. note::
160 160 
161- Util now, diou backward only support trans==True, is_cross==False, mode==0('iou') current version if you 161+ Util now, diou backward only support trans==True, is_cross==False, mode==0('iou') current version if you
162 need to back propagation, please ensure your parameter is correct!162 need to back propagation, please ensure your parameter is correct!
163- 163+ 
164 Examples::164 Examples::
165 >>> box1 = torch.randn(4, 32)165 >>> box1 = torch.randn(4, 32)
166 >>> box1.requires_grad = True166 >>> box1.requires_grad = True
@@ -181,17 +181,17 @@ def npu_diou(boxes1,
181 Tensor: IoU, sized [1, n].181 Tensor: IoU, sized [1, n].
182 """182 """
183 warnings.warn("torch_npu.contrib.function.npu_diou is deprecated. "183 warnings.warn("torch_npu.contrib.function.npu_diou is deprecated. "
184- "Please use torch_npu.npu_diou for replacement.", FutureWarning)184+ "Please use torch_npu.npu_diou as a replacement.", FutureWarning)
185 185 
186 out = torch_npu.npu_diou(boxes1, boxes2, trans, is_cross, mode)186 out = torch_npu.npu_diou(boxes1, boxes2, trans, is_cross, mode)
187 187 
188 return out188 return out
189 189 
190 190 
191-def npu_ciou(boxes1, 191+def npu_ciou(boxes1,
192 boxes2,192 boxes2,
193- trans=True, 193+ trans=True,
194- is_cross=False, 194+ is_cross=False,
195 mode=0195 mode=0
196 ):196 ):
197 """ Applies an NPU based CIOU operation.197 """ Applies an NPU based CIOU operation.
@@ -202,16 +202,16 @@ def npu_ciou(boxes1,
202 iou = overlap_area / union_area202 iou = overlap_area / union_area
203 ciou = 1 - iou + p * p(b,bgt) / c * c + αv203 ciou = 1 - iou + p * p(b,bgt) / c * c + αv
204 204 
205- Among them, b and bgt represent the center points of the predicted frame and the real frame, respectively, 205+ Among them, b and bgt represent the center points of the predicted frame and the real frame, respectively,
206- and ρ represents the Euclidean distance between the two center points. c represents the diagonal distance 206+ and ρ represents the Euclidean distance between the two center points. c represents the diagonal distance
207- of the smallest closure region that can contain both the predicted box and the ground-truth box. α is the 207+ of the smallest closure region that can contain both the predicted box and the ground-truth box. α is the
208 weight function, v is used to measure the similarity of the aspect ratio.208 weight function, v is used to measure the similarity of the aspect ratio.
209- 209+ 
210 .. note::210 .. note::
211 211 
212- Util now, ciou backward only support trans==True, is_cross==False, mode==0('iou') current version if you 212+ Util now, ciou backward only support trans==True, is_cross==False, mode==0('iou') current version if you
213 need to back propagation, please ensure your parameter is correct!213 need to back propagation, please ensure your parameter is correct!
214- 214+ 
215 Examples::215 Examples::
216 >>> box1 = torch.randn(4, 32)216 >>> box1 = torch.randn(4, 32)
217 >>> box1.requires_grad = True217 >>> box1.requires_grad = True
@@ -234,7 +234,7 @@ def npu_ciou(boxes1,
234 234 
235 """235 """
236 warnings.warn("torch_npu.contrib.function.npu_ciou is deprecated. "236 warnings.warn("torch_npu.contrib.function.npu_ciou is deprecated. "
237- "Please use torch_npu.npu_ciou for replacement.", FutureWarning)237+ "Please use torch_npu.npu_ciou as a replacement.", FutureWarning)
238 238 
239 out = torch_npu.npu_ciou(boxes1, boxes2, trans, is_cross, mode, True)239 out = torch_npu.npu_ciou(boxes1, boxes2, trans, is_cross, mode, True)
240 240 
@@ -1,6 +1,5 @@
1import warnings1import warnings
2 2 
3-import torch
4import torch.nn as nn3import torch.nn as nn
5import torch_npu4import torch_npu
6 5 
@@ -25,9 +24,9 @@ class Mish(nn.Module):
25 >>> output = m(input_tensor)24 >>> output = m(input_tensor)
26 """25 """
27 super(Mish, self).__init__()26 super(Mish, self).__init__()
28- 27+ 
29 warnings.warn("torch_npu.contrib.module.Mish is deprecated. "28 warnings.warn("torch_npu.contrib.module.Mish is deprecated. "
30- "Please use torch.nn.Mish for replacement.", FutureWarning)29+ "Please use torch.nn.Mish as a replacement.", FutureWarning)
31 30 
32 def forward(self, x):31 def forward(self, x):
33 x = torch_npu.npu_mish(x)32 x = torch_npu.npu_mish(x)
@@ -48,9 +47,9 @@ class SiLU(nn.Module):
48 >>> output = m(input_tensor)47 >>> output = m(input_tensor)
49 """48 """
50 super(SiLU, self).__init__()49 super(SiLU, self).__init__()
51- 50+ 
52 warnings.warn("torch_npu.contrib.module.SiLU is deprecated. "51 warnings.warn("torch_npu.contrib.module.SiLU is deprecated. "
53- "Please use torch.nn.SiLU for replacement.", FutureWarning)52+ "Please use torch.nn.SiLU as a replacement.", FutureWarning)
54 53 
55 def forward(self, x):54 def forward(self, x):
56 x = torch_npu.npu_silu(x)55 x = torch_npu.npu_silu(x)
@@ -1,7 +1,6 @@
1import warnings1import warnings
2 2 
3import torch3import torch
4-import torch_npu
5 4 
6warnings.filterwarnings(action='once', category=FutureWarning)5warnings.filterwarnings(action='once', category=FutureWarning)
7 6 
@@ -64,7 +63,7 @@ class BiLSTM(torch.nn.Module):
64 super(BiLSTM, self).__init__()63 super(BiLSTM, self).__init__()
65 64 
66 warnings.warn("torch_npu.contrib.BiLSTM is deprecated. "65 warnings.warn("torch_npu.contrib.BiLSTM is deprecated. "
67- "Please check document for replacement.", FutureWarning)66+ "Please check the documentation for a replacement.", FutureWarning)
68 self.fw_rnn = torch.nn.LSTM(input_size, hidden_size, bidirectional=False)67 self.fw_rnn = torch.nn.LSTM(input_size, hidden_size, bidirectional=False)
69 self.bw_rnn = torch.nn.LSTM(input_size, hidden_size, bidirectional=False)68 self.bw_rnn = torch.nn.LSTM(input_size, hidden_size, bidirectional=False)
70 69 
@@ -76,4 +75,4 @@ class BiLSTM(torch.nn.Module):
76 recurrent_bw = torch.flip(recurrent_bw, [0])75 recurrent_bw = torch.flip(recurrent_bw, [0])
77 recurrent = torch.cat((recurrent_fw, recurrent_bw), 2)76 recurrent = torch.cat((recurrent_fw, recurrent_bw), 2)
78 77 
79- return recurrent78+ return recurrent
@@ -124,7 +124,7 @@ class FusedColorJitter(torch.nn.Module):
124 def __init__(self, brightness=0, contrast=0, saturation=0, hue=0):124 def __init__(self, brightness=0, contrast=0, saturation=0, hue=0):
125 super().__init__()125 super().__init__()
126 warnings.warn("torch_npu.contrib.module.FusedColorJitter is deprecated. "126 warnings.warn("torch_npu.contrib.module.FusedColorJitter is deprecated. "
127- "Please use torchvision.transforms.ColorJitter for replacement.", FutureWarning)127+ "Please use torchvision.transforms.ColorJitter as a replacement.", FutureWarning)
128 self.brightness = self._check_input(brightness, 'brightness')128 self.brightness = self._check_input(brightness, 'brightness')
129 self.contrast = self._check_input(contrast, 'contrast')129 self.contrast = self._check_input(contrast, 'contrast')
130 self.saturation = self._check_input(saturation, 'saturation')130 self.saturation = self._check_input(saturation, 'saturation')
@@ -62,7 +62,7 @@ class LinearA8W8Quant(nn.Module):
62 pertoken_scale: bool = False, device=None, dtype=None, output_dtype=None) -> None:62 pertoken_scale: bool = False, device=None, dtype=None, output_dtype=None) -> None:
63 63 
64 super(LinearA8W8Quant, self).__init__()64 super(LinearA8W8Quant, self).__init__()
65- warnings.warn("torch_npu.contrib.module.LinearA8W8Quant is deprecated and will be removed in future version. "65+ warnings.warn("torch_npu.contrib.module.LinearA8W8Quant is deprecated and will be removed in a future version. "
66 "Use torch_npu.contrib.module.LinearQuant instead.", FutureWarning)66 "Use torch_npu.contrib.module.LinearQuant instead.", FutureWarning)
67 self.in_features = in_features67 self.in_features = in_features
68 self.out_features = out_features68 self.out_features = out_features
@@ -90,8 +90,10 @@ class LinearA8W8Quant(nn.Module):
90 second_last_dim = self.weight.dim() - 290 second_last_dim = self.weight.dim() - 2
91 if not ((linear_quant_input.dtype == torch.int32 and self.weight.dtype == torch.int32) or91 if not ((linear_quant_input.dtype == torch.int32 and self.weight.dtype == torch.int32) or
92 (linear_quant_input.dtype == torch.int8 and self.weight.dtype == torch.int8)):92 (linear_quant_input.dtype == torch.int8 and self.weight.dtype == torch.int8)):
93- raise ValueError("input and weight should be both torch.int32 or both torch.int8 datatype, "93+ raise ValueError(
94- f"but now input is {linear_quant_input.dtype}, weight is {self.weight.dtype}." + ops_error(ErrCode.TYPE))94+ "input and weight should be both torch.int32 or both torch.int8 datatype, "
95+ f"but now input is {linear_quant_input.dtype}, weight is {self.weight.dtype}."
96+ + ops_error(ErrCode.TYPE))
95 if self.scale.dtype not in [torch.int64, torch.float32, torch.bfloat16]:97 if self.scale.dtype not in [torch.int64, torch.float32, torch.bfloat16]:
96 raise ValueError("scale should be torch.int64, torch.float32 or torch.bfloat16 datatype, "98 raise ValueError("scale should be torch.int64, torch.float32 or torch.bfloat16 datatype, "
97 f"but now it is {self.scale.dtype}." + ops_error(ErrCode.TYPE))99 f"but now it is {self.scale.dtype}." + ops_error(ErrCode.TYPE))
@@ -112,5 +114,7 @@ class LinearA8W8Quant(nn.Module):
112 if self.pertoken_scale is None and is_check_dtype_ok:114 if self.pertoken_scale is None and is_check_dtype_ok:
113 scale_quant = torch_npu.npu_trans_quant_param(self.scale, self.offset)115 scale_quant = torch_npu.npu_trans_quant_param(self.scale, self.offset)
114 116 
115- return torch_npu.npu_quant_matmul(linear_quant_input, self.weight.transpose(second_last_dim, first_last_dim),117+ return torch_npu.npu_quant_matmul(
116- scale_quant, offset=self.offset, pertoken_scale=self.pertoken_scale, bias=self.bias, output_dtype=self.output_dtype)118+ linear_quant_input, self.weight.transpose(second_last_dim, first_last_dim),
119+ scale_quant, offset=self.offset, pertoken_scale=self.pertoken_scale,
120+ bias=self.bias, output_dtype=self.output_dtype)
@@ -274,9 +274,9 @@ def _wrapper_profiler(fn):
274 if 'experimental_config' in kwargs.keys() and \274 if 'experimental_config' in kwargs.keys() and \
275 type(kwargs.get('experimental_config')) is not torch_npu.profiler._ExperimentalConfig:275 type(kwargs.get('experimental_config')) is not torch_npu.profiler._ExperimentalConfig:
276 logger.warning(276 logger.warning(
277- 'The parameter experimental_config of torch.profiler.profile has been deleted by the tool '277+ 'The parameter experimental_config of torch.profiler.profile has been removed by the tool '
278- 'because it can only be used in cuda, please manually modify the code '278+ 'because it can only be used with CUDA. Please manually modify the code '
279- 'and use the experimental_config parameter adapted to npu.')279+ 'to use an experimental_config parameter that supports NPU.')
280 del kwargs['experimental_config']280 del kwargs['experimental_config']
281 return fn(*args, **kwargs)281 return fn(*args, **kwargs)
282 282 
@@ -293,7 +293,7 @@ def _jit_script(obj, *args, **kwargs):
293 if not _warned_jit_fallback:293 if not _warned_jit_fallback:
294 _warned_jit_fallback = True 294 _warned_jit_fallback = True
295 warnings.warn(295 warnings.warn(
296- "using torch.jit.script successfully",296+ "torch.jit.script is in use.",
297 RuntimeWarning,297 RuntimeWarning,
298 )298 )
299 return _real_jit_script(obj, *args, **kwargs)299 return _real_jit_script(obj, *args, **kwargs)
@@ -308,7 +308,8 @@ def _jit_script_method(fn):
308 308 
309def _patch_jit_script():309def _patch_jit_script():
310 msg = ('torch.jit.script and torch.jit.script_method will be disabled by transfer_to_npu, '310 msg = ('torch.jit.script and torch.jit.script_method will be disabled by transfer_to_npu, '
311- 'which currently does not support them, if you need to enable them, please do not use transfer_to_npu.')311+ 'which currently does not support them. If you need to enable them, '
312+ 'please do not use transfer_to_npu.')
312 warnings.warn(msg, RuntimeWarning)313 warnings.warn(msg, RuntimeWarning)
313 torch.jit.script = _jit_script314 torch.jit.script = _jit_script
314 torch.jit.script_method = _jit_script_method315 torch.jit.script_method = _jit_script_method
@@ -654,7 +654,7 @@ def set_deterministic_level(level):
654 warnings.warn(654 warnings.warn(
655 "The current configuration value of 'torch_npu.npu.set_deterministic_level' "655 "The current configuration value of 'torch_npu.npu.set_deterministic_level' "
656 "conflicts with 'torch.use_deterministic_algorithms'. "656 "conflicts with 'torch.use_deterministic_algorithms'. "
657- "'torch.use_deterministic_algorithms' has been configured to 'False'"657+ "'torch.use_deterministic_algorithms' has been configured to 'False'."
658 )658 )
659 torch.use_deterministic_algorithms(False)659 torch.use_deterministic_algorithms(False)
660 deterministic_changed = True660 deterministic_changed = True
@@ -662,7 +662,7 @@ def set_deterministic_level(level):
662 warnings.warn(662 warnings.warn(
663 "The current configuration value of 'torch_npu.npu.set_deterministic_level' "663 "The current configuration value of 'torch_npu.npu.set_deterministic_level' "
664 "conflicts with 'torch.use_deterministic_algorithms'. "664 "conflicts with 'torch.use_deterministic_algorithms'. "
665- "'torch.use_deterministic_algorithms' has been configured to 'True'"665+ "'torch.use_deterministic_algorithms' has been configured to 'True'."
666 )666 )
667 torch.use_deterministic_algorithms(True)667 torch.use_deterministic_algorithms(True)
668 deterministic_changed = True668 deterministic_changed = True
@@ -12,7 +12,7 @@ def flash_sdp_enabled() -> bool:
12 .. warning:: This flag is beta and subject to change.12 .. warning:: This flag is beta and subject to change.
13 Returns whether flash scaled dot product attention is enabled or not.13 Returns whether flash scaled dot product attention is enabled or not.
14 """14 """
15- warnings.warn("Currently, the device operator does not support flash sdp and only sets Global variable!")15+ warnings.warn("Currently, the device operator does not support flash sdp and only sets the global variable!")
16 return torch._C._get_flash_sdp_enabled()16 return torch._C._get_flash_sdp_enabled()
17 17 
18 18 
@@ -21,7 +21,7 @@ def enable_flash_sdp(enabled: bool):
21 .. warning:: This flag is beta and subject to change.21 .. warning:: This flag is beta and subject to change.
22 Enables or disables flash scaled dot product attention.22 Enables or disables flash scaled dot product attention.
23 """23 """
24- warnings.warn("Currently, the device operator does not support flash sdp and only sets Global variable!")24+ warnings.warn("Currently, the device operator does not support flash sdp and only sets the global variable!")
25 torch._C._set_sdp_use_flash(enabled)25 torch._C._set_sdp_use_flash(enabled)
26 26 
27 27 
@@ -69,8 +69,8 @@ def sdp_kernel(enable_flash: bool = True, enable_math: bool = True, enable_mem_e
69 attention.69 attention.
70 Upon exiting the context manager, the previous state of the flags will be restored.70 Upon exiting the context manager, the previous state of the flags will be restored.
71 """71 """
72- warnings.warn("Currently, the device operator does not support flashmathmem_efficient sdp "72+ warnings.warn("Currently, the device operator does not support flash, math, mem_efficient sdp "
73- "and only sets Global variable!")73+ "and only sets the global variable!")
74 previous_flash: bool = flash_sdp_enabled()74 previous_flash: bool = flash_sdp_enabled()
75 previous_mem_efficient: bool = mem_efficient_sdp_enabled()75 previous_mem_efficient: bool = mem_efficient_sdp_enabled()
76 previous_math: bool = math_sdp_enabled()76 previous_math: bool = math_sdp_enabled()
@@ -96,4 +96,4 @@ def preferred_linalg_library(backend: Union[None, str, torch._C._LinalgBackend]
96def get_soc_version():96def get_soc_version():
97 torch_npu.npu._lazy_init()97 torch_npu.npu._lazy_init()
98 soc_version = torch_npu._C._npu_get_soc_version()98 soc_version = torch_npu._C._npu_get_soc_version()
99- return soc_version99+ return soc_version
@@ -2491,7 +2491,7 @@ class NPUGraphTreeManager:
2491 warnings.warn(2491 warnings.warn(
2492 "Unable to hit fast path of NPUGraphs because of pending, uninvoked backwards. "2492 "Unable to hit fast path of NPUGraphs because of pending, uninvoked backwards. "
2493 "Consider running with torch.no_grad() or using torch.compiler.npugraph_mark_step_begin() "2493 "Consider running with torch.no_grad() or using torch.compiler.npugraph_mark_step_begin() "
2494- "before each model invocation"2494+ "before each model invocation."
2495 )2495 )
2496 2496 
2497 @staticmethod2497 @staticmethod
@@ -98,7 +98,7 @@ class GradScaler(BaseGradScaler):
98 dynamic=True,98 dynamic=True,
99 enabled=True):99 enabled=True):
100 if enabled and amp_definitely_not_available():100 if enabled and amp_definitely_not_available():
101- warnings.warn("torch_npu.amp.GradScaler is enabled, but NPU is not available. Disabling.")101+ warnings.warn("torch_npu.amp.GradScaler is enabled, but NPU is not available. Disabling.")
102 self._enabled = False102 self._enabled = False
103 else:103 else:
104 self._enabled = enabled104 self._enabled = enabled
@@ -193,7 +193,7 @@ class GradScaler(BaseGradScaler):
193 return val * stash[0].get(val.device)193 return val * stash[0].get(val.device)
194 elif isinstance(val, container_abcs.Iterable):194 elif isinstance(val, container_abcs.Iterable):
195 iterable = map(apply_scale, val)195 iterable = map(apply_scale, val)
196- if isinstance(val, list) or isinstance(val, tuple):196+ if isinstance(val, (list, tuple)):
197 return type(val)(iterable)197 return type(val)(iterable)
198 else:198 else:
199 return iterable199 return iterable
@@ -39,10 +39,10 @@ class mstx:
39 @_no_exception_func()39 @_no_exception_func()
40 def mark(message: str, stream=None, domain: str = 'default'):40 def mark(message: str, stream=None, domain: str = 'default'):
41 if not message or not isinstance(message, str):41 if not message or not isinstance(message, str):
42- warnings.warn("Invalid message for mstx.mark func. Please input valid message string.")42+ warnings.warn("Invalid message for mstx.mark function. Please provide a valid message string.")
43 return43 return
44 if not isinstance(domain, str):44 if not isinstance(domain, str):
45- warnings.warn("Invalid domain for mstx.mark func. Please input valid domain string.")45+ warnings.warn("Invalid domain for mstx.mark function. Please provide a valid domain string.")
46 return46 return
47 if stream:47 if stream:
48 if isinstance(stream, torch_npu.npu.streams.Stream):48 if isinstance(stream, torch_npu.npu.streams.Stream):
@@ -52,7 +52,7 @@ class mstx:
52 stream.device_type,52 stream.device_type,
53 domain)53 domain)
54 else:54 else:
55- warnings.warn("Invalid stream for mstx.mark func. Please input valid stream.")55+ warnings.warn("Invalid stream for mstx.mark function. Please provide a valid stream.")
56 return56 return
57 else:57 else:
58 torch_npu._C._mstx._mark_on_host(message, domain)58 torch_npu._C._mstx._mark_on_host(message, domain)
@@ -91,7 +91,7 @@ class mstx:
91 @_no_exception_func()91 @_no_exception_func()
92 def range_start(message: str, stream=None, domain: str = 'default') -> int:92 def range_start(message: str, stream=None, domain: str = 'default') -> int:
93 if not message or not isinstance(message, str):93 if not message or not isinstance(message, str):
94- warnings.warn("Invalid message for mstx.range_start func. Please input valid message string.")94+ warnings.warn("Invalid message for mstx.range_start function. Please provide a valid message string.")
95 return 095 return 0
96 if not domain or not isinstance(domain, str):96 if not domain or not isinstance(domain, str):
97 warnings.warn("Invalid domain for mstx.range_start func. Please input valid domain string.")97 warnings.warn("Invalid domain for mstx.range_start func. Please input valid domain string.")
@@ -113,7 +113,7 @@ class mstx:
113 @_no_exception_func()113 @_no_exception_func()
114 def range_end(range_id: int, domain: str = 'default'):114 def range_end(range_id: int, domain: str = 'default'):
115 if not isinstance(range_id, int):115 if not isinstance(range_id, int):
116- warnings.warn("Invalid message for mstx.range_end func. Please input return value from mstx.range_start.")116+ warnings.warn("Invalid message for mstx.range_end function. Please provide the return value from mstx.range_start.")
117 return117 return
118 if not domain or not isinstance(domain, str):118 if not domain or not isinstance(domain, str):
119 warnings.warn("Invalid domain for mstx.range_end func. Please input valid domain string.")119 warnings.warn("Invalid domain for mstx.range_end func. Please input valid domain string.")
@@ -164,4 +164,4 @@ class annotate:
164 164 
165 return inner165 return inner
166 166 
167-mstx.annotate = annotate167+mstx.annotate = annotate
@@ -8,16 +8,14 @@ __all__ = ["set_option", "set_aoe",
8 "set_device_limit", "get_device_limit", "set_stream_limit",8 "set_device_limit", "get_device_limit", "set_stream_limit",
9 "reset_stream_limit", "get_stream_limit"]9 "reset_stream_limit", "get_stream_limit"]
10 10 
11-from logging import exception11+from enum import IntEnum
12-from enum import IntEnum, unique
13import inspect12import inspect
14import os13import os
15import warnings14import warnings
16import torch_npu15import torch_npu
17import torch_npu._C16import torch_npu._C
18from torch_npu.utils._path_manager import PathManager17from torch_npu.utils._path_manager import PathManager
19-from torch_npu.utils._error_code import ErrCode, pta_error, prof_error18+from torch_npu.utils._error_code import ErrCode, pta_error
20-from .utils import _get_device_index
21 19 
22_option_map = {"ACL_PRECISION_MODE": ["allow_fp32_to_fp16", "must_keep_origin_dtype"],20_option_map = {"ACL_PRECISION_MODE": ["allow_fp32_to_fp16", "must_keep_origin_dtype"],
23 "ACL_OP_SELECT_IMPL_MODE": ["high_performance", "high_precision"],21 "ACL_OP_SELECT_IMPL_MODE": ["high_performance", "high_precision"],
@@ -37,7 +35,7 @@ class _CubeMathType(IntEnum):
37 ALLOW_FP32_DOWN_PRECISION = 135 ALLOW_FP32_DOWN_PRECISION = 1
38 USE_FP16 = 236 USE_FP16 = 2
39 USE_HF32 = 337 USE_HF32 = 3
40- FORCE_GRP_ACC_FOR_FP32 = 4 # deprecate, but use as a transition for now38+ FORCE_GRP_ACC_FOR_FP32 = 4 # deprecate, but use as a transition for now
41 USE_FP32_ADD = 439 USE_FP32_ADD = 4
42 40 
43 41 
@@ -73,8 +71,8 @@ def set_option(option):
73 pta_error(ErrCode.PARAM))71 pta_error(ErrCode.PARAM))
74 72 
75 if option_name in _deprecated_option_set:73 if option_name in _deprecated_option_set:
76- warnings.warn(f"{option_name} will be deprecated in future version. The accuracy or performance "74+ warnings.warn(f"{option_name} will be deprecated in a future version. The accuracy or performance "
77- f"may not be the optimal when configuring this option. We do not recommend setting it.")75+ f"may not be optimal when configuring this option. We do not recommend setting it.")
78 76 
79 torch_npu._C._npu_setOption(option)77 torch_npu._C._npu_setOption(option)
80 78 
@@ -120,7 +118,7 @@ def set_aoe(dump_path):
120This global flag control mm and bmm use ND format to compute, if the flag is True,118This global flag control mm and bmm use ND format to compute, if the flag is True,
121we use ND format for mm and bmm in Linear module119we use ND format for mm and bmm in Linear module
122 120 
123-useage:121+usage:
124```122```
125option = {}123option = {}
126option["MM_BMM_ND_ENABLE"] = "enable"124option["MM_BMM_ND_ENABLE"] = "enable"
@@ -170,8 +168,9 @@ class _allowHF32Matmul:
170 option = {"ALLOW_MATMUL_HF32": "enable" if value else "disable"}168 option = {"ALLOW_MATMUL_HF32": "enable" if value else "disable"}
171 torch_npu._C._npu_setOption(option)169 torch_npu._C._npu_setOption(option)
172 elif name == "cube_math_type":170 elif name == "cube_math_type":
173- if(not isinstance(value, _CubeMathType)):171+ if not isinstance(value, _CubeMathType):
174- raise TypeError(f"value should be one of Enum CubeMathType when setting cube_math_type, but got {type(value)}")172+ raise TypeError(
173+ f"value should be one of Enum CubeMathType when setting cube_math_type, but got {type(value)}")
175 torch_npu._C._npu_setOption({"CUBE_MATH_TYPE": str(value.value)})174 torch_npu._C._npu_setOption({"CUBE_MATH_TYPE": str(value.value)})
176 175 
177 @classmethod176 @classmethod
@@ -216,7 +215,8 @@ class _call_once_class:
216 215 
217 def __call__(self, *args, **kwargs):216 def __call__(self, *args, **kwargs):
218 if self.called:217 if self.called:
219- raise RuntimeError(f"Function '{self.func.__name__}' has already been called, You can only set this interface once.")218+ raise RuntimeError(
219+ f"Function '{self.func.__name__}' has already been called, You can only set this interface once.")
220 220 
221 self.called = True221 self.called = True
222 self.result = self.func(*args, **kwargs)222 self.result = self.func(*args, **kwargs)
@@ -252,15 +252,18 @@ def get_device_limit(device):
252 if device < 0 or device >= device_count():252 if device < 0 or device >= device_count():
253 raise AssertionError("Invalid device id" + pta_error(ErrCode.VALUE))253 raise AssertionError("Invalid device id" + pta_error(ErrCode.VALUE))
254 torch_npu.npu._lazy_init()254 torch_npu.npu._lazy_init()
255- return {"cube_core_num": torch_npu._C._npu_get_device_res_limit(device, 0), \255+ return {
256- "vector_core_num": torch_npu._C._npu_get_device_res_limit(device, 1)}256+ "cube_core_num": torch_npu._C._npu_get_device_res_limit(device, 0),
257+ "vector_core_num": torch_npu._C._npu_get_device_res_limit(device, 1),
258+ }
257 259 
258 260 
259def set_stream_limit(stream, cube_num=-1, vector_num=-1):261def set_stream_limit(stream, cube_num=-1, vector_num=-1):
260 if stream is None:262 if stream is None:
261 raise AssertionError("stream cannot be None" + pta_error(ErrCode.PARAM))263 raise AssertionError("stream cannot be None" + pta_error(ErrCode.PARAM))
262 if not isinstance(stream, torch_npu.npu.Stream):264 if not isinstance(stream, torch_npu.npu.Stream):
263- raise AssertionError(f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))265+ raise AssertionError(
266+ f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))
264 torch_npu.npu._lazy_init()267 torch_npu.npu._lazy_init()
265 if cube_num != -1:268 if cube_num != -1:
266 torch_npu._C._npu_set_stream_res_limit(stream_id=stream.stream_id,269 torch_npu._C._npu_set_stream_res_limit(stream_id=stream.stream_id,
@@ -280,7 +283,8 @@ def reset_stream_limit(stream):
280 if stream is None:283 if stream is None:
281 raise AssertionError("stream cannot be None" + pta_error(ErrCode.PARAM))284 raise AssertionError("stream cannot be None" + pta_error(ErrCode.PARAM))
282 if not isinstance(stream, torch_npu.npu.Stream):285 if not isinstance(stream, torch_npu.npu.Stream):
283- raise AssertionError(f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))286+ raise AssertionError(
287+ f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))
284 torch_npu.npu._lazy_init()288 torch_npu.npu._lazy_init()
285 torch_npu._C._npu_reset_stream_res_limit(stream_id=stream.stream_id,289 torch_npu._C._npu_reset_stream_res_limit(stream_id=stream.stream_id,
286 device_index=stream.device_index,290 device_index=stream.device_index,
@@ -294,11 +298,15 @@ def get_stream_limit(stream):
294 raise AssertionError(298 raise AssertionError(
295 f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))299 f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))
296 torch_npu.npu._lazy_init()300 torch_npu.npu._lazy_init()
297- return {"cube_core_num": torch_npu._C._npu_get_stream_res_limit(stream_id=stream.stream_id,301+ return {
298- device_index=stream.device_index,302+ "cube_core_num": torch_npu._C._npu_get_stream_res_limit(
299- device_type=stream.device_type,303+ stream_id=stream.stream_id,
300- type=0), \304+ device_index=stream.device_index,
301- "vector_core_num": torch_npu._C._npu_get_stream_res_limit(stream_id=stream.stream_id,305+ device_type=stream.device_type,
302- device_index=stream.device_index,306+ type=0),
303- device_type=stream.device_type,307+ "vector_core_num": torch_npu._C._npu_get_stream_res_limit(
304- type=1)}308+ stream_id=stream.stream_id,
309+ device_index=stream.device_index,
310+ device_type=stream.device_type,
311+ type=1),
312+ }
@@ -1,17 +1,13 @@
1import os1import os
2from typing import Any, Optional2from typing import Any, Optional
3import warnings3import warnings
4-import contextlib
5-from enum import Enum
6- 
7import torch4import torch
8from torch._utils import _get_device_index as _torch_get_device_index5from torch._utils import _get_device_index as _torch_get_device_index
9 6 
10import torch_npu7import torch_npu
11import torch_npu._C8import torch_npu._C
12from torch_npu.utils._error_code import ErrCode, pta_error9from torch_npu.utils._error_code import ErrCode, pta_error
13-from torch_npu.npu._backends import get_soc_version10+from torch_npu.npu._backends import get_soc_version # noqa: F401
14- 
15 11 
16__all__ = ["obfuscation_initialize", "obfuscation_finalize", "obfuscation_calculate",12__all__ = ["obfuscation_initialize", "obfuscation_finalize", "obfuscation_calculate",
17 "synchronize", "set_device", "current_device", "device", "device_of", "StreamContext",13 "synchronize", "set_device", "current_device", "device", "device_of", "StreamContext",
@@ -21,9 +17,13 @@ __all__ = ["obfuscation_initialize", "obfuscation_finalize", "obfuscation_calcul
21 "check_uce_in_memory", "stress_detect", "get_cann_version", "ipc_collect", "set_op_timeout_ms"]17 "check_uce_in_memory", "stress_detect", "get_cann_version", "ipc_collect", "set_op_timeout_ms"]
22 18 
23 19 
24-def obfuscation_initialize(hidden_size, tp_rank, cmd, *, data_type=None, model_obf_seed_id=0, data_obf_seed_id=0, thread_num=4, obf_coefficient=1.0):20+def obfuscation_initialize(
25- return torch_npu.obfuscation_initialize(hidden_size, tp_rank, cmd, data_type=data_type, model_obf_seed_id=model_obf_seed_id,21+ hidden_size, tp_rank, cmd, *,
26- data_obf_seed_id=data_obf_seed_id, thread_num=thread_num, obf_coefficient=obf_coefficient)22+ data_type=None, model_obf_seed_id=0, data_obf_seed_id=0, thread_num=4, obf_coefficient=1.0):
23+ return torch_npu.obfuscation_initialize(
24+ hidden_size, tp_rank, cmd,
25+ data_type=data_type, model_obf_seed_id=model_obf_seed_id,
26+ data_obf_seed_id=data_obf_seed_id, thread_num=thread_num, obf_coefficient=obf_coefficient)
27 27 
28 28 
29def obfuscation_finalize(fd_to_close):29def obfuscation_finalize(fd_to_close):
@@ -37,7 +37,8 @@ def obfuscation_calculate(fd, x, param, *, obf_coefficient=1.0):
37def get_cann_version(module="CANN"):37def get_cann_version(module="CANN"):
38 r"""38 r"""
39 Args:39 Args:
40- module: can be selected from [\"CANN\", \"RUNTIME\", \"COMPILER\", \"HCCL\", \"TOOLKIT\", \"OPP\", \"OPP_KERNEL\", \"DRIVER\"]40+ module: can be selected from [
41+ \"CANN\", \"RUNTIME\", \"COMPILER\", \"HCCL\", \"TOOLKIT\", \"OPP\", \"OPP_KERNEL\", \"DRIVER\"]
41 42 
42 Returns: current version.43 Returns: current version.
43 44 
@@ -395,7 +396,7 @@ def npu_check_overflow(grad):
395 396 
396def clear_npu_overflow_flag():397def clear_npu_overflow_flag():
397 if is_support_inf_nan():398 if is_support_inf_nan():
398- warnings.warn("When soc_version >= Ascend910B1, clear_npu_overflow_flag is useless, please remove it.")399+ warnings.warn("When soc_version >= Ascend910B1, clear_npu_overflow_flag is useless. Please remove it.")
399 return400 return
400 float_status = torch.zeros(8).npu()401 float_status = torch.zeros(8).npu()
401 torch_npu.npu_clear_float_status(float_status)402 torch_npu.npu_clear_float_status(float_status)
@@ -406,21 +407,23 @@ hccl_detect_group = None
406 407 
407def stress_detect(detect_type='aic'):408def stress_detect(detect_type='aic'):
408 if detect_type not in ['aic', 'hccs']:409 if detect_type not in ['aic', 'hccs']:
409- warnings.warn("Detecct_type should be `aic` or `hccs`. For details, aic as `Online aicore detect`, hccs as `Online p2p detect`.")410+ warnings.warn(
411+ "Detect_type should be `aic` or `hccs`. "
412+ "For details, `aic` is for `Online aicore detect`, and `hccs` is for `Online p2p detect`.")
410 return 1413 return 1
411 torch_npu.npu._lazy_init()414 torch_npu.npu._lazy_init()
412 mode = 0 if detect_type == 'aic' else 1415 mode = 0 if detect_type == 'aic' else 1
413 comm = 0416 comm = 0
414 if mode == 1:417 if mode == 1:
415 if not torch.distributed.is_initialized():418 if not torch.distributed.is_initialized():
416- warnings.warn("The torch.distributed should to be initialized for p2p detection.")419+ warnings.warn("torch.distributed should be initialized for p2p detection.")
417 return 1420 return 1
418 global hccl_detect_group421 global hccl_detect_group
419 rank = int(os.getenv('RANK', -1))422 rank = int(os.getenv('RANK', -1))
420 local_world_size = int(os.getenv('LOCAL_WORLD_SIZE', -1))423 local_world_size = int(os.getenv('LOCAL_WORLD_SIZE', -1))
421 world_size = int(os.getenv('WORLD_SIZE', -1))424 world_size = int(os.getenv('WORLD_SIZE', -1))
422 if rank == -1 or local_world_size == -1 or world_size == -1:425 if rank == -1 or local_world_size == -1 or world_size == -1:
423- warnings.warn("Environment variable 'RANK', 'LOCAL_WORLD_SIZE' or 'WORLD_SIZE' is not set.")426+ warnings.warn("Environment variables 'RANK', 'LOCAL_WORLD_SIZE' or 'WORLD_SIZE' are not set.")
424 return 1427 return 1
425 num_workers = world_size // local_world_size428 num_workers = world_size // local_world_size
426 worker_index = rank // local_world_size429 worker_index = rank // local_world_size
@@ -437,7 +440,7 @@ def stress_detect(detect_type='aic'):
437 try:440 try:
438 comm = hccl_detect_group._get_backend(torch.device('npu')).get_hccl_comm(local_rank)441 comm = hccl_detect_group._get_backend(torch.device('npu')).get_hccl_comm(local_rank)
439 except Exception as err:442 except Exception as err:
440- warnings.warn("Create local hccl group for p2p detection failed.")443+ warnings.warn("Failed to create local hccl group for p2p detection.")
441 return 1444 return 1
442 return torch_npu._C._npu_stress_detect(mode, comm)445 return torch_npu._C._npu_stress_detect(mode, comm)
443 446 
@@ -484,15 +487,17 @@ def _erase_stream(tensor, stream):
484 raise TypeError(f"tensor should be torch.Tensor, could not be {type(tensor)}" + pta_error(ErrCode.TYPE))487 raise TypeError(f"tensor should be torch.Tensor, could not be {type(tensor)}" + pta_error(ErrCode.TYPE))
485 if not isinstance(stream, torch_npu.npu.Stream):488 if not isinstance(stream, torch_npu.npu.Stream):
486 raise TypeError(f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))489 raise TypeError(f"stream should be torch_npu.npu.Stream, could not be {type(stream)}" + pta_error(ErrCode.TYPE))
487- torch_npu._C._npu_eraseStream(tensor=tensor,490+ torch_npu._C._npu_eraseStream(
488- stream_id=stream.stream_id,491+ tensor=tensor,
489- device_index=stream.device_index,492+ stream_id=stream.stream_id,
490- device_type=stream.device_type)493+ device_index=stream.device_index,
494+ device_type=stream.device_type)
491 495 
492 496 
493def _set_op_timeout_ms_impl(timeout):497def _set_op_timeout_ms_impl(timeout):
494- torch_npu.npu._lazy_init()498+ torch_npu.npu._lazy_init()
495- torch_npu._C._npu_set_op_timeout_ms(timeout)499+ torch_npu._C._npu_set_op_timeout_ms(timeout)
500+ 
496 501 
497_npu_lib = torch.library.Library("npu", "FRAGMENT")502_npu_lib = torch.library.Library("npu", "FRAGMENT")
498if not hasattr(torch.ops.npu, "set_op_timeout_ms"):503if not hasattr(torch.ops.npu, "set_op_timeout_ms"):
@@ -503,9 +508,11 @@ if not hasattr(torch.ops.npu, "set_op_timeout_ms"):
503 508 
504 torch.fx.node.has_side_effect(torch.ops.npu.set_op_timeout_ms.default)509 torch.fx.node.has_side_effect(torch.ops.npu.set_op_timeout_ms.default)
505 510 
511+ 
506 @torch.library.register_fake("npu::set_op_timeout_ms")512 @torch.library.register_fake("npu::set_op_timeout_ms")
507 def _set_op_timeout_ms_meta(timeout):513 def _set_op_timeout_ms_meta(timeout):
508 pass514 pass
509 515 
516+ 
510def set_op_timeout_ms(timeout):517def set_op_timeout_ms(timeout):
511- torch.ops.npu.set_op_timeout_ms(timeout)518+ torch.ops.npu.set_op_timeout_ms(timeout)
@@ -2,7 +2,7 @@ import os
2import re2import re
3import warnings3import warnings
4 4 
5-from torch_npu.utils._error_code import ErrCode, prof_error5+from torch_npu.utils._error_code import ErrCode
6 6 
7from ._constant import Constant7from ._constant import Constant
8 8 
@@ -183,7 +183,7 @@ class ProfilerPathManager:
183 )183 )
184 path = os.path.expanduser(path)184 path = os.path.expanduser(path)
185 if os.path.islink(path):185 if os.path.islink(path):
186- msg = f"Invalid input path is a soft chain: {path}"186+ msg = f"Invalid input path is a symbolic link: {path}"
187 warnings.warn(msg)187 warnings.warn(msg)
188 return os.path.realpath(path)188 return os.path.realpath(path)
189 189 
@@ -14,7 +14,6 @@ from ..prof_common_func._file_manager import FileManager
14from ..prof_common_func._log import ProfilerLogger14from ..prof_common_func._log import ProfilerLogger
15from ..prof_common_func._path_manager import ProfilerPathManager15from ..prof_common_func._path_manager import ProfilerPathManager
16 16 
17- 
18__all__ = []17__all__ = []
19 18 
20 19 
@@ -146,13 +145,13 @@ class CANNFileParser:
146 raise RuntimeError("CANN Profiling data does not exist.")145 raise RuntimeError("CANN Profiling data does not exist.")
147 if not FileManager.check_file_readable(self._cann_path):146 if not FileManager.check_file_readable(self._cann_path):
148 self.logger.warning(147 self.logger.warning(
149- f"Path '{self._cann_path}' owner is not readable. "148+ "The path '%s' is not readable. Please run: chmod -R 755 '%s'.",
150- f"Please execute 'chmod -R 755 '{self._cann_path}' '."149+ self._cann_path, self._cann_path
151 )150 )
152 if not FileManager.check_file_writable(self._cann_path):151 if not FileManager.check_file_writable(self._cann_path):
153 self.logger.warning(152 self.logger.warning(
154- f"Path '{self._cann_path}' owner is not writable. "153+ "The path '%s' is not writable. Please execute 'chmod -R 755 '%s' '.",
155- f"Please execute 'chmod -R 755 '{self._cann_path}' '."154+ self._cann_path, self._cann_path
156 )155 )
157 156 
158 @classmethod157 @classmethod
@@ -207,10 +206,10 @@ class CANNFileParser:
207 event_dict[unique_id] = data206 event_dict[unique_id] = data
208 207 
209 if not flow_dict:208 if not flow_dict:
210- logger.warning("There is no HostToDevice flow events in msprof timeline.")209+ logger.warning("There are no HostToDevice flow events in the msprof timeline.")
211 210 
212 if not event_dict:211 if not event_dict:
213- logger.error("There is no kernel events in msprof timeline.")212+ logger.error("There are no kernel events in the msprof timeline.")
214 213 
215 acl_to_npu_dict = {}214 acl_to_npu_dict = {}
216 warning_kernel_num = 0215 warning_kernel_num = 0
@@ -22,7 +22,7 @@ class FwkCANNRelationParser:
22 return acl_to_npu_dict22 return acl_to_npu_dict
23 kernel_dict = {}23 kernel_dict = {}
24 index = 024 index = 0
25- acl_start_time_list = sorted(list(acl_to_npu_dict.keys()))25+ acl_start_time_list = sorted(acl_to_npu_dict.keys())
26 for acl_start_time in acl_start_time_list:26 for acl_start_time in acl_start_time_list:
27 while index < len(dequeue_data_list):27 while index < len(dequeue_data_list):
28 if dequeue_data_list[index].ts > acl_start_time:28 if dequeue_data_list[index].ts > acl_start_time:
@@ -61,24 +61,24 @@ class FwkCANNRelationParser:
61 61 
62 def get_step_range(self, root_node: TorchOpNode, kernel_dict: dict):62 def get_step_range(self, root_node: TorchOpNode, kernel_dict: dict):
63 if not kernel_dict:63 if not kernel_dict:
64- self.logger.error("Get step range failed, the kernel dict is empty.")64+ self.logger.error("Failed to get the step range; the kernel dict is empty.")
65 return []65 return []
66 # Get ProfilerStep#x node66 # Get ProfilerStep#x node
67 step_node_list = [node for node in root_node.child_node_list if node.is_profiler_step()]67 step_node_list = [node for node in root_node.child_node_list if node.is_profiler_step()]
68 if not step_node_list:68 if not step_node_list:
69- self.logger.warning("Get step range failed, the step node list is empty.")69+ self.logger.warning("Failed to get the step range; the step node list is empty.")
70 return []70 return []
71 71 
72 # Gather flow events start time in each step node72 # Gather flow events start time in each step node
73 if not FwkFileParser(self._profiler_path).has_task_queue_data():73 if not FwkFileParser(self._profiler_path).has_task_queue_data():
74- acl_start_time_list = sorted(list(kernel_dict.keys()))74+ acl_start_time_list = sorted(kernel_dict.keys())
75 self._update_step_node_info(step_node_list, acl_start_time_list)75 self._update_step_node_info(step_node_list, acl_start_time_list)
76 # Get step range on device by flow events76 # Get step range on device by flow events
77 step_range = []77 step_range = []
78 for step_node in step_node_list:78 for step_node in step_node_list:
79 step_id = step_node.event.name.split("#")[-1]79 step_id = step_node.event.name.split("#")[-1]
80 if not step_node.corr_id_total:80 if not step_node.corr_id_total:
81- self.logger.error("There is no flow events in %s range.", step_node.event.name)81+ self.logger.error("There are no flow events in the %s range.", step_node.event.name)
82 continue82 continue
83 corr_id_list = sorted(step_node.corr_id_total)83 corr_id_list = sorted(step_node.corr_id_total)
84 min_index, max_index = 0, len(corr_id_list) - 184 min_index, max_index = 0, len(corr_id_list) - 1
@@ -81,9 +81,9 @@ class FwkFileParser:
81 dequeue_data_list.append(op_mark)81 dequeue_data_list.append(op_mark)
82 start_op_list.clear()82 start_op_list.clear()
83 if enqueue_match_failed_num:83 if enqueue_match_failed_num:
84- self.logger.warning(f"{enqueue_match_failed_num} enqueue data match failed.")84+ self.logger.warning("%s enqueue data failed to match.", enqueue_match_failed_num)
85 if dequeue_match_failed_num:85 if dequeue_match_failed_num:
86- self.logger.warning(f"{dequeue_match_failed_num} dequeue data match failed.")86+ self.logger.warning("%s dequeue data failed to match.", dequeue_match_failed_num)
87 return enqueue_data_list, dequeue_data_list87 return enqueue_data_list, dequeue_data_list
88 88 
89 def get_torch_op_tree_node(self, torch_op_data: list, enqueue_data: list = None) -> list:89 def get_torch_op_tree_node(self, torch_op_data: list, enqueue_data: list = None) -> list:
@@ -109,7 +109,7 @@ class FwkFileParser:
109 return []109 return []
110 tid_dict = {}110 tid_dict = {}
111 fwk_x_event_list = [None] * (111 fwk_x_event_list = [None] * (
112- len(torch_op_data) + len(enqueue_data_list) * 2 + len(dequeue_data_list) * 2)112+ len(torch_op_data) + len(enqueue_data_list) * 2 + len(dequeue_data_list) * 2)
113 index = 0113 index = 0
114 fwd_dict = defaultdict(dict)114 fwd_dict = defaultdict(dict)
115 correlation_id_name_dict = {}115 correlation_id_name_dict = {}
@@ -225,10 +225,13 @@ class FwkFileParser:
225 python_trace_apis = []225 python_trace_apis = []
226 226 
227 for dequeue_data in dequeue_data_list:227 for dequeue_data in dequeue_data_list:
228- task_dequeues.append(228+ task_dequeues.append([
229- [dequeue_data.ts, dequeue_data.ts + dequeue_data.dur, contact_2num(pid, dequeue_data.tid),229+ dequeue_data.ts, dequeue_data.ts + dequeue_data.dur, contact_2num(pid, dequeue_data.tid),
230- connection_id_manager.get_id_from_connection_ids([dequeue_data.corr_id + DbConstant.START_CONNECTION_ID_FWK_API]), str2id_manager.get_id_from_str(dequeue_data.name),230+ connection_id_manager.get_id_from_connection_ids(
231- None, None, None, None, None, ApiType.TASK_QUEUE])231+ [dequeue_data.corr_id + DbConstant.START_CONNECTION_ID_FWK_API]),
232+ str2id_manager.get_id_from_str(dequeue_data.name),
233+ None, None, None, None, None, ApiType.TASK_QUEUE,
234+ ])
232 correlation_id_name_dict[dequeue_data.corr_id] = dequeue_data.origin_name235 correlation_id_name_dict[dequeue_data.corr_id] = dequeue_data.origin_name
233 236 
234 for enqueue_data in enqueue_data_list:237 for enqueue_data in enqueue_data_list:
@@ -236,19 +239,30 @@ class FwkFileParser:
236 if enqueue_data.corr_id in correlation_id_name_dict:239 if enqueue_data.corr_id in correlation_id_name_dict:
237 # append correlation name with '@' prefix for consistent with Dequeue240 # append correlation name with '@' prefix for consistent with Dequeue
238 name += f"@{correlation_id_name_dict[enqueue_data.corr_id]}"241 name += f"@{correlation_id_name_dict[enqueue_data.corr_id]}"
239- task_enqueues.append(242+ task_enqueues.append([
240- [enqueue_data.ts, enqueue_data.ts + enqueue_data.dur, contact_2num(pid, enqueue_data.tid),243+ enqueue_data.ts, enqueue_data.ts + enqueue_data.dur, contact_2num(pid, enqueue_data.tid),
241- connection_id_manager.get_id_from_connection_ids([enqueue_data.corr_id + DbConstant.START_CONNECTION_ID_FWK_API]), str2id_manager.get_id_from_str(name),244+ connection_id_manager.get_id_from_connection_ids(
242- None, None, None, None, None, ApiType.TASK_QUEUE])245+ [enqueue_data.corr_id + DbConstant.START_CONNECTION_ID_FWK_API]),
246+ str2id_manager.get_id_from_str(name),
247+ None, None, None, None, None, ApiType.TASK_QUEUE,
248+ ])
243 connection_ids.append(enqueue_data.corr_id)249 connection_ids.append(enqueue_data.corr_id)
244 250 
245 for torch_op in torch_op_data:251 for torch_op in torch_op_data:
246- api = [torch_op.ts, torch_op.end_ns, contact_2num(pid, torch_op.tid), [], str2id_manager.get_id_from_str(torch_op.name),252+ api = [
247- torch_op.args.get(Constant.SEQUENCE_NUMBER, -1), torch_op.args.get(Constant.FORWARD_THREAD_ID),253+ torch_op.ts, torch_op.end_ns, contact_2num(pid, torch_op.tid), [],
248- None if not torch_op.args.get(Constant.INPUT_DTYPES) else str2id_manager.get_id_from_str(torch_op.args.get(Constant.INPUT_DTYPES)),254+ str2id_manager.get_id_from_str(torch_op.name),
249- None if not torch_op.args.get(Constant.INPUT_SHAPES) else str2id_manager.get_id_from_str(torch_op.args.get(Constant.INPUT_SHAPES)),255+ torch_op.args.get(Constant.SEQUENCE_NUMBER, -1),
250- None if not torch_op.args.get(Constant.CALL_STACK) else call_chain_id_manager.get_callchain_id_from_callstack(torch_op.args.get(Constant.CALL_STACK)),256+ torch_op.args.get(Constant.FORWARD_THREAD_ID),
251- ApiType.TORCH_OP]257+ (None if not torch_op.args.get(Constant.INPUT_DTYPES)
258+ else str2id_manager.get_id_from_str(torch_op.args.get(Constant.INPUT_DTYPES))),
259+ (None if not torch_op.args.get(Constant.INPUT_SHAPES)
260+ else str2id_manager.get_id_from_str(torch_op.args.get(Constant.INPUT_SHAPES))),
261+ (None if not torch_op.args.get(Constant.CALL_STACK)
262+ else call_chain_id_manager.get_callchain_id_from_callstack(
263+ torch_op.args.get(Constant.CALL_STACK))),
264+ ApiType.TORCH_OP,
265+ ]
252 if torch_op.name.startswith("mstx_"):266 if torch_op.name.startswith("mstx_"):
253 mstx_mark_apis.append(api)267 mstx_mark_apis.append(api)
254 else:268 else:
@@ -264,7 +278,8 @@ class FwkFileParser:
264 if trace_hash_data and func_call_data:278 if trace_hash_data and func_call_data:
265 python_trace_parser = PythonTraceParser(trace_hash_data, func_call_data)279 python_trace_parser = PythonTraceParser(trace_hash_data, func_call_data)
266 python_trace_apis = python_trace_parser.get_python_trace_api_data()280 python_trace_apis = python_trace_parser.get_python_trace_api_data()
267- return {Constant.TORCH_OP_DATA: torch_op_apis, Constant.ENQUEUE_DATA: task_enqueues, Constant.DEQUEUE_DATA: task_dequeues,281+ return {Constant.TORCH_OP_DATA: torch_op_apis, Constant.ENQUEUE_DATA: task_enqueues,
282+ Constant.DEQUEUE_DATA: task_dequeues,
268 Constant.PYTHON_TRACE_DATA: python_trace_apis, Constant.MSTX_OP_DATA: mstx_mark_apis}283 Constant.PYTHON_TRACE_DATA: python_trace_apis, Constant.MSTX_OP_DATA: mstx_mark_apis}
269 284 
270 def get_first_fwk_op(self, torch_op_data: list):285 def get_first_fwk_op(self, torch_op_data: list):
@@ -41,7 +41,7 @@ class KernelViewParser(BaseParser):
41 self._init_step_range(deps_data)41 self._init_step_range(deps_data)
42 self.generate_view()42 self.generate_view()
43 except Exception as e:43 except Exception as e:
44- self.logger.error("Failed to generate kernel_details.csv, error: %s", str(e), exc_info=True)44+ self.logger.exception("Failed to generate kernel_details.csv.")
45 return Constant.FAIL, None45 return Constant.FAIL, None
46 self.logger.info("KernelViewParser finish.")46 self.logger.info("KernelViewParser finish.")
47 return Constant.SUCCESS, None47 return Constant.SUCCESS, None
@@ -75,11 +75,11 @@ class KernelViewParser(BaseParser):
75 if torch_op_node:75 if torch_op_node:
76 kernel_dict = deps_data.get(Constant.RELATION_PARSER, {})76 kernel_dict = deps_data.get(Constant.RELATION_PARSER, {})
77 if not kernel_dict:77 if not kernel_dict:
78- self.logger.error("Kernel view get step range failed, the kernel dict is empty.")78+ self.logger.error("Kernel view failed to get the step range; the kernel dict is empty.")
79 return79 return
80 step_range = FwkCANNRelationParser(self._profiler_path).get_step_range(torch_op_node[0], kernel_dict)80 step_range = FwkCANNRelationParser(self._profiler_path).get_step_range(torch_op_node[0], kernel_dict)
81 if not step_range:81 if not step_range:
82- self.logger.warning("Kernel view get step range failed, the step range is empty.")82+ self.logger.warning("Kernel view failed to get the step range; the step range is empty.")
83 for step_data in step_range:83 for step_data in step_range:
84 step_id = step_data.get(Constant.STEP_ID)84 step_id = step_data.get(Constant.STEP_ID)
85 step_start = convert_ns2us_str(step_data.get(Constant.START_TS, 0))85 step_start = convert_ns2us_str(step_data.get(Constant.START_TS, 0))
@@ -35,7 +35,6 @@ from ...prof_common_func._log import ProfilerLogger
35from ...prof_common_func._path_manager import ProfilerPathManager35from ...prof_common_func._path_manager import ProfilerPathManager
36from .._base_parser import BaseParser36from .._base_parser import BaseParser
37 37 
38- 
39__all__ = []38__all__ = []
40 39 
41 40 
@@ -121,8 +120,9 @@ class CANNExportParser(BaseParser):
121 for path in paths:120 for path in paths:
122 if not FileManager.check_file_owner(path):121 if not FileManager.check_file_owner(path):
123 self.logger.warning(122 self.logger.warning(
124- f"Path '{self._cann_path}' owner is neither root nor the current user. "123+ "The owner of path '%s' is neither root nor the current user. "
125- f"Please execute 'chown -R $(id -un) '{self._cann_path}' '."124+ "Please run: chown -R $(id -un) '%s'.",
125+ self._cann_path, self._cann_path
126 )126 )
127 return False127 return False
128 128 
@@ -35,7 +35,7 @@ class BasicDbParser(BaseParser):
35 self.save_env_vars_info_to_db()35 self.save_env_vars_info_to_db()
36 self.save_profiler_metadata_to_db()36 self.save_profiler_metadata_to_db()
37 except Exception as error:37 except Exception as error:
38- self.logger.error("Failed to generate basic db file. Error: %s", str(error), exc_info=True)38+ self.logger.exception("Failed to generate basic db file.")
39 return Constant.FAIL, ""39 return Constant.FAIL, ""
40 self.logger.info("BasicDbParser finish.")40 self.logger.info("BasicDbParser finish.")
41 return Constant.SUCCESS, ""41 return Constant.SUCCESS, ""
@@ -43,14 +43,14 @@ class BasicDbParser(BaseParser):
43 def get_cann_db_path(self):43 def get_cann_db_path(self):
44 if not self._cann_path:44 if not self._cann_path:
45 return ""45 return ""
46- db_patten = '^msprof_\d+\.db$'46+ db_patten = r'^msprof_\d+\.db$'
47 for cann_file in os.listdir(self._cann_path):47 for cann_file in os.listdir(self._cann_path):
48 file_path = os.path.join(self._cann_path, cann_file)48 file_path = os.path.join(self._cann_path, cann_file)
49 if re.match(db_patten, cann_file):49 if re.match(db_patten, cann_file):
50 try:50 try:
51 FileManager.check_db_file_vaild(file_path)51 FileManager.check_db_file_vaild(file_path)
52 except RuntimeError:52 except RuntimeError:
53- self.logger.warning("Invalid cann db file. file name is: %s", cann_file)53+ self.logger.warning("Invalid CANN db file. File name: %s", cann_file)
54 continue54 continue
55 return file_path55 return file_path
56 # when cann package support default export db, use mindstudio_profiler_output path to get db file56 # when cann package support default export db, use mindstudio_profiler_output path to get db file
@@ -109,13 +109,13 @@ class BasicDbParser(BaseParser):
109 def save_profiler_metadata_to_db(self):109 def save_profiler_metadata_to_db(self):
110 profiler_metadata_path = os.path.join(self._profiler_path, Constant.PROFILER_META_DATA)110 profiler_metadata_path = os.path.join(self._profiler_path, Constant.PROFILER_META_DATA)
111 if not os.path.exists(profiler_metadata_path):111 if not os.path.exists(profiler_metadata_path):
112- self.logger.warning("Can not find profiler_metadata.json, path is: %s", profiler_metadata_path)112+ self.logger.warning("Cannot find profiler_metadata.json. Path: %s", profiler_metadata_path)
113 return113 return
114 profiler_metadata = FileManager.file_read_all(profiler_metadata_path)114 profiler_metadata = FileManager.file_read_all(profiler_metadata_path)
115 try:115 try:
116 profiler_metadata = json.loads(profiler_metadata)116 profiler_metadata = json.loads(profiler_metadata)
117 except json.JSONDecodeError as e:117 except json.JSONDecodeError as e:
118- self.logger.warning("profiler_metadata.json parse failed, error is: %s", str(e))118+ self.logger.warning("Failed to parse profiler_metadata.json.")
119 return119 return
120 data = [[str(key), json.dumps(value)] for key, value in profiler_metadata.items()]120 data = [[str(key), json.dumps(value)] for key, value in profiler_metadata.items()]
121 TorchDb().create_table_with_headers(DbConstant.TABLE_META_DATA,121 TorchDb().create_table_with_headers(DbConstant.TABLE_META_DATA,
@@ -62,7 +62,7 @@ class PathManager:
62 msg = f"The path does not exist: {path}"62 msg = f"The path does not exist: {path}"
63 raise RuntimeError(msg)63 raise RuntimeError(msg)
64 if os.path.islink(path):64 if os.path.islink(path):
65- msg = f"Invalid path is a soft chain: {path}"65+ msg = f"Invalid path is a symbolic link: {path}"
66 warnings.warn(msg)66 warnings.warn(msg)
67 if not os.access(path, os.W_OK):67 if not os.access(path, os.W_OK):
68 msg = f"The path permission check failed: {path}"68 msg = f"The path permission check failed: {path}"
@@ -82,7 +82,7 @@ class PathManager:
82 msg = f"The path does not exist: {path}"82 msg = f"The path does not exist: {path}"
83 raise RuntimeError(msg)83 raise RuntimeError(msg)
84 if os.path.islink(path):84 if os.path.islink(path):
85- msg = f"Invalid path is a soft chain: {path}"85+ msg = f"Invalid path is a symbolic link: {path}"
86 warnings.warn(msg)86 warnings.warn(msg)
87 if not os.access(path, os.R_OK):87 if not os.access(path, os.R_OK):
88 msg = f"The path permission check failed: {path}"88 msg = f"The path permission check failed: {path}"
@@ -146,7 +146,7 @@ class PathManager:
146 warnings.warn("Length of input path exceeds the limit.")146 warnings.warn("Length of input path exceeds the limit.")
147 147 
148 if os.path.islink(path):148 if os.path.islink(path):
149- msg = f"Invalid input path is a soft chain: {path}"149+ msg = f"Invalid input path is a symbolic link: {path}"
150 warnings.warn(msg)150 warnings.warn(msg)
151 151 
152 pattern = r'(\.|/|_|-|\s|[~0-9a-zA-Z]|[\u4e00-\u9fa5])+'152 pattern = r'(\.|/|_|-|\s|[~0-9a-zA-Z]|[\u4e00-\u9fa5])+'
@@ -14,7 +14,6 @@ import torch_npu
14from torch_npu.utils._error_code import ErrCode, pta_error14from torch_npu.utils._error_code import ErrCode, pta_error
15from torch_npu.asd.asd import _silent_check_decorator, silent_check, _matmul_silent_check_decorator, matmul_check15from torch_npu.asd.asd import _silent_check_decorator, silent_check, _matmul_silent_check_decorator, matmul_check
16 16 
17- 
18original_call = Module.__call__17original_call = Module.__call__
19DEFAULT_FALGS = os.O_WRONLY | os.O_CREAT | os.O_TRUNC18DEFAULT_FALGS = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
20DEFAULT_PERMISSION = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP19DEFAULT_PERMISSION = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP
@@ -44,6 +43,7 @@ class PerfDumpState:
44 return True43 return True
45 return False44 return False
46 45 
46+ 
47perf_dump_state = PerfDumpState()47perf_dump_state = PerfDumpState()
48perf_dump_enable = False48perf_dump_enable = False
49 49 
@@ -92,7 +92,8 @@ def delete_pref_pt_logs(perf_dump_path, device_id):
92 try:92 try:
93 os.remove(log_file)93 os.remove(log_file)
94 except Exception as e:94 except Exception as e:
95- raise RuntimeError(f"Failed to delete {log_file}. Please delete it manually." + pta_error(ErrCode.SYSCALL)) from e95+ raise RuntimeError(
96+ f"Failed to delete {log_file}. Please delete it manually." + pta_error(ErrCode.SYSCALL)) from e
96 97 
97 98 
98def _get_uuid():99def _get_uuid():
@@ -139,9 +140,9 @@ def _perf_dump_decorator(func):
139 perf_dump_state.log_file_name = os.path.join(perf_dump_path, f"perf_pt_{pid}_{device_id}.log")140 perf_dump_state.log_file_name = os.path.join(perf_dump_path, f"perf_pt_{pid}_{device_id}.log")
140 _setup_logger("perf_logger", perf_dump_state.log_file_name)141 _setup_logger("perf_logger", perf_dump_state.log_file_name)
141 logger = logging.getLogger("perf_logger")142 logger = logging.getLogger("perf_logger")
142- logger.info(f"[LOCALUUID]:{perf_dump_state.local_uuid}")143+ logger.info("[LOCALUUID]:%s", perf_dump_state.local_uuid)
143 logger.info("[FRAMEWORK]:PyTorch")144 logger.info("[FRAMEWORK]:PyTorch")
144- logger.info(f"[UUID]:{perf_dump_state.uuid}")145+ logger.info("[UUID]:%s", perf_dump_state.uuid)
145 os.chmod(perf_dump_state.log_file_name, DEFAULT_PERMISSION)146 os.chmod(perf_dump_state.log_file_name, DEFAULT_PERMISSION)
146 perf_dump_state.has_log = True147 perf_dump_state.has_log = True
147 148 
@@ -150,7 +151,7 @@ def _perf_dump_decorator(func):
150 current_time = int(time.time() * 1000)151 current_time = int(time.time() * 1000)
151 logger = logging.getLogger("perf_logger")152 logger = logging.getLogger("perf_logger")
152 if perf_dump_state.last_time is not None:153 if perf_dump_state.last_time is not None:
153- logger.info(f"[STEPTIME]:{perf_dump_state.last_time},{current_time}")154+ logger.info("[STEPTIME]:%s,%s", perf_dump_state.last_time, current_time)
154 perf_dump_state.last_time = current_time155 perf_dump_state.last_time = current_time
155 perf_dump_state.add_module_dict(self)156 perf_dump_state.add_module_dict(self)
156 perf_dump_state.is_outer_call = False157 perf_dump_state.is_outer_call = False
@@ -164,6 +165,7 @@ def _perf_dump_decorator(func):
164 self.visited = False165 self.visited = False
165 166 
166 return tmp167 return tmp
168+ 
167 return wrapper169 return wrapper
168 170 
169 171 
@@ -190,7 +192,10 @@ def _prase_asd_config(asd_config):
190 # checksum192 # checksum
191 with_checksum_str = asd_config.get("with_checksum", "false")193 with_checksum_str = asd_config.get("with_checksum", "false")
192 if with_checksum_str not in ["true", "false"]:194 if with_checksum_str not in ["true", "false"]:
193- raise ValueError("NPU_ASD_CONFIG-with_checksum should be true or false. For details, 0 as `with checksum closed`, 1 as `with checksum opened`." + pta_error(ErrCode.VALUE))195+ raise ValueError(
196+ "NPU_ASD_CONFIG-with_checksum should be true or false. "
197+ "For details, 0 as `with checksum closed`, 1 as `with checksum opened`."
198+ + pta_error(ErrCode.VALUE))
194 with_checksum = with_checksum_str == "true"199 with_checksum = with_checksum_str == "true"
195 matmul_check.set_with_checksum(with_checksum)200 matmul_check.set_with_checksum(with_checksum)
196 201 
@@ -199,49 +204,49 @@ def _prase_asd_config(asd_config):
199 if cooldown.isdigit() and cooldown != "0":204 if cooldown.isdigit() and cooldown != "0":
200 matmul_check.set_cooldown(int(cooldown))205 matmul_check.set_cooldown(int(cooldown))
201 else:206 else:
202- warnings.warn(f"Warning: NPU_ASD_CONFIG-cooldown is invalid, use the default value of 5.")207+ warnings.warn("NPU_ASD_CONFIG-cooldown is invalid; using the default value of 5.")
203 208 
204 # strikes_num209 # strikes_num
205 strikes_num = asd_config.get("strikes_num", "3")210 strikes_num = asd_config.get("strikes_num", "3")
206 if strikes_num.isdigit() and strikes_num != "0":211 if strikes_num.isdigit() and strikes_num != "0":
207 matmul_check.set_strikes_num(int(strikes_num))212 matmul_check.set_strikes_num(int(strikes_num))
208 else:213 else:
209- warnings.warn(f"Warning: NPU_ASD_CONFIG-strikes_num is invalid, use the default value of 3.")214+ warnings.warn("NPU_ASD_CONFIG-strikes_num is invalid; using the default value of 3.")
210 215 
211 # strikes_window216 # strikes_window
212 strikes_window = asd_config.get("strikes_window", "480")217 strikes_window = asd_config.get("strikes_window", "480")
213 if strikes_window.isdigit() and strikes_window != "0":218 if strikes_window.isdigit() and strikes_window != "0":
214 matmul_check.set_strikes_window(int(strikes_window))219 matmul_check.set_strikes_window(int(strikes_window))
215 else:220 else:
216- warnings.warn(f"Warning: NPU_ASD_CONFIG-strikes_window is invalid, use the default value of 480.")221+ warnings.warn("NPU_ASD_CONFIG-strikes_window is invalid; using the default value of 480.")
217 222 
218 # checksum_cooldown223 # checksum_cooldown
219 checksum_cooldown = asd_config.get("checksum_cooldown", "180")224 checksum_cooldown = asd_config.get("checksum_cooldown", "180")
220 if checksum_cooldown.isdigit() and checksum_cooldown != "0":225 if checksum_cooldown.isdigit() and checksum_cooldown != "0":
221 matmul_check.set_checksum_cooldown(int(checksum_cooldown))226 matmul_check.set_checksum_cooldown(int(checksum_cooldown))
222 else:227 else:
223- warnings.warn(f"Warning: NPU_ASD_CONFIG-checksum_cooldown is invalid, use the default value of 180.")228+ warnings.warn("NPU_ASD_CONFIG-checksum_cooldown is invalid; using the default value of 180.")
224 229 
225 # upper_thresh1230 # upper_thresh1
226 upper_thresh1 = asd_config.get("upper_thresh1", "1000000")231 upper_thresh1 = asd_config.get("upper_thresh1", "1000000")
227 if upper_thresh1.isdigit() and int(upper_thresh1) >= 3:232 if upper_thresh1.isdigit() and int(upper_thresh1) >= 3:
228 matmul_check.set_upper_thresh1(int(upper_thresh1))233 matmul_check.set_upper_thresh1(int(upper_thresh1))
229 else:234 else:
230- warnings.warn(f"Warning: NPU_ASD_CONFIG-upper_thresh1 is invalid, use the default value of 1000000.")235+ warnings.warn("NPU_ASD_CONFIG-upper_thresh1 is invalid; using the default value of 1000000.")
231 236 
232 # upper_thresh2237 # upper_thresh2
233 upper_thresh2 = asd_config.get("upper_thresh2", "100")238 upper_thresh2 = asd_config.get("upper_thresh2", "100")
234 if upper_thresh2.isdigit() and int(upper_thresh2) >= 3:239 if upper_thresh2.isdigit() and int(upper_thresh2) >= 3:
235 matmul_check.set_upper_thresh2(int(upper_thresh2))240 matmul_check.set_upper_thresh2(int(upper_thresh2))
236 else:241 else:
237- warnings.warn(f"Warning: NPU_ASD_CONFIG-upper_thresh2 is invalid, use the default value of 100.")242+ warnings.warn("NPU_ASD_CONFIG-upper_thresh2 is invalid; using the default value of 100.")
238 243 
239 # grad_sample_interval244 # grad_sample_interval
240 grad_sample_interval = asd_config.get("grad_sample_interval", "3")245 grad_sample_interval = asd_config.get("grad_sample_interval", "3")
241 if grad_sample_interval.isdigit() and grad_sample_interval != "0":246 if grad_sample_interval.isdigit() and grad_sample_interval != "0":
242 matmul_check.set_grad_sample_interval(int(grad_sample_interval))247 matmul_check.set_grad_sample_interval(int(grad_sample_interval))
243 else:248 else:
244- warnings.warn(f"Warning: NPU_ASD_CONFIG-grad_sample_interval is invalid, use the default value of 3.")249+ warnings.warn("NPU_ASD_CONFIG-grad_sample_interval is invalid; using the default value of 3.")
245 250 
246 251 
247def add_perf_dump_patch():252def add_perf_dump_patch():
@@ -258,33 +263,46 @@ def add_perf_dump_patch():
258 asd_config_dict = _parse_config(asd_config)263 asd_config_dict = _parse_config(asd_config)
259 asd_config_enable = asd_config_dict.get("enable", "false")264 asd_config_enable = asd_config_dict.get("enable", "false")
260 if asd_config_enable not in ["true", "false"]:265 if asd_config_enable not in ["true", "false"]:
261- raise ValueError("NPU_ASD_CONFIG-enable should be true or false. For details, false as `ASD closed`, true as `ASD opened`." + pta_error(ErrCode.VALUE))266+ raise ValueError(
267+ "NPU_ASD_CONFIG-enable should be true or false. "
268+ "For details, false as `ASD closed`, true as `ASD opened`."
269+ + pta_error(ErrCode.VALUE))
262 if asd_config_enable == "true":270 if asd_config_enable == "true":
263- warnings.warn(f'Silent data corruption check may take up 1.5GB device memory, please make sure there are enough free space in device')271+ warnings.warn('Silent data corruption check may take up to 1.5GB device memory. '
272+ 'Please make sure there is enough free space on the device.')
264 _prase_asd_config(asd_config_dict)273 _prase_asd_config(asd_config_dict)
265 asd_enable = 1274 asd_enable = 1
266 matmul_check.set_matmul_hook_enable(asd_enable)275 matmul_check.set_matmul_hook_enable(asd_enable)
267- loggerSilent.info(f"Silent check 3.0 version will be enabled. The checksum enable is {matmul_check.get_with_checksum()}, "276+ loggerSilent.info(
268- f"cooldown is {matmul_check.get_cooldown()}, strikes_num is {matmul_check.get_strikes_num()}, strikes_window is {matmul_check.get_strikes_window()}, "277+ "Silent check 3.0 will be enabled. checksum_enable=%s, cooldown=%s, "
269- f"checksum_cooldown is {matmul_check.get_checksum_cooldown()}, upper_thresh1 is {matmul_check.get_upper_thresh1()}, "278+ "strikes_num=%s, strikes_window=%s, checksum_cooldown=%s, "
270- f"upper_thresh2 is {matmul_check.get_upper_thresh2()}. grad_sample_interval is {matmul_check.get_grad_sample_interval()}.")279+ "upper_thresh1=%s, upper_thresh2=%s, grad_sample_interval=%s.",
280+ matmul_check.get_with_checksum(), matmul_check.get_cooldown(),
281+ matmul_check.get_strikes_num(), matmul_check.get_strikes_window(),
282+ matmul_check.get_checksum_cooldown(), matmul_check.get_upper_thresh1(),
283+ matmul_check.get_upper_thresh2(), matmul_check.get_grad_sample_interval())
271 else:284 else:
272 asd_value = os.getenv("NPU_ASD_ENABLE", "0")285 asd_value = os.getenv("NPU_ASD_ENABLE", "0")
273 if asd_value not in ["0", "1", "2", "3"]:286 if asd_value not in ["0", "1", "2", "3"]:
274- raise ValueError("NPU_ASD_ENABLE should be 0, 1, 2 or 3. For details, 0 as `ASD closed`, "287+ raise ValueError(
275- "1 as `ASD opened, print error logs`, "288+ "NPU_ASD_ENABLE should be 0, 1, 2 or 3. For details, 0 as `ASD closed`, "
276- "2 as `ASD opened, print error logs and raise exception`, "289+ "1 as `ASD opened, print error logs`, "
277- "3 as `ASD opened, print debug logs and raise exception`" + pta_error(ErrCode.VALUE))290+ "2 as `ASD opened, print error logs and raise exception`, "
291+ "3 as `ASD opened, print debug logs and raise exception`" + pta_error(ErrCode.VALUE))
278 asd_enable = int(asd_value)292 asd_enable = int(asd_value)
279 if asd_enable > 0:293 if asd_enable > 0:
280 if torch_npu._C._get_silent_check_version() == 1:294 if torch_npu._C._get_silent_check_version() == 1:
281 # The old version CANN only supports ASD 1.0. It can be enabled by patching layernorm and embedding in asd.py,295 # The old version CANN only supports ASD 1.0. It can be enabled by patching layernorm and embedding in asd.py,
282 # and will raise an error when NPU_ASD_ENABLE is set to 2 or 3.296 # and will raise an error when NPU_ASD_ENABLE is set to 2 or 3.
283 if asd_enable == 1:297 if asd_enable == 1:
284- warnings.warn(f"Warning: CANN version lower than 8.0.RC3 and currently does not support silent check 2.0 version or later. It will switch to 1.0 version.")298+ warnings.warn(
299+ "CANN version is lower than 8.0.RC3 and currently does not support "
300+ "silent check 2.0 or later. It will switch to 1.0.")
285 else:301 else:
286- warnings.warn(f"Warning: Silent check 2.0 version will be enabled. The asd_detect is {asd_enable}. It is recommended to enable silent check v3 using the NPU_ASD_CONFIG.\n"302+ warnings.warn(f"Silent check 2.0 version will be enabled (asd_detect={asd_enable}). "
287- "Silent data corruption check may take up 1.5GB device memory, please make sure there are enough free space in device. ")303+ "It is recommended to enable silent check v3 using NPU_ASD_CONFIG.\n"
304+ "Silent data corruption check may take up to 1.5GB device memory. "
305+ "Please make sure there is enough free space on the device.")
288 silent_check.set_check_enable(asd_enable)306 silent_check.set_check_enable(asd_enable)
289 307 
290 if perf_dump_enable or asd_enable:308 if perf_dump_enable or asd_enable:
@@ -51,7 +51,7 @@ def get_torch_npu_install_path():
51 51 
52@deprecated(52@deprecated(
53 "`torch_npu.utils.collect_env.check_path_owner_consistent(path)` is deprecated and no longer performs path owner verification. "53 "`torch_npu.utils.collect_env.check_path_owner_consistent(path)` is deprecated and no longer performs path owner verification. "
54- "Please use `check_directory_path_readable(path)` to check the path existence.",54+ "Please use `check_directory_path_readable(path)` to check whether the path exists.",
55 category=FutureWarning,55 category=FutureWarning,
56)56)
57def check_path_owner_consistent(path: str):57def check_path_owner_consistent(path: str):
@@ -65,7 +65,7 @@ def check_directory_path_readable(path):
65 msg = f"The path does not exist: {path}"65 msg = f"The path does not exist: {path}"
66 raise RuntimeError(msg)66 raise RuntimeError(msg)
67 if os.path.islink(path):67 if os.path.islink(path):
68- msg = f"Invalid path is a soft chain: {path}"68+ msg = f"Invalid path is a symbolic link: {path}"
69 raise RuntimeError(msg)69 raise RuntimeError(msg)
70 if not os.access(path, os.R_OK):70 if not os.access(path, os.R_OK):
71 msg = f"The path permission check failed: {path}"71 msg = f"The path permission check failed: {path}"
@@ -1,5 +1,4 @@
1import os1import os
2-import re
3 2 
4from functools import wraps3from functools import wraps
5 4 
@@ -32,7 +31,7 @@ def _cann_package_check():
32 31 
33 # check whether environment variables are correctly configured32 # check whether environment variables are correctly configured
34 if "ASCEND_OPP_PATH" not in os.environ:33 if "ASCEND_OPP_PATH" not in os.environ:
35- raise Exception(f"ASCEND_OPP_PATH environment variable is not set. "34+ raise Exception("ASCEND_OPP_PATH environment variable is not set. "
36 "Please check whether the opp package has been installed. If exist, please run "35 "Please check whether the opp package has been installed. If exist, please run "
37 "'source set_env.sh' in the CANN installation path." +36 "'source set_env.sh' in the CANN installation path." +
38 pta_error(ErrCode.NOT_FOUND))37 pta_error(ErrCode.NOT_FOUND))
@@ -64,10 +63,10 @@ def _cann_package_check():
64 # check whether the CANN package version matches the pytorch version63 # check whether the CANN package version matches the pytorch version
65 if cann_version in cann_pytorch_version_map and \64 if cann_version in cann_pytorch_version_map and \
66 torch_npu.__version__ not in cann_pytorch_version_map[cann_version]:65 torch_npu.__version__ not in cann_pytorch_version_map[cann_version]:
67- print(f"Warning : CANN package version {cann_version} and PyTorch version {torch_npu.__version__} "66+ print(f"Warning: CANN package version {cann_version} and PyTorch version {torch_npu.__version__} "
68- "is not matched, please check the README of the ascend pytorch repo.")67+ "do not match. Please check the README of the Ascend PyTorch repo.")
69 else:68 else:
70- print(f"Warning : ASCEND_HOME_PATH environment variable is not set.")69+ print("Warning: ASCEND_HOME_PATH environment variable is not set.")
71 70 
72 71 
73def _create_wrap_func(check_func):72def _create_wrap_func(check_func):
@@ -314,8 +314,8 @@ def load(
314 314 
315 warn_massage = (315 warn_massage = (
316 'Warning: since the loaded file is not a zipfile, only "torch.device" and "str" type parameters '316 'Warning: since the loaded file is not a zipfile, only "torch.device" and "str" type parameters '
317- "are currently supported for parameter types of map_location. If parameter types of map_location is "317+ "are currently supported for map_location. If the parameter type of map_location is "
318- '"Callable[[torch.Tensor, str], torch.Tensor]" or "Dict[str, str]", which is only support for '318+ '"Callable[[torch.Tensor, str], torch.Tensor]" or "Dict[str, str]", which is supported only for '
319 "zipfile, all tensors are currently loaded onto the CPU, which may introduce problems."319 "zipfile, all tensors are currently loaded onto the CPU, which may introduce problems."
320 )320 )
321 _warn_legacy_serialization(warn_massage, "load")321 _warn_legacy_serialization(warn_massage, "load")
@@ -665,9 +665,9 @@ def _add_serialization_methods():
665 def _npu_legacy_save(obj, f, pickle_module, pickle_protocol):665 def _npu_legacy_save(obj, f, pickle_module, pickle_protocol):
666 warn_massage = (666 warn_massage = (
667 'Warning: torch.save with "_use_new_zipfile_serialization = False" is not recommended '667 'Warning: torch.save with "_use_new_zipfile_serialization = False" is not recommended '
668- "for npu tensor, which may bring unexpected errors and hopefully set "668+ "for NPU tensors, which may cause unexpected errors. It is better to set "
669- '"_use_new_zipfile_serialization = True"',669+ '"_use_new_zipfile_serialization = True". '
670- "if it is necessary to use this, please convert the npu tensor to cpu tensor for saving",670+ "If it is necessary to use this, please convert the NPU tensors to CPU tensors for saving."
671 )671 )
672 _warn_legacy_serialization(warn_massage, "save")672 _warn_legacy_serialization(warn_massage, "save")
673 return _orig_legacy_save(obj, f, pickle_module, pickle_protocol)673 return _orig_legacy_save(obj, f, pickle_module, pickle_protocol)