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

Function test_matmul

imperative/python/test/unit/quantization/test_op.py:345–358  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

343
344
345def test_matmul():
346 inp_scale = np.float32(np.random.rand())
347 weight_scale = np.float32(np.random.rand())
348 inp_dtype = dtype.qint8(inp_scale)
349 weight_dtype = dtype.qint8(weight_scale)
350
351 inp_data = np.random.random((3, 12))
352 weight_data = np.random.random((5, 12))
353 inp_int8 = mge.tensor(dtype.convert_to_qint8(inp_data, inp_dtype))
354 weight_int8 = mge.tensor(dtype.convert_to_qint8(weight_data, weight_dtype))
355
356 res = F.matmul(inp_int8, weight_int8, transpose_b=True)
357 res_scale = dtype.get_scale(res.dtype)
358 np.testing.assert_allclose(inp_scale * weight_scale, res_scale)

Callers

nothing calls this directly

Calls 2

tensorMethod · 0.80
get_scaleMethod · 0.45

Tested by

no test coverage detected