|
| 1 | +import pytest |
| 2 | +import torch |
| 3 | + |
| 4 | +import flag_gems |
| 5 | + |
| 6 | +from .accuracy_utils import ( |
| 7 | + FLOAT_DTYPES, |
| 8 | + POINTWISE_SHAPES, |
| 9 | + gems_assert_close, |
| 10 | + to_reference, |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +@pytest.mark.rsub_tensor |
| 15 | +@pytest.mark.parametrize("shape", POINTWISE_SHAPES) |
| 16 | +@pytest.mark.parametrize("dtype", FLOAT_DTYPES) |
| 17 | +def test_rsub_tensor(shape, dtype): |
| 18 | + inp1 = torch.randn(shape, dtype=dtype, device=flag_gems.device) |
| 19 | + inp2 = torch.randn(shape, dtype=dtype, device=flag_gems.device) |
| 20 | + ref_inp1 = to_reference(inp1) |
| 21 | + ref_inp2 = to_reference(inp2) |
| 22 | + |
| 23 | + ref_out = torch.rsub(ref_inp1, ref_inp2) |
| 24 | + with flag_gems.use_gems(): |
| 25 | + res_out = torch.rsub(inp1, inp2) |
| 26 | + |
| 27 | + gems_assert_close(res_out, ref_out, dtype) |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.rsub_scalar |
| 31 | +@pytest.mark.parametrize("shape", POINTWISE_SHAPES) |
| 32 | +@pytest.mark.parametrize("dtype", FLOAT_DTYPES) |
| 33 | +def test_rsub_scalar(shape, dtype): |
| 34 | + inp1 = torch.randn(shape, dtype=dtype, device=flag_gems.device) |
| 35 | + ref_inp1 = to_reference(inp1) |
| 36 | + inp2 = 0.5 |
| 37 | + |
| 38 | + ref_out = torch.rsub(ref_inp1, inp2) |
| 39 | + with flag_gems.use_gems(): |
| 40 | + res_out = torch.rsub(inp1, inp2) |
| 41 | + |
| 42 | + gems_assert_close(res_out, ref_out, dtype) |
0 commit comments