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

Function test_l1_loss

tests/python/relax/test_training_loss.py:39–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37
38
39def test_l1_loss():
40 N = 3
41 C = 5
42 predictions = relax.TensorStructInfo((N, C), "float32")
43 targets = relax.TensorStructInfo((N, C), "float32")
44 l1_loss = relax.training.loss.L1Loss()
45
46 @R.function
47 def expected(
48 predictions: R.Tensor((3, 5), "float32"), targets: R.Tensor((3, 5), "float32")
49 ) -> R.Tensor((), "float32"):
50 R.func_attr({"global_symbol": "l1_loss"})
51 with R.dataflow():
52 lv: R.Tensor((3, 5), "float32") = R.subtract(predictions, targets)
53 lv1: R.Tensor((3, 5), "float32") = R.abs(lv)
54 gv: R.Tensor((), "float32") = R.mean(lv1, axis=None, keepdims=False)
55 R.output(gv)
56 return gv
57
58 assert_structural_equal(l1_loss(predictions, targets), expected)
59
60
61def test_l1_loss_append():

Callers

nothing calls this directly

Calls 1

assert_structural_equalFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…