已合并
[v2.7.1][Fix] Fix static check errors detected by TABS #37994
thickhair创建于 6月9日
[v2.7.1][Fix] Fix static check errors detected by TABS #37994
已合并
共 10 个文件变更+84-91
| @@ -464,49 +464,42 @@ is_formatter = true | |||
| 464 | # '@{{PATHSFILE}}' | 464 | # '@{{PATHSFILE}}' |
| 465 | # ] | 465 | # ] |
| 466 | 466 | ||
| 467 | -# [[linter]] | 467 | +[[linter]] |
| 468 | -# code = 'TABS' | 468 | +code = 'TABS' |
| 469 | -# include_patterns = ['**'] | 469 | +include_patterns = ['**'] |
| 470 | -# exclude_patterns = [ | 470 | +exclude_patterns = [ |
| 471 | -# '**/*.svg', | 471 | + '**/*.svg', |
| 472 | -# '**/*Makefile', | 472 | + '**/*Makefile', |
| 473 | -# '**/contrib/**', | 473 | + '**/contrib/**', |
| 474 | -# 'third_party/**', | 474 | + 'third_party/**', |
| 475 | -# '**/.gitattributes', | 475 | + '**/.gitattributes', |
| 476 | -# '**/.gitmodules', | 476 | + '**/.gitmodules', |
| 477 | -# 'fb/**', | 477 | + 'fb/**', |
| 478 | -# '**/fb/**', | 478 | + '**/fb/**', |
| 479 | -# 'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h', | 479 | + 'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h', |
| 480 | -# 'test/cpp/jit/upgrader_models/*.ptl', | 480 | + 'test/cpp/jit/upgrader_models/*.ptl', |
| 481 | -# 'test/cpp/jit/upgrader_models/*.ptl.ff', | 481 | + 'test/cpp/jit/upgrader_models/*.ptl.ff', |
| 482 | -# '.ci/docker/common/install_rocm_drm.sh', | 482 | + '.ci/docker/common/install_rocm_drm.sh', |
| 483 | -# '.lintrunner.toml', | 483 | + '.lintrunner.toml', |
| 484 | -# '**/*.patch', | 484 | + '**/*.patch', |
| 485 | -# # NPUGraph logs files | 485 | + # NPUGraph logs files |
| 486 | -# 'torch_npu/_logging/_internal.py', | 486 | + 'torch_npu/_logging/_internal.py', |
| 487 | -# 'torch_npu/csrc/core/npu/NPUGraph.cpp', | 487 | + '**/*.md', |
| 488 | -# 'torch_npu/csrc/core/npu/NPUGraph.h', | 488 | +] |
| 489 | -# 'torch_npu/csrc/npu/Graph.cpp', | 489 | +command = [ |
| 490 | -# 'torch_npu/csrc/core/npu/NPUCachingAllocator.cpp', | 490 | + 'python3', |
| 491 | -# 'torch_npu/csrc/core/npu/NPUWorkspaceAllocator.cpp', | 491 | + 'tools/linter/adapters/grep_linter.py', |
| 492 | -# 'torch_npu/npu/_graph_tree.py', | 492 | + # @lint-ignore TXT2 |
| 493 | -# 'torch_npu/npu/graphs.py', | 493 | + '--pattern= ', |
| 494 | -# 'torch_npu/utils/_graph_tree.py', | 494 | + '--linter-name=TABS', |
| 495 | -# ] | 495 | + '--error-name=saw some tabs', |
| 496 | -# command = [ | 496 | + '--replace-pattern=s/\t/ /', |
| 497 | -# 'python3', | 497 | + """--error-description=\ |
| 498 | -# 'tools/linter/adapters/grep_linter.py', | 498 | + This line has tabs; please replace them with spaces.\ |
| 499 | -# # @lint-ignore TXT2 | 499 | + """, |
| 500 | -# '--pattern= ', | 500 | + '--', |
| 501 | -# '--linter-name=TABS', | 501 | + '@{{PATHSFILE}}' |
| 502 | -# '--error-name=saw some tabs', | 502 | +] |
| 503 | -# '--replace-pattern=s/\t/ /', | ||
| 504 | -# """--error-description=\ | ||
| 505 | -# This line has tabs; please replace them with spaces.\ | ||
| 506 | -# """, | ||
| 507 | -# '--', | ||
| 508 | -# '@{{PATHSFILE}}' | ||
| 509 | -# ] | ||
| 510 | 503 | ||
| 511 | # [[linter]] | 504 | # [[linter]] |
| 512 | # code = 'C10_UNUSED' | 505 | # code = 'C10_UNUSED' |
| @@ -63,8 +63,8 @@ def is_not_compatibility_for_cpp_api(base_signature: str, file: str): | |||
| 63 | subs += line | 63 | subs += line |
| 64 | if ")" in line and "(" not in line and start_concat: | 64 | if ")" in line and "(" not in line and start_concat: |
| 65 | start_concat = False | 65 | start_concat = False |
| 66 | - subs = re.sub("(?<=\\()[ \n]+", "", subs) | 66 | + subs = re.sub("(?<=\\()[ \n]+", "", subs) |
| 67 | - subs = re.sub("(?<=,)[ \n]+", " ", subs) | 67 | + subs = re.sub("(?<=,)[ \n]+", " ", subs) |
| 68 | line = subs | 68 | line = subs |
| 69 | subs = "" | 69 | subs = "" |
| 70 | if not start_concat: | 70 | if not start_concat: |
| @@ -160,7 +160,7 @@ class TestArgumentHandler(TestCase): | |||
| 160 | 160 | ||
| 161 | self.assertEqual({out.data_ptr()}, argument_handler.dataptrs_written) | 161 | self.assertEqual({out.data_ptr()}, argument_handler.dataptrs_written) |
| 162 | self.assertEqual({out.data_ptr()}, argument_handler.outputs) | 162 | self.assertEqual({out.data_ptr()}, argument_handler.outputs) |
| 163 | - | 163 | + |
| 164 | def test_equal_reads_inputs_but_no_tensor_output_written(self): | 164 | def test_equal_reads_inputs_but_no_tensor_output_written(self): |
| 165 | """Data-reading op with non-tensor output should not record tensor writes.""" | 165 | """Data-reading op with non-tensor output should not record tensor writes.""" |
| 166 | equal_func = torch.ops.aten.equal.default | 166 | equal_func = torch.ops.aten.equal.default |
| @@ -177,7 +177,7 @@ class TestArgumentHandler(TestCase): | |||
| 177 | self.assertEqual(set(), argument_handler.outputs) | 177 | self.assertEqual(set(), argument_handler.outputs) |
| 178 | self.assertTrue(isinstance(out, bool)) | 178 | self.assertTrue(isinstance(out, bool)) |
| 179 | 179 | ||
| 180 | - | 180 | + |
| 181 | class TestRecordStreamHandler(TestCase): | 181 | class TestRecordStreamHandler(TestCase): |
| 182 | def test_erase_stream_removes_recorded_stream(self): | 182 | def test_erase_stream_removes_recorded_stream(self): |
| 183 | """Communication eraseStream should clear the matching recorded stream.""" | 183 | """Communication eraseStream should clear the matching recorded stream.""" |
| @@ -576,8 +576,8 @@ | |||
| 576 | "signature": "(group=None, rebuild_link=True)" | 576 | "signature": "(group=None, rebuild_link=True)" |
| 577 | }, | 577 | }, |
| 578 | "torch_npu.distributed.tensor.experimental.context_parallel": { | 578 | "torch_npu.distributed.tensor.experimental.context_parallel": { |
| 579 | - "signature": "(mesh: torch.distributed.device_mesh.DeviceMesh, *, buffers: Optional[list[torch.Tensor]] = None, buffer_seq_dims: Optional[list[int]] = None, no_restore_buffers: Optional[set[torch.Tensor]] = None) -> collections.abc.Generator[None, None, None]" | 579 | + "signature": "(mesh: torch.distributed.device_mesh.DeviceMesh, *, buffers: Optional[list[torch.Tensor]] = None, buffer_seq_dims: Optional[list[int]] = None, no_restore_buffers: Optional[set[torch.Tensor]] = None) -> collections.abc.Generator[None, None, None]" |
| 580 | - }, | 580 | + }, |
| 581 | "torch_npu.distributed.rpc.options.NPUTensorPipeRpcBackendOptions": { | 581 | "torch_npu.distributed.rpc.options.NPUTensorPipeRpcBackendOptions": { |
| 582 | "signature": "(*, num_worker_threads: int = 16, rpc_timeout: float = 60.0, init_method: str = 'env://', device_maps: Optional[Dict[str, Dict[Union[int, str, torch.device], Union[int, str, torch.device]]]] = None, devices: Optional[List[Union[int, str, torch.device]]] = None, _transports: Optional[List] = None, _channels: Optional[List] = None)" | 582 | "signature": "(*, num_worker_threads: int = 16, rpc_timeout: float = 60.0, init_method: str = 'env://', device_maps: Optional[Dict[str, Dict[Union[int, str, torch.device], Union[int, str, torch.device]]]] = None, devices: Optional[List[Union[int, str, torch.device]]] = None, _transports: Optional[List] = None, _channels: Optional[List] = None)" |
| 583 | }, | 583 | }, |
| @@ -25,8 +25,8 @@ namespace { | |||
| 25 | void apply_cache_op_info(aclrtStream stream, bool enabled) | 25 | void apply_cache_op_info(aclrtStream stream, bool enabled) |
| 26 | { | 26 | { |
| 27 | if (!IsGteCANNVersion("8.5.0", "CANN")) { | 27 | if (!IsGteCANNVersion("8.5.0", "CANN")) { |
| 28 | - return; | 28 | + return; |
| 29 | - } | 29 | + } |
| 30 | aclrtStreamAttrValue val; | 30 | aclrtStreamAttrValue val; |
| 31 | val.cacheOpInfoSwitch = static_cast<uint32_t>(enabled ? 1u : 0u); | 31 | val.cacheOpInfoSwitch = static_cast<uint32_t>(enabled ? 1u : 0u); |
| 32 | int32_t ret = c10_npu::acl::AclrtSetStreamAttribute(stream, aclrtStreamAttr::ACL_STREAM_ATTR_CACHE_OP_INFO, | 32 | int32_t ret = c10_npu::acl::AclrtSetStreamAttribute(stream, aclrtStreamAttr::ACL_STREAM_ATTR_CACHE_OP_INFO, |
| @@ -83,7 +83,7 @@ struct TORCH_NPU_API NPUGraph { | |||
| 83 | void capture_begin( | 83 | void capture_begin( |
| 84 | MempoolId_t pool = {0, 0}, | 84 | MempoolId_t pool = {0, 0}, |
| 85 | aclmdlRICaptureMode capture_mode = aclmdlRICaptureMode::ACL_MODEL_RI_CAPTURE_MODE_GLOBAL, | 85 | aclmdlRICaptureMode capture_mode = aclmdlRICaptureMode::ACL_MODEL_RI_CAPTURE_MODE_GLOBAL, |
| 86 | - bool report_shape = true); | 86 | + bool report_shape = true); |
| 87 | void capture_end(); | 87 | void capture_end(); |
| 88 | void replay(); | 88 | void replay(); |
| 89 | void reset(); | 89 | void reset(); |
| @@ -102,9 +102,9 @@ using ServerProcFn = std::function<StoreMessage(int fd, const StoreMessage &req) | |||
| 102 | class ParallelTcpServer { | 102 | class ParallelTcpServer { |
| 103 | public: | 103 | public: |
| 104 | explicit ParallelTcpServer(uint32_t threadNum, const std::string host, uint16_t port, uint32_t listenThreadNum, | 104 | explicit ParallelTcpServer(uint32_t threadNum, const std::string host, uint16_t port, uint32_t listenThreadNum, |
| 105 | - ServerProcFn process) noexcept; | 105 | + ServerProcFn process) noexcept; |
| 106 | explicit ParallelTcpServer(uint32_t threadNum, const std::string localSocketPath, uint32_t listenThreadNum, | 106 | explicit ParallelTcpServer(uint32_t threadNum, const std::string localSocketPath, uint32_t listenThreadNum, |
| 107 | - ServerProcFn process) noexcept; | 107 | + ServerProcFn process) noexcept; |
| 108 | 108 | ||
| 109 | int Start() noexcept; | 109 | int Start() noexcept; |
| 110 | void Stop() noexcept; | 110 | void Stop() noexcept; |
| @@ -4741,15 +4741,15 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::batch_isend_irecv_inner( | |||
| 4741 | tensors_tmp, | 4741 | tensors_tmp, |
| 4742 | [&](at::Tensor& input, at::Tensor& output, HcclComm comm, c10_npu::NPUStream& stream, std::shared_ptr<bool> is_dispatched) { | 4742 | [&](at::Tensor& input, at::Tensor& output, HcclComm comm, c10_npu::NPUStream& stream, std::shared_ptr<bool> is_dispatched) { |
| 4743 | RECORD_FUNCTION("HcclBatchSendRecv", std::vector<c10::IValue>({input})); | 4743 | RECORD_FUNCTION("HcclBatchSendRecv", std::vector<c10::IValue>({input})); |
| 4744 | - auto itemNum = static_cast<uint32_t>(op_type.size()); | 4744 | + auto itemNum = static_cast<uint32_t>(op_type.size()); |
| 4745 | - std::vector<void *> tensor_ptr_list; | 4745 | + std::vector<void *> tensor_ptr_list; |
| 4746 | - std::vector<uint64_t> numel_list; | 4746 | + std::vector<uint64_t> numel_list; |
| 4747 | - std::vector<HcclDataType> type_list; | 4747 | + std::vector<HcclDataType> type_list; |
| 4748 | - for (size_t i = 0; i < op_type.size(); ++i) { | 4748 | + for (size_t i = 0; i < op_type.size(); ++i) { |
| 4749 | - tensor_ptr_list.push_back(tensors[i].data_ptr()); | 4749 | + tensor_ptr_list.push_back(tensors[i].data_ptr()); |
| 4750 | - numel_list.push_back(getNumelForHCCL(tensors[i])); | 4750 | + numel_list.push_back(getNumelForHCCL(tensors[i])); |
| 4751 | - type_list.push_back(getHcclDataType(tensors[i].scalar_type())); | 4751 | + type_list.push_back(getHcclDataType(tensors[i].scalar_type())); |
| 4752 | - } | 4752 | + } |
| 4753 | 4753 | ||
| 4754 | std::vector<uint32_t> remote_rank_list_cast; | 4754 | std::vector<uint32_t> remote_rank_list_cast; |
| 4755 | remote_rank_list_cast.reserve(remote_rank_list.size()); | 4755 | remote_rank_list_cast.reserve(remote_rank_list.size()); |
| @@ -4761,36 +4761,36 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::batch_isend_irecv_inner( | |||
| 4761 | } | 4761 | } |
| 4762 | remote_rank_list_cast.push_back(static_cast<uint32_t>(remote_rank_list[i])); | 4762 | remote_rank_list_cast.push_back(static_cast<uint32_t>(remote_rank_list[i])); |
| 4763 | } | 4763 | } |
| 4764 | - auto hccl_call = [tensor_ptr_list, numel_list, type_list, remote_rank_list_cast, op_type, itemNum, comm, stream, is_dispatched]() -> int { | 4764 | + auto hccl_call = [tensor_ptr_list, numel_list, type_list, remote_rank_list_cast, op_type, itemNum, comm, stream, is_dispatched]() -> int { |
| 4765 | - HcclSendRecvItem sendRecvInfo[itemNum]; | 4765 | + HcclSendRecvItem sendRecvInfo[itemNum]; |
| 4766 | - HcclSendRecvType currType; | 4766 | + HcclSendRecvType currType; |
| 4767 | - for (size_t i = 0; i < op_type.size(); ++i) { | 4767 | + for (size_t i = 0; i < op_type.size(); ++i) { |
| 4768 | - if (op_type[i] == "isend") { | 4768 | + if (op_type[i] == "isend") { |
| 4769 | - currType = HcclSendRecvType::HCCL_SEND; | 4769 | + currType = HcclSendRecvType::HCCL_SEND; |
| 4770 | - } else if (op_type[i] == "irecv") { | 4770 | + } else if (op_type[i] == "irecv") { |
| 4771 | - currType = HcclSendRecvType::HCCL_RECV; | 4771 | + currType = HcclSendRecvType::HCCL_RECV; |
| 4772 | - } else { | 4772 | + } else { |
| 4773 | - currType = HcclSendRecvType::HCCL_SEND_RECV_RESERVED; | 4773 | + currType = HcclSendRecvType::HCCL_SEND_RECV_RESERVED; |
| 4774 | - } | 4774 | + } |
| 4775 | - sendRecvInfo[i] = HcclSendRecvItem{currType, | 4775 | + sendRecvInfo[i] = HcclSendRecvItem{currType, |
| 4776 | - tensor_ptr_list[i], | 4776 | + tensor_ptr_list[i], |
| 4777 | - numel_list[i], | 4777 | + numel_list[i], |
| 4778 | - type_list[i], | 4778 | + type_list[i], |
| 4779 | - remote_rank_list_cast[i] | 4779 | + remote_rank_list_cast[i] |
| 4780 | - }; | 4780 | + }; |
| 4781 | - } | 4781 | + } |
| 4782 | 4782 | ||
| 4783 | torch_npu::profiler::MstxRange range( | 4783 | torch_npu::profiler::MstxRange range( |
| 4784 | getMstxHcclMsg("HcclBatchSendRecv", sendRecvInfo[0].count, sendRecvInfo[0].dataType, comm, stream.id(), -1, -1), | 4784 | getMstxHcclMsg("HcclBatchSendRecv", sendRecvInfo[0].count, sendRecvInfo[0].dataType, comm, stream.id(), -1, -1), |
| 4785 | stream.stream(false), torch_npu::profiler::DOMAIN_COMMUNICATION); | 4785 | stream.stream(false), torch_npu::profiler::DOMAIN_COMMUNICATION); |
| 4786 | 4786 | ||
| 4787 | - if (c10_npu::is_core_control_enabled()) { | 4787 | + if (c10_npu::is_core_control_enabled()) { |
| 4788 | c10_npu::UseStreamResInCurrentThread(stream.stream(false)); | 4788 | c10_npu::UseStreamResInCurrentThread(stream.stream(false)); |
| 4789 | } | 4789 | } |
| 4790 | auto hccl_result = hcclBatchIsendIrecv(sendRecvInfo, itemNum, comm, stream.stream(false)); | 4790 | auto hccl_result = hcclBatchIsendIrecv(sendRecvInfo, itemNum, comm, stream.stream(false)); |
| 4791 | *is_dispatched = true; | 4791 | *is_dispatched = true; |
| 4792 | return hccl_result; | 4792 | return hccl_result; |
| 4793 | - }; | 4793 | + }; |
| 4794 | at_npu::native::OpCommand::RunOpApiV3("HcclBatchSendRecv", hccl_call, false, &stream); | 4794 | at_npu::native::OpCommand::RunOpApiV3("HcclBatchSendRecv", hccl_call, false, &stream); |
| 4795 | return HCCL_SUCCESS; | 4795 | return HCCL_SUCCESS; |
| 4796 | }, | 4796 | }, |
| @@ -444,7 +444,7 @@ public: | |||
| 444 | std::vector<std::pair<c10::weak_intrusive_ptr<c10::StorageImpl>, c10_npu::NPUStream>> recorded_outputs_; | 444 | std::vector<std::pair<c10::weak_intrusive_ptr<c10::StorageImpl>, c10_npu::NPUStream>> recorded_outputs_; |
| 445 | 445 | ||
| 446 | std::vector<at::Tensor> lazy_destroy_tensors_; | 446 | std::vector<at::Tensor> lazy_destroy_tensors_; |
| 447 | - | 447 | + |
| 448 | std::vector<at::Tensor> stashed_for_allocator_safety_; | 448 | std::vector<at::Tensor> stashed_for_allocator_safety_; |
| 449 | // unique id used to tell the trace buffer that this | 449 | // unique id used to tell the trace buffer that this |
| 450 | // work has completed | 450 | // work has completed |
| @@ -627,14 +627,14 @@ public: | |||
| 627 | const c10d::ReduceOptions& opts = c10d::ReduceOptions()); | 627 | const c10d::ReduceOptions& opts = c10d::ReduceOptions()); |
| 628 | 628 | ||
| 629 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv( | 629 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv( |
| 630 | - std::vector<std::string>& op_type, | 630 | + std::vector<std::string>& op_type, |
| 631 | - std::vector<at::Tensor>& tensors, | 631 | + std::vector<at::Tensor>& tensors, |
| 632 | - std::vector<int64_t> remote_rank_list); | 632 | + std::vector<int64_t> remote_rank_list); |
| 633 | 633 | ||
| 634 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv_inner( | 634 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv_inner( |
| 635 | - std::vector<std::string>& op_type, | 635 | + std::vector<std::string>& op_type, |
| 636 | - std::vector<at::Tensor>& tensors, | 636 | + std::vector<at::Tensor>& tensors, |
| 637 | - std::vector<int64_t> remote_rank_list); | 637 | + std::vector<int64_t> remote_rank_list); |
| 638 | 638 | ||
| 639 | at::Tensor byte_alignment(at::Tensor& tensors) const; | 639 | at::Tensor byte_alignment(at::Tensor& tensors) const; |
| 640 | 640 | ||
| @@ -743,7 +743,7 @@ void TORCH_NPU_API THNPGraph_init(PyObject* module) { | |||
| 743 | [](c10_npu::NPUGraph& self, | 743 | [](c10_npu::NPUGraph& self, |
| 744 | std::optional<c10_npu::MempoolId_t> pool_opt, | 744 | std::optional<c10_npu::MempoolId_t> pool_opt, |
| 745 | std::string capture_error_mode, | 745 | std::string capture_error_mode, |
| 746 | - bool report_shape) { | 746 | + bool report_shape) { |
| 747 | aclmdlRICaptureMode capture_mode; | 747 | aclmdlRICaptureMode capture_mode; |
| 748 | c10_npu::MempoolId_t pool = pool_opt.has_value() | 748 | c10_npu::MempoolId_t pool = pool_opt.has_value() |
| 749 | ? pool_opt.value() : c10_npu::MempoolId_t{0, 0}; | 749 | ? pool_opt.value() : c10_npu::MempoolId_t{0, 0}; |