|
| 1 | +import infini.ops |
| 2 | +import pytest |
| 3 | +import torch |
| 4 | + |
| 5 | +from tests.utils import Payload, empty_strided, get_stream, randn_strided |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.auto_act_and_assert |
| 9 | +@pytest.mark.parametrize( |
| 10 | + "shape, input_strides, out_strides, inplace", |
| 11 | + ( |
| 12 | + ((13, 4), None, None, False), |
| 13 | + ((13, 4), None, None, True), |
| 14 | + ((13, 4), (10, 1), (10, 1), False), |
| 15 | + ((13, 4), (0, 1), None, False), |
| 16 | + ((13, 4, 4), None, None, False), |
| 17 | + ((13, 4, 4), None, None, True), |
| 18 | + ((13, 4, 4), (20, 4, 1), (20, 4, 1), False), |
| 19 | + ((13, 4, 4), (4, 0, 1), None, False), |
| 20 | + ((16, 5632), None, None, False), |
| 21 | + ((16, 5632), None, None, True), |
| 22 | + ((16, 5632), (13312, 1), (13312, 1), False), |
| 23 | + ((4, 4, 5632), None, None, False), |
| 24 | + ((4, 4, 5632), None, None, True), |
| 25 | + ((4, 4, 5632), (45056, 5632, 1), (45056, 5632, 1), False), |
| 26 | + ((4, 4, 56320), None, None, False), |
| 27 | + ), |
| 28 | +) |
| 29 | +@pytest.mark.parametrize( |
| 30 | + ("dtype", "rtol", "atol"), |
| 31 | + ( |
| 32 | + (torch.float32, 1e-7, 1e-7), |
| 33 | + (torch.float16, 1e-3, 1e-3), |
| 34 | + (torch.bfloat16, 1e-2, 1e-2), |
| 35 | + ), |
| 36 | +) |
| 37 | +def test_sigmoid_infinilm( |
| 38 | + shape, input_strides, out_strides, inplace, dtype, device, rtol, atol |
| 39 | +): |
| 40 | + input = randn_strided(shape, input_strides, dtype=dtype, device=device) |
| 41 | + out = ( |
| 42 | + input |
| 43 | + if inplace |
| 44 | + else empty_strided(shape, out_strides, dtype=dtype, device=device) |
| 45 | + ) |
| 46 | + |
| 47 | + return Payload( |
| 48 | + _sigmoid_infinilm, |
| 49 | + _torch_sigmoid_infinilm, |
| 50 | + (input, out), |
| 51 | + {}, |
| 52 | + rtol=rtol, |
| 53 | + atol=atol, |
| 54 | + ) |
| 55 | + |
| 56 | + |
| 57 | +def _sigmoid_infinilm(input, out): |
| 58 | + infini.ops.sigmoid_infinilm(input, out, stream=get_stream(input.device)) |
| 59 | + |
| 60 | + return out |
| 61 | + |
| 62 | + |
| 63 | +def _torch_sigmoid_infinilm(input, out): |
| 64 | + torch.sigmoid(input, out=out) |
| 65 | + |
| 66 | + return out |
0 commit comments