()
| 883 | |
| 884 | |
| 885 | def test_softplus(): |
| 886 | import torch |
| 887 | from torch.nn import Module |
| 888 | |
| 889 | torch.set_grad_enabled(False) |
| 890 | |
| 891 | class Softplus0(torch.nn.Module): |
| 892 | def __init__(self): |
| 893 | super().__init__() |
| 894 | self.softplus = torch.nn.Softplus(1.0, 20.0) |
| 895 | |
| 896 | def forward(self, x): |
| 897 | return self.softplus(x) |
| 898 | |
| 899 | class Softplus1(Module): |
| 900 | def forward(self, input): |
| 901 | return torch.nn.functional.softplus(input, 1.0, 20.0) |
| 902 | |
| 903 | @tvm.script.ir_module |
| 904 | class expected: |
| 905 | @R.function |
| 906 | def main(x: R.Tensor((1, 3, 10, 10), dtype="float32")) -> R.Tuple( |
| 907 | R.Tensor((1, 3, 10, 10), dtype="float32") |
| 908 | ): |
| 909 | with R.dataflow(): |
| 910 | lv: R.Tensor((1, 3, 10, 10), dtype="float32") = R.multiply( |
| 911 | x, R.const(1.0, "float32") |
| 912 | ) |
| 913 | lv1: R.Tensor((1, 3, 10, 10), dtype="float32") = R.exp(lv) |
| 914 | lv2: R.Tensor((1, 3, 10, 10), dtype="float32") = R.add(lv1, R.const(1.0, "float32")) |
| 915 | lv3: R.Tensor((1, 3, 10, 10), dtype="float32") = R.log(lv2) |
| 916 | lv4: R.Tensor((1, 3, 10, 10), dtype="float32") = R.divide( |
| 917 | lv3, R.const(1.0, "float32") |
| 918 | ) |
| 919 | lv5: R.Tensor((1, 3, 10, 10), dtype="bool") = R.greater( |
| 920 | lv, R.const(20.0, "float32") |
| 921 | ) |
| 922 | lv6: R.Tensor((1, 3, 10, 10), dtype="float32") = R.where(lv5, x, lv4) |
| 923 | gv: R.Tuple(R.Tensor((1, 3, 10, 10), dtype="float32")) = (lv6,) |
| 924 | R.output(gv) |
| 925 | return gv |
| 926 | |
| 927 | example_args = (torch.randn(1, 3, 10, 10, dtype=torch.float32),) |
| 928 | verify_model(Softplus0(), example_args, {}, expected) |
| 929 | verify_model(Softplus1(), example_args, {}, expected) |
| 930 | |
| 931 | |
| 932 | def test_leakyrelu(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…