|
| 1 | +import pytest |
| 2 | +import torch |
| 3 | + |
| 4 | +from benchmark.attri_util import FLOAT_DTYPES |
| 5 | +from benchmark.performance_utils import GenericBenchmark, generate_tensor_input |
| 6 | + |
| 7 | + |
| 8 | +class RepeatInterleaveBenchmark(GenericBenchmark): |
| 9 | + """ |
| 10 | + Due to potential memory limitations, benchmark sizes need to be carefully controlled. |
| 11 | +
|
| 12 | + Notably, when the input size is set to (1024, 1024, 1024) and the repeat dimensions |
| 13 | + are set to [1, 1, 2], the system encountered an "illegal memory access" error. |
| 14 | + To avoid such issues, we constrain the benchmark input sizes for these operations |
| 15 | + to prevent excessive memory usage. |
| 16 | + """ |
| 17 | + |
| 18 | + def set_more_shapes(self): |
| 19 | + return [ |
| 20 | + (16, 256, 256), |
| 21 | + (512, 512, 512), |
| 22 | + (64, 64, 64, 64), |
| 23 | + ] |
| 24 | + |
| 25 | + |
| 26 | +# repeat_interleave.self_int(Tensor self, SymInt repeats, int? dim=None, *, SymInt? output_size=None) -> Tensor |
| 27 | +def repeat_interleave_self_int_input_fn(shape, dtype, device): |
| 28 | + inp = generate_tensor_input(shape, dtype, device) |
| 29 | + repeats = 3 |
| 30 | + yield inp, repeats, |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.repeat_interleave |
| 34 | +def test_repeat_interleave_self_int(): |
| 35 | + bench = RepeatInterleaveBenchmark( |
| 36 | + input_fn=repeat_interleave_self_int_input_fn, |
| 37 | + op_name="repeat_interleave.self_int", |
| 38 | + torch_op=torch.repeat_interleave, |
| 39 | + dtypes=FLOAT_DTYPES, |
| 40 | + ) |
| 41 | + bench.run() |
| 42 | + |
| 43 | + |
| 44 | +# repeat_interleave.self_Tensor(Tensor self, Tensor repeats, int? dim=None, *, SymInt? output_size=None) -> Tensor |
| 45 | +def repeat_interleave_self_tensor_input_fn(shape, dtype, device): |
| 46 | + inp = generate_tensor_input(shape, dtype, device) |
| 47 | + repeats = torch.randint( |
| 48 | + low=0, |
| 49 | + high=0x1F, # control the repeats number here |
| 50 | + size=[ |
| 51 | + shape[0], |
| 52 | + ], |
| 53 | + device=device, |
| 54 | + ) |
| 55 | + dim = 0 |
| 56 | + yield inp, repeats, dim |
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.skip(reason="This test case runs out of memory: issue #2674") |
| 60 | +@pytest.mark.repeat_interleave |
| 61 | +def test_repeat_interleave_self_tensor(): |
| 62 | + bench = RepeatInterleaveBenchmark( |
| 63 | + op_name="repeat_interleave.self_tensor", |
| 64 | + input_fn=repeat_interleave_self_tensor_input_fn, |
| 65 | + torch_op=torch.repeat_interleave, |
| 66 | + dtypes=[torch.int32], |
| 67 | + ) |
| 68 | + bench.run() |
| 69 | + |
| 70 | + |
| 71 | +# repeat_interleave.Tensor(Tensor repeats, *, SymInt? output_size=None) -> Tensor |
| 72 | +def repeat_interleave_tensor_input_fn(shape, dtype, device): |
| 73 | + repeats = torch.randint( |
| 74 | + low=0, |
| 75 | + high=0x1F, # control the repeats number here |
| 76 | + size=[ |
| 77 | + shape[0], |
| 78 | + ], |
| 79 | + device=device, |
| 80 | + ) |
| 81 | + yield repeats, |
| 82 | + |
| 83 | + |
| 84 | +@pytest.mark.skip(reason="This test case runs out of memory: issue #2674") |
| 85 | +@pytest.mark.repeat_interleave |
| 86 | +def test_repeat_interleave_tensor(): |
| 87 | + bench = RepeatInterleaveBenchmark( |
| 88 | + op_name="repeat_interleave.tensor", |
| 89 | + input_fn=repeat_interleave_tensor_input_fn, |
| 90 | + torch_op=torch.repeat_interleave, |
| 91 | + dtypes=[torch.int32], |
| 92 | + ) |
| 93 | + |
| 94 | + bench.run() |
0 commit comments