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

Function test_matmul

tests/python/relax/test_transform_gradient_numeric.py:198–231  ·  view source on GitHub ↗
(target, dev)

Source from the content-addressed store, hash-verified

196
197@tvm.testing.parametrize_targets("llvm")
198def test_matmul(target, dev):
199 @tvm.script.ir_module
200 class Before:
201 @R.function
202 def main(x: R.Tensor((3, 3), "float32"), y: R.Tensor((3, 3), "float32")):
203 with R.dataflow():
204 lv1 = R.matmul(x, y)
205 lv2 = R.permute_dims(x)
206 lv3 = R.matmul(lv2, y)
207 lv4 = R.permute_dims(y)
208 lv5 = R.matmul(x, lv4)
209 lv6 = R.permute_dims(x)
210 lv7 = R.permute_dims(y)
211 lv8 = R.matmul(lv6, lv7)
212 lv9 = lv1 + lv3 + lv5 + lv8
213 gv = R.sum(lv9)
214 R.output(gv)
215 return gv
216
217 After = relax.transform.Gradient("main")(Before)
218 args = []
219 for arg in After["main_adjoint"].params:
220 shape = [int(l) for l in arg.struct_info.shape]
221 args.append(rand("float32", *shape))
222
223 vm_before = _legalize_and_build(Before, target, dev)
224 vm_after = _legalize_and_build(After, target, dev)
225 _, grad = vm_after["main_adjoint"](*args)
226
227 def func(*inputs):
228 loss = vm_before["main"](*[tvm.runtime.tensor(i) for i in inputs])
229 return loss.numpy()
230
231 check_numerical_grads(func, [i.numpy() for i in args], [i.numpy() for i in grad])
232
233
234if __name__ == "__main__":

Callers

nothing calls this directly

Calls 5

check_numerical_gradsFunction · 0.90
randFunction · 0.85
numpyMethod · 0.80
_legalize_and_buildFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…