已合并
add index_copy.out #2521
zqwen创建于 2025年5月17日
add index_copy.out #2521
已合并
zqwen创建于 2025年5月17日
refs/pull/2521/head合入到master
2 个文件变更+19-1
Mop_plugin/config/op_plugin_functions.yaml+8-0
@@ -2828,6 +2828,14 @@ official:
2828 dtype: self2828 dtype: self
2829 exec: aclnnIndexCopy2829 exec: aclnnIndexCopy
2830 2830 
2831+ - func: index_copy.out(Tensor self, int dim, Tensor index, Tensor source, *, Tensor(a!) out) -> Tensor(a!)
2832+ op_api: all_version
2833+ gen_opapi:
2834+ out:
2835+ size: self
2836+ dtype: self
2837+ exec: aclnnIndexCopy
2838+ 
2831 - func: index_copy_(Tensor(a!) self, int dim, Tensor index, Tensor source) -> Tensor(a!)2839 - func: index_copy_(Tensor(a!) self, int dim, Tensor index, Tensor source) -> Tensor(a!)
2832 acl_op: [v2.0, newest]2840 acl_op: [v2.0, newest]
2833 op_api: [v2.0, newest]2841 op_api: [v2.0, newest]
Mtest/test_base_ops/test_index_copy.py+11-1
@@ -2,7 +2,6 @@ import torch
2import torch_npu2import torch_npu
3 3 
4from torch_npu.testing.testcase import TestCase, run_tests4from torch_npu.testing.testcase import TestCase, run_tests
5-from torch_npu.testing.common_utils import create_common_tensor
6 5 
7 6 
8class TestIndexCopy(TestCase):7class TestIndexCopy(TestCase):
@@ -20,6 +19,14 @@ class TestIndexCopy(TestCase):
20 output = input1.numpy()19 output = input1.numpy()
21 return output20 return output
22 21 
22+ def op_out_exec(self, npuflag, input1, dim, indices, updates):
23+ output = torch.empty_like(input1)
24+ torch.index_copy(input1, dim, indices, updates, out=output)
25+ if npuflag:
26+ output = output.to("cpu")
27+ output = output.numpy()
28+ return output
29+ 
23 def case_exec(self, input1, dim, indices, updates):30 def case_exec(self, input1, dim, indices, updates):
24 npu_input = input1.npu()31 npu_input = input1.npu()
25 npu_indices = indices.npu()32 npu_indices = indices.npu()
@@ -27,6 +34,9 @@ class TestIndexCopy(TestCase):
27 cpu_output = self.op_exec(0, input1, dim, indices, updates)34 cpu_output = self.op_exec(0, input1, dim, indices, updates)
28 npu_output = self.op_exec(1, npu_input, dim, npu_indices, npu_updates)35 npu_output = self.op_exec(1, npu_input, dim, npu_indices, npu_updates)
29 self.assertEqual(cpu_output, npu_output)36 self.assertEqual(cpu_output, npu_output)
37+ cpu_output = self.op_out_exec(0, input1, dim, indices, updates)
38+ npu_output = self.op_out_exec(1, npu_input, dim, npu_indices, npu_updates)
39+ self.assertEqual(cpu_output, npu_output)
30 cpu_output = self.op_inp_exec(0, input1, dim, indices, updates)40 cpu_output = self.op_inp_exec(0, input1, dim, indices, updates)
31 npu_output = self.op_inp_exec(1, npu_input, dim, npu_indices, npu_updates)41 npu_output = self.op_inp_exec(1, npu_input, dim, npu_indices, npu_updates)
32 self.assertEqual(cpu_output, npu_output)42 self.assertEqual(cpu_output, npu_output)