已合并
【fix】batcnnorm_check_fix #36324
cuiduo创建于 5月21日
【fix】batcnnorm_check_fix #36324
已合并
cuiduo创建于 5月21日
4 个文件变更+14-6
Mtest/_inductor/test_run_with_rng_state.py+1-0
@@ -9,6 +9,7 @@ import torch_npu
9import torch_npu._inductor9import torch_npu._inductor
10 10 
11 11 
12+ 
12class TestRunWithRngState(TestUtils):13class TestRunWithRngState(TestUtils):
13 def op_calc(self, current_state, like, device, dtype):14 def op_calc(self, current_state, like, device, dtype):
14 res1 = torch._prims.rng_prims.run_with_rng_state(15 res1 = torch._prims.rng_prims.run_with_rng_state(
Mtorch_npu/_inductor/codegen/wrapper.py+1-2
@@ -2,7 +2,6 @@ import copy
2import hashlib2import hashlib
3import os3import os
4 4 
5-import sympy
6 5 
7import torch6import torch
8import torch_npu.npu.aclnn7import torch_npu.npu.aclnn
@@ -35,7 +34,7 @@ class _NPUKernelCodegenMixin:
35 (AOT debug / aclnn initialization / whole-graph benchmark harness, etc.)34 (AOT debug / aclnn initialization / whole-graph benchmark harness, etc.)
36 from leaking into subgraphs.35 from leaking into subgraphs.
37 """36 """
38- 37+
39 # generate numel expr for range_tree_node38 # generate numel expr for range_tree_node
40 def generate_node_numel_expr(self, kernel_name: str, node, numel_expr):39 def generate_node_numel_expr(self, kernel_name: str, node, numel_expr):
41 expr = f"{kernel_name}_{node.name}_numel"40 expr = f"{kernel_name}_{node.name}_numel"
Mtorch_npu/contrib/module/_batchnorm_with_int32_count.py+5-4
@@ -270,10 +270,7 @@ class FastSyncBatchNorm(_BatchNorm):
270 )270 )
271 271 
272 def forward(self, input1: Tensor) -> Tensor:272 def forward(self, input1: Tensor) -> Tensor:
273- # currently NPU or GPU input1 is supported273+
274- if not input1.is_cuda and not input1.is_npu:
275- raise ValueError("SyncBatchNorm expected input1 tensor to be on NPU or GPU" + ops_error(ErrCode.VALUE))
276- 
277 self._check_input_dim(input1)274 self._check_input_dim(input1)
278 self._check_non_zero_input_channels(input1)275 self._check_non_zero_input_channels(input1)
279 276 
@@ -324,6 +321,10 @@ class FastSyncBatchNorm(_BatchNorm):
324 and torch.distributed.is_initialized()321 and torch.distributed.is_initialized()
325 )322 )
326 if need_sync:323 if need_sync:
324+ # currently NPU or GPU input1 is supported
325+ if not input1.is_cuda and not input1.is_npu:
326+ raise ValueError("SyncBatchNorm expected input1 tensor to be on NPU or GPU" + ops_error(ErrCode.VALUE))
327+ 
327 process_group = torch.distributed.group.WORLD328 process_group = torch.distributed.group.WORLD
328 if self.process_group:329 if self.process_group:
329 process_group = self.process_group330 process_group = self.process_group
Mtorch_npu/multiprocessing/reductions.py+7-0
@@ -12,6 +12,7 @@ from torch.multiprocessing.reductions import (
12 rebuild_tensor,12 rebuild_tensor,
13 storage_from_cache,13 storage_from_cache,
14 rebuild_meta_tensor,14 rebuild_meta_tensor,
15+ reduce_nested_tensor,
15)16)
16 17 
17import torch_npu18import torch_npu
@@ -95,6 +96,12 @@ def rebuild_npu_tensor(
95 96 
96 97 
97def _npu_reduce_tensor(tensor):98def _npu_reduce_tensor(tensor):
99+ from torch.nested._internal.nested_tensor import NestedTensor
100+ 
101+ if tensor.is_nested and not isinstance(tensor, NestedTensor):
102+ return reduce_nested_tensor(tensor)
103+ 
104+ storage = tensor._typed_storage()
98 storage = tensor._typed_storage()105 storage = tensor._typed_storage()
atomgit-bot
atomgit-botatomgit-bot5月21日

🟡 Medium Priority

第 104 行是 PR 新增的行,与第 105 行原有代码完全相同。新增行的赋值结果被第 105 行立即覆盖,属于无意义的死存储(dead store),且表明该行是误加而非有意为之。虽然不影响最终结果,但会引入不必要的计算开销且降低代码可读性。

likedislike
99 106 
100 if tensor.requires_grad and not tensor.is_leaf:107 if tensor.requires_grad and not tensor.is_leaf: