已合并
[fix] Init version in GetCANNVersion and delete unnecessary warning #38143
zhaoyu65创建于 6月10日
[fix] Init version in GetCANNVersion and delete unnecessary warning #38143
已合并
zhaoyu65创建于 6月10日
7 个文件变更+46-66
Mbenchmarks/torchbench/common.py+6-10
@@ -262,14 +262,6 @@ class PathManager:
262 DATA_FILE_AUTHORITY = 0o640262 DATA_FILE_AUTHORITY = 0o640
263 DATA_DIR_AUTHORITY = 0o750263 DATA_DIR_AUTHORITY = 0o750
264 264 
265- @classmethod
266- def check_path_owner_consistent(cls, path: str):
267- if not os.path.exists(path):
268- msg = f"The path does not exist: {path}"
269- raise RuntimeError(msg)
270- if os.stat(path).st_uid != os.getuid():
271- warnings.warn(f"Warning: The {path} owner does not match the current user.")
272- 
273 @classmethod265 @classmethod
274 def create_file_safety(cls, path: str):266 def create_file_safety(cls, path: str):
275 msg = f"Failed to create file: {path}"267 msg = f"Failed to create file: {path}"
@@ -285,7 +277,9 @@ class PathManager:
285 277 
286 @classmethod278 @classmethod
287 def check_directory_path_readable(cls, path):279 def check_directory_path_readable(cls, path):
288- cls.check_path_owner_consistent(path)280+ if not os.path.exists(path):
281+ msg = f"The path does not exist: {path}"
282+ raise RuntimeError(msg)
289 if os.path.islink(path):283 if os.path.islink(path):
290 msg = f"Invalid path is a soft chain: {path}"284 msg = f"Invalid path is a soft chain: {path}"
291 raise RuntimeError(msg)285 raise RuntimeError(msg)
@@ -295,7 +289,9 @@ class PathManager:
295 289 
296 @classmethod290 @classmethod
297 def check_directory_path_writeable(cls, path):291 def check_directory_path_writeable(cls, path):
298- cls.check_path_owner_consistent(path)292+ if not os.path.exists(path):
293+ msg = f"The path does not exist: {path}"
294+ raise RuntimeError(msg)
299 if os.path.islink(path):295 if os.path.islink(path):
300 msg = f"Invalid path is a soft chain: {path}"296 msg = f"Invalid path is a soft chain: {path}"
301 raise RuntimeError(msg)297 raise RuntimeError(msg)
Mtest/deprecated_apis.json+3-0
@@ -15,6 +15,9 @@
15 "npu_silu",15 "npu_silu",
16 "npu_sort_v2"16 "npu_sort_v2"
17 ],17 ],
18+ "torch_npu.utils.collect_env": [
19+ "deprecated"
20+ ],
18 "torch_npu.contrib": [21 "torch_npu.contrib": [
19 "BiLSTM",22 "BiLSTM",
20 "DCNv2",23 "DCNv2",
Mtorch_npu/csrc/core/npu/GetCANNInfo.cpp+13-11
@@ -458,31 +458,33 @@ std::string GetCANNVersion(const std::string& module)
458 }458 }
459 std::string module_version = "";459 std::string module_version = "";
460 if (find_module != packageNameMap.end()) {460 if (find_module != packageNameMap.end()) {
461- aclCANNPackageVersion version;461+ aclCANNPackageVersion version = {};
462 aclCANNPackageName name = find_module->second;462 aclCANNPackageName name = find_module->second;
463 aclError ret = c10_npu::acl::AclsysGetCANNVersion(name, &version);463 aclError ret = c10_npu::acl::AclsysGetCANNVersion(name, &version);
464- if (ret == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {464+ if (ret != ACL_RT_SUCCESS) {
465- ASCEND_LOGW("Failed to find function aclsysGetCANNVersion.");465+ ASCEND_LOGW("Failed to find function aclsysGetCANNVersion, ret: %d.", ret);
466 CANNVersionCache[module] = "";466 CANNVersionCache[module] = "";
467 return "";467 return "";
468+ } else {
469+ module_version = version.version;
470+ CANNVersionCache[module] = module_version;
471+ return module_version;
468 }472 }
469- module_version = version.version;
470- CANNVersionCache[module] = module_version;
471 }473 }
472 474 
473 if (find_module_v2 != pkgNameV2Map.end()) {475 if (find_module_v2 != pkgNameV2Map.end()) {
474 char versionStr[ACL_PKG_VERSION_MAX_SIZE] = {0};476 char versionStr[ACL_PKG_VERSION_MAX_SIZE] = {0};
475 aclError retV2 = c10_npu::acl::AclsysGetVersionStr(const_cast<char*>(module.c_str()), versionStr);477 aclError retV2 = c10_npu::acl::AclsysGetVersionStr(const_cast<char*>(module.c_str()), versionStr);
476- if (retV2 == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {478+ if (retV2 != ACL_RT_SUCCESS) {
477- ASCEND_LOGW("Failed to find function aclsysGetVersionStr.");479+ ASCEND_LOGW("Failed to find function aclsysGetVersionStr, ret: %d.", retV2);
478 CANNVersionCache[module] = "";480 CANNVersionCache[module] = "";
479 return "";481 return "";
482+ } else {
483+ module_version = versionStr;
484+ CANNVersionCache[module] = module_version;
485+ return module_version;
480 }486 }
481- module_version = versionStr;
482- CANNVersionCache[module] = module_version;
483 }487 }
484- 
485- return module_version;
486}488}
487// Returns: 1 if currentVersion >= targetVersion, 0 if currentVersion < targetVersion, -1 if invalid489// Returns: 1 if currentVersion >= targetVersion, 0 if currentVersion < targetVersion, -1 if invalid
488int CompareVersionsByDispatch(const std::string& currentVersion, const std::string& targetVersion)490int CompareVersionsByDispatch(const std::string& currentVersion, const std::string& targetVersion)
Mtorch_npu/profiler/analysis/_npu_profiler.py+4-1
@@ -1,3 +1,4 @@
1+import os
1import multiprocessing2import multiprocessing
2 3 
3from .prof_common_func._constant import Constant, print_error_msg4from .prof_common_func._constant import Constant, print_error_msg
@@ -43,4 +44,6 @@ class NpuProfiler:
43 @classmethod44 @classmethod
44 def _check_input_path(cls, path: str):45 def _check_input_path(cls, path: str):
45 PathManager.check_input_directory_path(path)46 PathManager.check_input_directory_path(path)
46- PathManager.check_path_owner_consistent(path)47+ if not os.path.exists(path):
48+ msg = f"The path does not exist: {path}"
49+ raise RuntimeError(msg)
Mtorch_npu/utils/_path_manager.py+7-20
@@ -48,23 +48,6 @@ class PathManager:
48 msg = "Invalid input path is a directory path: {path}"48 msg = "Invalid input path is a directory path: {path}"
49 raise RuntimeError(msg + pta_error(ErrCode.PARAM))49 raise RuntimeError(msg + pta_error(ErrCode.PARAM))
50 50 
51- @classmethod
52- def check_path_owner_consistent(cls, path: str):
53- """
54- Function Description:
55- check whether the path belong to process owner
56- Parameter:
57- path: the path to check
58- Exception Description:
59- Raise a RuntimeError when the specified path does not exist
60- """
61- 
62- if not os.path.exists(path):
63- msg = f"The path does not exist: {path}"
64- raise RuntimeError(msg + pta_error(ErrCode.NOT_FOUND))
65- if os.stat(path).st_uid != os.getuid():
66- warnings.warn(f"Permission mismatch: The owner of {path} does not match.")
67- 
68 @classmethod51 @classmethod
69 def check_directory_path_writeable(cls, path):52 def check_directory_path_writeable(cls, path):
70 """53 """
@@ -75,7 +58,9 @@ class PathManager:
75 Exception Description:58 Exception Description:
76 when invalid data throw exception59 when invalid data throw exception
77 """60 """
78- cls.check_path_owner_consistent(path)61+ if not os.path.exists(path):
62+ msg = f"The path does not exist: {path}"
63+ raise RuntimeError(msg)
79 if os.path.islink(path):64 if os.path.islink(path):
80 msg = f"Invalid path is a soft chain: {path}"65 msg = f"Invalid path is a soft chain: {path}"
81 warnings.warn(msg)66 warnings.warn(msg)
@@ -87,13 +72,15 @@ class PathManager:
87 def check_directory_path_readable(cls, path):72 def check_directory_path_readable(cls, path):
88 """73 """
89 Function Description:74 Function Description:
90- check whether the path is writable75+ check whether the path is readable
91 Parameter:76 Parameter:
92 path: the path to check77 path: the path to check
93 Exception Description:78 Exception Description:
94 when invalid data throw exception79 when invalid data throw exception
95 """80 """
96- cls.check_path_owner_consistent(path)81+ if not os.path.exists(path):
82+ msg = f"The path does not exist: {path}"
83+ raise RuntimeError(msg)
97 if os.path.islink(path):84 if os.path.islink(path):
98 msg = f"Invalid path is a soft chain: {path}"85 msg = f"Invalid path is a soft chain: {path}"
99 warnings.warn(msg)86 warnings.warn(msg)
Mtorch_npu/utils/collect_env.py+9-5
@@ -3,7 +3,7 @@ import re
3import sys3import sys
4import os4import os
5import site5import site
6-import warnings6+from typing_extensions import deprecated
7from collections import namedtuple7from collections import namedtuple
8 8 
9from torch.utils import collect_env as torch_collect_env9from torch.utils import collect_env as torch_collect_env
@@ -49,17 +49,21 @@ def get_torch_npu_install_path():
49 path = site_packages[0]49 path = site_packages[0]
50 return path50 return path
51 51 
52- 52+@deprecated(
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.",
55+ category=FutureWarning,
56+)
53def check_path_owner_consistent(path: str):57def check_path_owner_consistent(path: str):
54 if not os.path.exists(path):58 if not os.path.exists(path):
55 msg = f"The path does not exist: {path}"59 msg = f"The path does not exist: {path}"
56 raise RuntimeError(msg)60 raise RuntimeError(msg)
57- if os.stat(path).st_uid != os.getuid():
58- warnings.warn(f"Warning: The {path} owner does not match the current owner.")
59 61 
60 62 
61def check_directory_path_readable(path):63def check_directory_path_readable(path):
62- check_path_owner_consistent(path)64+ if not os.path.exists(path):
65+ msg = f"The path does not exist: {path}"
66+ raise RuntimeError(msg)
63 if os.path.islink(path):67 if os.path.islink(path):
64 msg = f"Invalid path is a soft chain: {path}"68 msg = f"Invalid path is a soft chain: {path}"
65 raise RuntimeError(msg)69 raise RuntimeError(msg)
Mtorchnpugen/utils.py+4-19
@@ -78,34 +78,19 @@ DEVICE_CHECK_NOTSUPPORT_TYPE = {"Tensor[]?"}
78 78 
79 79 
80class PathManager:80class PathManager:
81- @classmethod
82- def check_path_owner_consistent(cls, path: str):
83- """
84- Function Description:
85- check whether the path belong to process owner
86- Parameter:
87- path: the path to check
88- Exception Description:
89- when invalid path, prompt the user
90- """
91- 
92- if not os.path.exists(path):
93- msg = f"The path does not exist: {path}"
94- raise RuntimeError(msg)
95- if os.stat(path).st_uid != os.getuid():
96- warnings.warn(f"Warning: The {path} owner does not match the current user.")
97- 
98 @classmethod81 @classmethod
99 def check_directory_path_readable(cls, path):82 def check_directory_path_readable(cls, path):
100 """83 """
101 Function Description:84 Function Description:
102- check whether the path is writable85+ check whether the path is readable
103 Parameter:86 Parameter:
104 path: the path to check87 path: the path to check
105 Exception Description:88 Exception Description:
106 when invalid data throw exception89 when invalid data throw exception
107 """90 """
108- cls.check_path_owner_consistent(path)91+ if not os.path.exists(path):
92+ msg = f"The path does not exist: {path}"
93+ raise RuntimeError(msg)
109 if os.path.islink(path):94 if os.path.islink(path):
110 msg = f"Invalid path is a soft chain: {path}"95 msg = f"Invalid path is a soft chain: {path}"
111 raise RuntimeError(msg)96 raise RuntimeError(msg)