已合并
[v2.9.0][Fix] Fix static check errors detected by TABS #37946
thickhair创建于 6月9日
[v2.9.0][Fix] Fix static check errors detected by TABS #37946
已合并
共 9 个文件变更+92-101
| @@ -457,50 +457,41 @@ command = [ | |||
| 457 | '@{{PATHSFILE}}' | 457 | '@{{PATHSFILE}}' |
| 458 | ] | 458 | ] |
| 459 | 459 | ||
| 460 | -# [[linter]] | 460 | +[[linter]] |
| 461 | -# code = 'TABS' | 461 | +code = 'TABS' |
| 462 | -# include_patterns = ['**'] | 462 | +include_patterns = ['**'] |
| 463 | -# exclude_patterns = [ | 463 | +exclude_patterns = [ |
| 464 | -# 'test_upstream/**', | 464 | + 'test_upstream/**', |
| 465 | -# '**/*.svg', | 465 | + '**/*.svg', |
| 466 | -# '**/*Makefile', | 466 | + '**/*Makefile', |
| 467 | -# '**/contrib/**', | 467 | + '**/contrib/**', |
| 468 | -# 'third_party/**', | 468 | + 'third_party/**', |
| 469 | -# '**/.gitattributes', | 469 | + '**/.gitattributes', |
| 470 | -# '**/.gitmodules', | 470 | + '**/.gitmodules', |
| 471 | -# 'fb/**', | 471 | + 'fb/**', |
| 472 | -# '**/fb/**', | 472 | + '**/fb/**', |
| 473 | -# 'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h', | 473 | + 'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h', |
| 474 | -# 'test/cpp/jit/upgrader_models/*.ptl', | 474 | + 'test/cpp/jit/upgrader_models/*.ptl', |
| 475 | -# 'test/cpp/jit/upgrader_models/*.ptl.ff', | 475 | + 'test/cpp/jit/upgrader_models/*.ptl.ff', |
| 476 | -# '.ci/docker/common/install_rocm_drm.sh', | 476 | + '.ci/docker/common/install_rocm_drm.sh', |
| 477 | -# '.lintrunner.toml', | 477 | + '.lintrunner.toml', |
| 478 | -# '**/*.patch', | 478 | + '**/*.patch', |
| 479 | -# # NPUGraph logs files | 479 | + '**/*.md', |
| 480 | -# 'torch_npu/_logging/_internal.py', | 480 | +] |
| 481 | -# 'torch_npu/csrc/core/npu/NPUGraph.cpp', | 481 | +command = [ |
| 482 | -# 'torch_npu/csrc/core/npu/NPUGraph.h', | 482 | + 'python3', |
| 483 | -# 'torch_npu/csrc/npu/Graph.cpp', | 483 | + 'tools/linter/adapters/grep_linter.py', |
| 484 | -# 'torch_npu/csrc/core/npu/NPUCachingAllocator.cpp', | 484 | + # @lint-ignore TXT2 |
| 485 | -# 'torch_npu/csrc/core/npu/NPUWorkspaceAllocator.cpp', | 485 | + '--pattern= ', |
| 486 | -# 'torch_npu/npu/_graph_tree.py', | 486 | + '--linter-name=TABS', |
| 487 | -# 'torch_npu/npu/graphs.py', | 487 | + '--error-name=saw some tabs', |
| 488 | -# 'torch_npu/utils/_graph_tree.py', | 488 | + '--replace-pattern=s/\t/ /', |
| 489 | -# ] | 489 | + """--error-description=\ |
| 490 | -# command = [ | 490 | + This line has tabs; please replace them with spaces.\ |
| 491 | -# 'python3', | 491 | + """, |
| 492 | -# 'tools/linter/adapters/grep_linter.py', | 492 | + '--', |
| 493 | -# # @lint-ignore TXT2 | 493 | + '@{{PATHSFILE}}' |
| 494 | -# '--pattern= ', | 494 | +] |
| 495 | -# '--linter-name=TABS', | ||
| 496 | -# '--error-name=saw some tabs', | ||
| 497 | -# '--replace-pattern=s/\t/ /', | ||
| 498 | -# """--error-description=\ | ||
| 499 | -# This line has tabs; please replace them with spaces.\ | ||
| 500 | -# """, | ||
| 501 | -# '--', | ||
| 502 | -# '@{{PATHSFILE}}' | ||
| 503 | -# ] | ||
| 504 | 495 | ||
| 505 | # [[linter]] | 496 | # [[linter]] |
| 506 | # code = 'C10_UNUSED' | 497 | # 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: |
| @@ -84,8 +84,8 @@ anir_config.GENERATE_LIST = [ | |||
| 84 | aten.reshape, | 84 | aten.reshape, |
| 85 | # aten.clone, | 85 | # aten.clone, |
| 86 | aten.lift_fresh_copy, | 86 | aten.lift_fresh_copy, |
| 87 | - aten.lift_fresh_copy.default, | 87 | + aten.lift_fresh_copy.default, |
| 88 | - triton_kernel_wrapper_mutation, | 88 | + triton_kernel_wrapper_mutation, |
| 89 | ] | 89 | ] |
| 90 | 90 | ||
| 91 | 91 | ||
| @@ -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; |
| @@ -4773,15 +4773,15 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::batch_isend_irecv_inner( | |||
| 4773 | tensors_tmp, | 4773 | tensors_tmp, |
| 4774 | [&](at::Tensor& input, at::Tensor& output, HcclComm comm, c10_npu::NPUStream& stream, std::shared_ptr<bool> is_dispatched) { | 4774 | [&](at::Tensor& input, at::Tensor& output, HcclComm comm, c10_npu::NPUStream& stream, std::shared_ptr<bool> is_dispatched) { |
| 4775 | RECORD_FUNCTION("HcclBatchSendRecv", std::vector<c10::IValue>({input})); | 4775 | RECORD_FUNCTION("HcclBatchSendRecv", std::vector<c10::IValue>({input})); |
| 4776 | - auto itemNum = static_cast<uint32_t>(op_type.size()); | 4776 | + auto itemNum = static_cast<uint32_t>(op_type.size()); |
| 4777 | - std::vector<void *> tensor_ptr_list; | 4777 | + std::vector<void *> tensor_ptr_list; |
| 4778 | - std::vector<uint64_t> numel_list; | 4778 | + std::vector<uint64_t> numel_list; |
| 4779 | - std::vector<HcclDataType> type_list; | 4779 | + std::vector<HcclDataType> type_list; |
| 4780 | - for (size_t i = 0; i < op_type.size(); ++i) { | 4780 | + for (size_t i = 0; i < op_type.size(); ++i) { |
| 4781 | - tensor_ptr_list.push_back(tensors[i].data_ptr()); | 4781 | + tensor_ptr_list.push_back(tensors[i].data_ptr()); |
| 4782 | - numel_list.push_back(getNumelForHCCL(tensors[i])); | 4782 | + numel_list.push_back(getNumelForHCCL(tensors[i])); |
| 4783 | - type_list.push_back(getHcclDataType(tensors[i].scalar_type())); | 4783 | + type_list.push_back(getHcclDataType(tensors[i].scalar_type())); |
| 4784 | - } | 4784 | + } |
| 4785 | 4785 | ||
| 4786 | std::vector<uint32_t> remote_rank_list_cast; | 4786 | std::vector<uint32_t> remote_rank_list_cast; |
| 4787 | remote_rank_list_cast.reserve(remote_rank_list.size()); | 4787 | remote_rank_list_cast.reserve(remote_rank_list.size()); |
| @@ -4793,36 +4793,36 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::batch_isend_irecv_inner( | |||
| 4793 | } | 4793 | } |
| 4794 | remote_rank_list_cast.push_back(static_cast<uint32_t>(remote_rank_list[i])); | 4794 | remote_rank_list_cast.push_back(static_cast<uint32_t>(remote_rank_list[i])); |
| 4795 | } | 4795 | } |
| 4796 | - auto hccl_call = [tensor_ptr_list, numel_list, type_list, remote_rank_list_cast, op_type, itemNum, comm, stream, is_dispatched]() -> int { | 4796 | + auto hccl_call = [tensor_ptr_list, numel_list, type_list, remote_rank_list_cast, op_type, itemNum, comm, stream, is_dispatched]() -> int { |
| 4797 | - HcclSendRecvItem sendRecvInfo[itemNum]; | 4797 | + HcclSendRecvItem sendRecvInfo[itemNum]; |
| 4798 | - HcclSendRecvType currType; | 4798 | + HcclSendRecvType currType; |
| 4799 | - for (size_t i = 0; i < op_type.size(); ++i) { | 4799 | + for (size_t i = 0; i < op_type.size(); ++i) { |
| 4800 | - if (op_type[i] == "isend") { | 4800 | + if (op_type[i] == "isend") { |
| 4801 | - currType = HcclSendRecvType::HCCL_SEND; | 4801 | + currType = HcclSendRecvType::HCCL_SEND; |
| 4802 | - } else if (op_type[i] == "irecv") { | 4802 | + } else if (op_type[i] == "irecv") { |
| 4803 | - currType = HcclSendRecvType::HCCL_RECV; | 4803 | + currType = HcclSendRecvType::HCCL_RECV; |
| 4804 | - } else { | 4804 | + } else { |
| 4805 | - currType = HcclSendRecvType::HCCL_SEND_RECV_RESERVED; | 4805 | + currType = HcclSendRecvType::HCCL_SEND_RECV_RESERVED; |
| 4806 | - } | 4806 | + } |
| 4807 | - sendRecvInfo[i] = HcclSendRecvItem{currType, | 4807 | + sendRecvInfo[i] = HcclSendRecvItem{currType, |
| 4808 | - tensor_ptr_list[i], | 4808 | + tensor_ptr_list[i], |
| 4809 | - numel_list[i], | 4809 | + numel_list[i], |
| 4810 | - type_list[i], | 4810 | + type_list[i], |
| 4811 | - remote_rank_list_cast[i] | 4811 | + remote_rank_list_cast[i] |
| 4812 | - }; | 4812 | + }; |
| 4813 | - } | 4813 | + } |
| 4814 | 4814 | ||
| 4815 | torch_npu::profiler::MstxRange range( | 4815 | torch_npu::profiler::MstxRange range( |
| 4816 | getMstxHcclMsg("HcclBatchSendRecv", sendRecvInfo[0].count, sendRecvInfo[0].dataType, comm, stream.id(), -1, -1), | 4816 | getMstxHcclMsg("HcclBatchSendRecv", sendRecvInfo[0].count, sendRecvInfo[0].dataType, comm, stream.id(), -1, -1), |
| 4817 | stream.stream(false), torch_npu::profiler::DOMAIN_COMMUNICATION); | 4817 | stream.stream(false), torch_npu::profiler::DOMAIN_COMMUNICATION); |
| 4818 | 4818 | ||
| 4819 | - if (c10_npu::is_core_control_enabled()) { | 4819 | + if (c10_npu::is_core_control_enabled()) { |
| 4820 | c10_npu::UseStreamResInCurrentThread(stream.stream(false)); | 4820 | c10_npu::UseStreamResInCurrentThread(stream.stream(false)); |
| 4821 | } | 4821 | } |
| 4822 | auto hccl_result = hcclBatchIsendIrecv(sendRecvInfo, itemNum, comm, stream.stream(false)); | 4822 | auto hccl_result = hcclBatchIsendIrecv(sendRecvInfo, itemNum, comm, stream.stream(false)); |
| 4823 | *is_dispatched = true; | 4823 | *is_dispatched = true; |
| 4824 | return hccl_result; | 4824 | return hccl_result; |
| 4825 | - }; | 4825 | + }; |
| 4826 | at_npu::native::OpCommand::RunOpApiV3("HcclBatchSendRecv", hccl_call, false, &stream); | 4826 | at_npu::native::OpCommand::RunOpApiV3("HcclBatchSendRecv", hccl_call, false, &stream); |
| 4827 | return HCCL_SUCCESS; | 4827 | return HCCL_SUCCESS; |
| 4828 | }, | 4828 | }, |
| @@ -6656,8 +6656,8 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::scatter( | |||
| 6656 | torch_npu::profiler::DOMAIN_COMMUNICATION); | 6656 | torch_npu::profiler::DOMAIN_COMMUNICATION); |
| 6657 | 6657 | ||
| 6658 | if (c10_npu::is_core_control_enabled()) { | 6658 | if (c10_npu::is_core_control_enabled()) { |
| 6659 | - c10_npu::UseStreamResInCurrentThread(stream.stream(false)); | 6659 | + c10_npu::UseStreamResInCurrentThread(stream.stream(false)); |
| 6660 | - } | 6660 | + } |
| 6661 | auto hccl_result = hcclScatter(inputDataPtr, outputDataPtr, numel, hcclType, root, comm, stream.stream(false)); | 6661 | auto hccl_result = hcclScatter(inputDataPtr, outputDataPtr, numel, hcclType, root, comm, stream.stream(false)); |
| 6662 | *is_dispatched = true; | 6662 | *is_dispatched = true; |
| 6663 | return hccl_result; | 6663 | return hccl_result; |
| @@ -7230,8 +7230,8 @@ c10::intrusive_ptr<c10d::Work> ProcessGroupHCCL::alltoall( | |||
| 7230 | stream.stream(false), torch_npu::profiler::DOMAIN_COMMUNICATION); | 7230 | stream.stream(false), torch_npu::profiler::DOMAIN_COMMUNICATION); |
| 7231 | 7231 | ||
| 7232 | if (c10_npu::is_core_control_enabled()) { | 7232 | if (c10_npu::is_core_control_enabled()) { |
| 7233 | - c10_npu::UseStreamResInCurrentThread(stream.stream(false)); | 7233 | + c10_npu::UseStreamResInCurrentThread(stream.stream(false)); |
| 7234 | - } | 7234 | + } |
| 7235 | auto hccl_result = hcclAlltoAllV( | 7235 | auto hccl_result = hcclAlltoAllV( |
| 7236 | inputDataPtr, | 7236 | inputDataPtr, |
| 7237 | input_counts.data(), | 7237 | input_counts.data(), |
| @@ -634,14 +634,14 @@ public: | |||
| 634 | const c10d::ReduceOptions& opts = c10d::ReduceOptions()); | 634 | const c10d::ReduceOptions& opts = c10d::ReduceOptions()); |
| 635 | 635 | ||
| 636 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv( | 636 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv( |
| 637 | - std::vector<std::string>& op_type, | 637 | + std::vector<std::string>& op_type, |
| 638 | - std::vector<at::Tensor>& tensors, | 638 | + std::vector<at::Tensor>& tensors, |
| 639 | - std::vector<int64_t> remote_rank_list); | 639 | + std::vector<int64_t> remote_rank_list); |
| 640 | 640 | ||
| 641 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv_inner( | 641 | c10::intrusive_ptr<c10d::Work> batch_isend_irecv_inner( |
| 642 | - std::vector<std::string>& op_type, | 642 | + std::vector<std::string>& op_type, |
| 643 | - std::vector<at::Tensor>& tensors, | 643 | + std::vector<at::Tensor>& tensors, |
| 644 | - std::vector<int64_t> remote_rank_list); | 644 | + std::vector<int64_t> remote_rank_list); |
| 645 | 645 | ||
| 646 | at::Tensor byte_alignment(at::Tensor& tensors) const; | 646 | at::Tensor byte_alignment(at::Tensor& tensors) const; |
| 647 | 647 | ||
| @@ -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}; |
| @@ -76,20 +76,20 @@ def _add_op_to_meta_table(op, fn, avoid_fallback_flag=False, inductor_decomp=Fal | |||
| 76 | if avoid_fallback_flag: | 76 | if avoid_fallback_flag: |
| 77 | avoid_make_fallback_table.append(op_overload) | 77 | avoid_make_fallback_table.append(op_overload) |
| 78 | if inductor_decomp: | 78 | if inductor_decomp: |
| 79 | - inductor_decomp_table.append(op_overload) | 79 | + inductor_decomp_table.append(op_overload) |
| 80 | 80 | ||
| 81 | 81 | ||
| 82 | def patch_torch_inductor_decompositions(): | 82 | def patch_torch_inductor_decompositions(): |
| 83 | - ''' | 83 | + ''' |
| 84 | - TorchInductor traces compiled backward with its own decomposition table. | 84 | + TorchInductor traces compiled backward with its own decomposition table. |
| 85 | - Only patch ops that explicitly opted in via inductor_decomp=True so we | 85 | + Only patch ops that explicitly opted in via inductor_decomp=True so we |
| 86 | - don't accidentally overwrite unrelated inductor decompositions. | 86 | + don't accidentally overwrite unrelated inductor decompositions. |
| 87 | - ''' | 87 | + ''' |
| 88 | - import torch._inductor.decomposition as inductor_decomposition | 88 | + import torch._inductor.decomposition as inductor_decomposition |
| 89 | 89 | ||
| 90 | - for op_overload in inductor_decomp_table: | 90 | + for op_overload in inductor_decomp_table: |
| 91 | - if op_overload in npu_meta_table: | 91 | + if op_overload in npu_meta_table: |
| 92 | - inductor_decomposition.decompositions[op_overload] = npu_meta_table[op_overload] | 92 | + inductor_decomposition.decompositions[op_overload] = npu_meta_table[op_overload] |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | def patch_torch_decomp_decompositions(): | 95 | def patch_torch_decomp_decompositions(): |