|
| 1 | +import pytest |
| 2 | +import torch |
| 3 | + |
| 4 | +from . import base, consts |
| 5 | + |
| 6 | + |
| 7 | +def _input_fn_factory(reduce): |
| 8 | + def inner(shape, dtype, device): |
| 9 | + inp = torch.randn(shape, dtype=dtype, device=device) |
| 10 | + dim = -1 |
| 11 | + size_dim = shape[dim] |
| 12 | + index = torch.randint(0, size_dim, shape, dtype=torch.long, device=device) |
| 13 | + src = torch.randn(shape, dtype=dtype, device=device) |
| 14 | + yield inp, dim, index, src, {"reduce": reduce} |
| 15 | + |
| 16 | + return inner |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.scatter_reduce_two_ |
| 20 | +def test_scatter_reduce_two_inplace_sum(): |
| 21 | + bench = base.GenericBenchmark2DOnly( |
| 22 | + op_name="scatter_reduce_.sum", |
| 23 | + torch_op=torch.Tensor.scatter_reduce_, |
| 24 | + input_fn=_input_fn_factory("sum"), |
| 25 | + dtypes=consts.FLOAT_DTYPES, |
| 26 | + inplace=True, |
| 27 | + ) |
| 28 | + bench.run() |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.scatter_reduce_two_ |
| 32 | +def test_scatter_reduce_two_inplace_amax(): |
| 33 | + bench = base.GenericBenchmark2DOnly( |
| 34 | + op_name="scatter_reduce_.amax", |
| 35 | + torch_op=torch.Tensor.scatter_reduce_, |
| 36 | + input_fn=_input_fn_factory("amax"), |
| 37 | + dtypes=consts.FLOAT_DTYPES, |
| 38 | + inplace=True, |
| 39 | + ) |
| 40 | + bench.run() |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.scatter_reduce_two_ |
| 44 | +def test_scatter_reduce_two_inplace_amin(): |
| 45 | + bench = base.GenericBenchmark2DOnly( |
| 46 | + op_name="scatter_reduce_.amin", |
| 47 | + torch_op=torch.Tensor.scatter_reduce_, |
| 48 | + input_fn=_input_fn_factory("amin"), |
| 49 | + dtypes=consts.FLOAT_DTYPES, |
| 50 | + inplace=True, |
| 51 | + ) |
| 52 | + bench.run() |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.scatter_reduce_two_ |
| 56 | +def test_scatter_reduce_two_inplace_mean(): |
| 57 | + bench = base.GenericBenchmark2DOnly( |
| 58 | + op_name="scatter_reduce_.mean", |
| 59 | + torch_op=torch.Tensor.scatter_reduce_, |
| 60 | + input_fn=_input_fn_factory("mean"), |
| 61 | + dtypes=consts.FLOAT_DTYPES, |
| 62 | + inplace=True, |
| 63 | + ) |
| 64 | + bench.run() |
0 commit comments