|
21 | 21 | )
|
22 | 22 |
|
23 | 23 | input_t1 = Tuple[torch.Tensor, torch.Tensor] # Input x, Input y
|
24 |
| -aten_op = "torch.ops.aten.repeat.default" |
25 | 24 |
|
26 | 25 |
|
27 | 26 | """Tests Tensor.repeat for different ranks and dimensions."""
|
28 | 27 |
|
29 | 28 |
|
30 | 29 | class Repeat(torch.nn.Module):
|
31 |
| - # (input tensor, multiples) |
32 |
| - test_parameters = { |
33 |
| - "1_x_1": lambda: (torch.randn(3), (2,)), |
34 |
| - "2_x_2": lambda: (torch.randn(3, 4), (2, 1)), |
35 |
| - "4_x_4": lambda: (torch.randn(1, 1, 2, 2), (1, 2, 3, 4)), |
36 |
| - "1_x_2": lambda: (torch.randn(3), (2, 2)), |
37 |
| - "1_x_3": lambda: (torch.randn(3), (1, 2, 3)), |
38 |
| - "2_x_3": lambda: (torch.randn((3, 3)), (2, 2, 2)), |
39 |
| - "1_x_4": lambda: (torch.randn((3, 3, 3)), (2, 1, 2, 4)), |
40 |
| - } |
41 |
| - |
42 |
| - def forward(self, x: torch.Tensor, multiples: Sequence): |
43 |
| - return x.repeat(multiples) |
44 |
| - |
45 |
| - |
46 |
| -@common.parametrize("test_data", Repeat.test_parameters) |
| 30 | + aten_op = "torch.ops.aten.repeat.default" |
| 31 | + |
| 32 | + def __init__(self, multiples: Sequence[int]): |
| 33 | + super().__init__() |
| 34 | + self.multiples = multiples |
| 35 | + |
| 36 | + def forward(self, x: torch.Tensor): |
| 37 | + return x.repeat(self.multiples) |
| 38 | + |
| 39 | + |
| 40 | +class RepeatInterleaveInt(torch.nn.Module): |
| 41 | + aten_op = "torch.ops.aten.repeat_interleave.self_int" |
| 42 | + |
| 43 | + def __init__(self, repeats: int, dim: int): |
| 44 | + super().__init__() |
| 45 | + self.repeats = repeats |
| 46 | + self.dim = dim |
| 47 | + |
| 48 | + def forward(self, x: torch.Tensor): |
| 49 | + return x.repeat_interleave(self.repeats, self.dim) |
| 50 | + |
| 51 | + |
| 52 | +test_data_suite = { |
| 53 | + # test_name : lambda: (module, test_data) |
| 54 | + "1_x_1": lambda: (Repeat((2,)), (torch.randn(3),)), |
| 55 | + "2_x_2": lambda: (Repeat((2, 1)), (torch.randn(3, 4),)), |
| 56 | + "4_x_4": lambda: (Repeat((1, 2, 3, 4)), (torch.randn(1, 1, 2, 2),)), |
| 57 | + "1_x_2": lambda: (Repeat((2, 2)), (torch.randn(3),)), |
| 58 | + "1_x_3": lambda: (Repeat((1, 2, 3)), (torch.randn(3),)), |
| 59 | + "2_x_3": lambda: (Repeat((2, 2, 2)), (torch.randn((3, 3)),)), |
| 60 | + "1_x_4": lambda: (Repeat((2, 1, 2, 4)), (torch.randn((3, 3, 3)),)), |
| 61 | + "interleave_int_3_x_1": lambda: (RepeatInterleaveInt(3, 1), (torch.randn(3, 4),)), |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +@common.parametrize("test_data", test_data_suite) |
47 | 66 | def test_repeat_tosa_MI(test_data: Tuple):
|
| 67 | + module, test_data = test_data() |
48 | 68 | pipeline = TosaPipelineMI[input_t1](
|
49 |
| - Repeat(), |
50 |
| - test_data(), |
51 |
| - aten_op, |
| 69 | + module, |
| 70 | + test_data, |
| 71 | + module.aten_op, |
52 | 72 | exir_op=[],
|
53 | 73 | )
|
54 | 74 | pipeline.run()
|
55 | 75 |
|
56 | 76 |
|
57 |
| -@common.parametrize("test_data", Repeat.test_parameters) |
| 77 | +@common.parametrize("test_data", test_data_suite) |
58 | 78 | def test_repeat_tosa_BI(test_data: Tuple):
|
| 79 | + module, test_data = test_data() |
59 | 80 | pipeline = TosaPipelineBI[input_t1](
|
60 |
| - Repeat(), |
61 |
| - test_data(), |
62 |
| - aten_op, |
| 81 | + module, |
| 82 | + test_data, |
| 83 | + module.aten_op, |
63 | 84 | exir_op=[],
|
64 | 85 | )
|
65 | 86 | pipeline.run()
|
66 | 87 |
|
67 | 88 |
|
68 |
| -@common.parametrize("test_data", Repeat.test_parameters) |
| 89 | +@common.parametrize("test_data", test_data_suite) |
69 | 90 | def test_repeat_u55_BI(test_data: Tuple):
|
| 91 | + module, test_data = test_data() |
70 | 92 | pipeline = EthosU55PipelineBI[input_t1](
|
71 |
| - Repeat(), |
72 |
| - test_data(), |
73 |
| - aten_op, |
| 93 | + module, |
| 94 | + test_data, |
| 95 | + module.aten_op, |
74 | 96 | exir_ops=[],
|
75 | 97 | run_on_fvp=False,
|
76 | 98 | )
|
77 | 99 | pipeline.run()
|
78 | 100 |
|
79 | 101 |
|
80 |
| -@common.parametrize("test_data", Repeat.test_parameters) |
| 102 | +@common.parametrize("test_data", test_data_suite) |
81 | 103 | def test_repeat_u85_BI(test_data: Tuple):
|
| 104 | + module, test_data = test_data() |
82 | 105 | pipeline = EthosU85PipelineBI[input_t1](
|
83 |
| - Repeat(), |
84 |
| - test_data(), |
85 |
| - aten_op, |
| 106 | + module, |
| 107 | + test_data, |
| 108 | + module.aten_op, |
86 | 109 | exir_ops=[],
|
87 | 110 | run_on_fvp=False,
|
88 | 111 | )
|
|
0 commit comments