MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / tester

Function tester

imperative/python/test/unit/xla/functional/test_xla_math.py:28–49  ·  view source on GitHub ↗
(lhs_shape, rhs_shape, lhs_transpose, rhs_transpose, dtype=None)

Source from the content-addressed store, hash-verified

26@pytest.mark.skipif(not is_cuda_available(), reason="only support cuda now")
27def test_matmul():
28 def tester(lhs_shape, rhs_shape, lhs_transpose, rhs_transpose, dtype=None):
29 lhs = tensor(0.1 * np.random.randn(*lhs_shape), dtype=dtype)
30 rhs = tensor(0.1 * np.random.randn(*rhs_shape), dtype=dtype)
31 out = F.matmul(lhs, rhs, lhs_transpose, rhs_transpose)
32 dout = tensor(0.1 * np.random.randn(*out.shape), dtype=dtype)
33 atol = 5e-4 if dtype == np.float16 else 1e-5
34
35 gm = GradManager()
36
37 @jit.xla_trace(without_host=True)
38 def func(lhs, rhs, dout):
39 gm.attach([lhs, rhs])
40 with gm:
41 out = F.matmul(lhs, rhs, lhs_transpose, rhs_transpose)
42 gm.backward(out, dout)
43 return out, lhs.grad, rhs.grad
44
45 mge_rsts = func(lhs, rhs, dout)
46 xla_rsts = func(lhs, rhs, dout)
47
48 for mge_rst, xla_rst in zip(mge_rsts, xla_rsts):
49 np.testing.assert_allclose(mge_rst.numpy(), xla_rst.numpy(), atol=atol)
50
51 for dtype in [np.float16, np.float32]:
52 tester((5,), (5,), False, False)

Callers 8

test_matmulFunction · 0.70
test_sort_and_argsortFunction · 0.70
test_topkFunction · 0.70
test_topk_accuracyFunction · 0.70
test_fakequantFunction · 0.70
test_tqtFunction · 0.70
test_lsqFunction · 0.70
test_non_finiteFunction · 0.70

Calls 9

GradManagerClass · 0.90
QuantDtypeMetaClass · 0.90
create_qparamsFunction · 0.90
fake_quant_tensorFunction · 0.90
tqt_forwardFunction · 0.90
lsq_forwardFunction · 0.90
uniformMethod · 0.80
funcFunction · 0.70
numpyMethod · 0.45

Tested by

no test coverage detected