已合并
[test]profiler fix uttest #38680
hhz0创建于 6月16日
[test]profiler fix uttest #38680
已合并
共 3 个文件变更+9-24
| @@ -1,14 +1,12 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import shutil | 2 | import shutil |
| 3 | import stat | 3 | import stat |
| 4 | -from unittest.mock import patch, MagicMock | ||
| 5 | 4 | ||
| 6 | from torch_npu.profiler.analysis.prof_common_func._constant import Constant | 5 | from torch_npu.profiler.analysis.prof_common_func._constant import Constant |
| 7 | from torch_npu.profiler.analysis.prof_common_func._file_manager import FileManager | 6 | from torch_npu.profiler.analysis.prof_common_func._file_manager import FileManager |
| 8 | from torch_npu.profiler.analysis.prof_common_func._path_manager import ProfilerPathManager | 7 | from torch_npu.profiler.analysis.prof_common_func._path_manager import ProfilerPathManager |
| 9 | 8 | ||
| 10 | from torch_npu.testing.testcase import TestCase, run_tests | 9 | from torch_npu.testing.testcase import TestCase, run_tests |
| 11 | -from torch_npu.utils._path_manager import PathManager | ||
| 12 | 10 | ||
| 13 | 11 | ||
| 14 | class TestPathManager(TestCase): | 12 | class TestPathManager(TestCase): |
| @@ -120,7 +118,7 @@ class TestPathManager(TestCase): | |||
| 120 | os.makedirs(os.path.join(prof_path2, "PROF_1_2_3a")) | 118 | os.makedirs(os.path.join(prof_path2, "PROF_1_2_3a")) |
| 121 | self.assertEqual([prof_path1], ProfilerPathManager.get_profiler_path_list(prof_path1)) | 119 | self.assertEqual([prof_path1], ProfilerPathManager.get_profiler_path_list(prof_path1)) |
| 122 | self.assertEqual([prof_path2], ProfilerPathManager.get_profiler_path_list(prof_path2)) | 120 | self.assertEqual([prof_path2], ProfilerPathManager.get_profiler_path_list(prof_path2)) |
| 123 | - self.assertEqual(set((prof_path1, prof_path2)), set(ProfilerPathManager.get_profiler_path_list(self.tmp_dir))) | 121 | + self.assertEqual({prof_path1, prof_path2}, set(ProfilerPathManager.get_profiler_path_list(self.tmp_dir))) |
| 124 | 122 | ||
| 125 | def test_device_all_file_list_by_tag(self): | 123 | def test_device_all_file_list_by_tag(self): |
| 126 | self.assertEqual([], ProfilerPathManager.get_output_all_file_list_by_type(self.tmp_dir, "mindstudio_profiler_output")) | 124 | self.assertEqual([], ProfilerPathManager.get_output_all_file_list_by_type(self.tmp_dir, "mindstudio_profiler_output")) |
| @@ -215,20 +213,6 @@ class TestPathManager(TestCase): | |||
| 215 | ] | 213 | ] |
| 216 | self.assertCountEqual(result_depth_2, expected_depth_2) | 214 | self.assertCountEqual(result_depth_2, expected_depth_2) |
| 217 | 215 | ||
| 218 | - | ||
| 219 | - def test_path_is_other_writable(self, mock_stat): | ||
| 220 | - mock_stat_result = MagicMock() | ||
| 221 | - mock_stat_result.st_mode = 0o777 | ||
| 222 | - mock_stat.return_value = mock_stat_result | ||
| 223 | - | ||
| 224 | - self.assertTrue(ProfilerPathManager.path_is_other_writable(self.tmp_dir)) | ||
| 225 | - mock_stat_result.st_mode = 0o755 | ||
| 226 | - self.assertFalse(ProfilerPathManager.path_is_other_writable(self.tmp_dir)) | ||
| 227 | - mock_stat_result.st_mode = 0o775 | ||
| 228 | - self.assertTrue(ProfilerPathManager.path_is_other_writable(self.tmp_dir)) | ||
| 229 | - mock_stat_result.st_mode = 0o700 | ||
| 230 | - self.assertFalse(ProfilerPathManager.path_is_other_writable(self.tmp_dir)) | ||
| 231 | - | ||
| 232 | 216 | ||
| 233 | if __name__ == "__main__": | 217 | if __name__ == "__main__": |
| 234 | run_tests() | 218 | run_tests() |
| @@ -4,7 +4,7 @@ import logging | |||
| 4 | import sys | 4 | import sys |
| 5 | import threading | 5 | import threading |
| 6 | from collections.abc import Callable | 6 | from collections.abc import Callable |
| 7 | -from typing import Any | 7 | +from typing import Any, Optional |
| 8 | 8 | ||
| 9 | from torch_npu.npu.mstx import mstx | 9 | from torch_npu.npu.mstx import mstx |
| 10 | 10 | ||
| @@ -70,7 +70,7 @@ class FlopsHookManager: | |||
| 70 | _installed = False | 70 | _installed = False |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | - def install(cls, target_ops: dict[str, tuple[Any, str]] | None = None): | 73 | + def install(cls, target_ops: Optional[dict[str, tuple[Any, str]]] = None): |
| 74 | if cls._installed: | 74 | if cls._installed: |
| 75 | return | 75 | return |
| 76 | if target_ops is None: | 76 | if target_ops is None: |
| @@ -1,16 +1,17 @@ | |||
| 1 | import logging | 1 | import logging |
| 2 | from collections.abc import Callable | 2 | from collections.abc import Callable |
| 3 | +from typing import Optional | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | logger = logging.getLogger(__name__) | 6 | logger = logging.getLogger(__name__) |
| 6 | 7 | ||
| 7 | -_default_npu_flop_registry: dict[str, tuple[Callable, str | None]] = {} | 8 | +_default_npu_flop_registry: dict[str, tuple[Callable, Optional[str]]] = {} |
| 8 | -_npu_flop_registry: dict[str, tuple[Callable, str | None]] = {} | 9 | +_npu_flop_registry: dict[str, tuple[Callable, Optional[str]]] = {} |
| 9 | 10 | ||
| 10 | 11 | ||
| 11 | def register_npu_flop( | 12 | def register_npu_flop( |
| 12 | - target: str | None = None, | 13 | + target: Optional[str] = None, |
| 13 | - op_name: str | None = None, | 14 | + op_name: Optional[str] = None, |
| 14 | *, | 15 | *, |
| 15 | is_default: bool = False, | 16 | is_default: bool = False, |
| 16 | ): | 17 | ): |
| @@ -34,7 +35,7 @@ def register_npu_flop( | |||
| 34 | return decorator | 35 | return decorator |
| 35 | 36 | ||
| 36 | 37 | ||
| 37 | -def get_flop_func(op_name: str) -> Callable | None: | 38 | +def get_flop_func(op_name: str) -> Optional[Callable]: |
| 38 | entry = _npu_flop_registry.get(op_name) or _default_npu_flop_registry.get(op_name) | 39 | entry = _npu_flop_registry.get(op_name) or _default_npu_flop_registry.get(op_name) |
| 39 | return entry[0] if entry else None | 40 | return entry[0] if entry else None |
| 40 | 41 | ||