MCPcopy Create free account
hub / github.com/apache/tvm / test_softplus

Function test_softplus

tests/python/relax/test_frontend_from_exported_program.py:885–929  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

883
884
885def 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
932def test_leakyrelu():

Callers

nothing calls this directly

Calls 3

verify_modelFunction · 0.70
Softplus0Class · 0.70
Softplus1Class · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…