| 343 | |
| 344 | |
| 345 | def 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) |