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

Function test_hardtanh

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

Source from the content-addressed store, hash-verified

845
846
847def test_hardtanh():
848 class Hardtanh(torch.nn.Module):
849 def __init__(self):
850 super().__init__()
851 self.ht = torch.nn.Hardtanh()
852
853 def forward(self, input):
854 return self.ht(input)
855
856 class Hardtanh2(torch.nn.Module):
857 def forward(self, input):
858 return torch.nn.functional.hardtanh(input)
859
860 class Hardtanh3(torch.nn.Module):
861 def forward(self, input):
862 return torch.ops.aten.hardtanh_(input)
863
864 @tvm.script.ir_module
865 class expected_for_1_2:
866 @R.function
867 def main(inp_0: R.Tensor((1, 3, 10, 10), dtype="float32")) -> R.Tuple(
868 R.Tensor((1, 3, 10, 10), dtype="float32")
869 ):
870 with R.dataflow():
871 lv: R.Tensor((1, 3, 10, 10), dtype="float32") = R.clip(
872 inp_0, R.prim_value(T.float64(-1.0)), R.prim_value(T.float64(1.0))
873 )
874 gv: R.Tuple(R.Tensor((1, 3, 10, 10), dtype="float32")) = (lv,)
875 R.output(gv)
876 return gv
877
878 example_args = (torch.randn(1, 3, 10, 10, dtype=torch.float32),)
879 verify_model(Hardtanh(), example_args, {}, expected_for_1_2)
880 verify_model(Hardtanh2(), example_args, {}, expected_for_1_2)
881 # In-place hardtanh_ yields the same program; mutation outputs are dropped.
882 verify_model(Hardtanh3(), example_args, {}, expected_for_1_2)
883
884
885def test_softplus():

Callers

nothing calls this directly

Calls 4

Hardtanh3Class · 0.85
verify_modelFunction · 0.70
HardtanhClass · 0.70
Hardtanh2Class · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…