(self)
| 471 | self.assertLess((y_q - y_hat).abs().max(), 2e-3) |
| 472 | |
| 473 | def test_fp_qvm(self): |
| 474 | key = mx.random.key(0) |
| 475 | k1, k2 = mx.random.split(key) |
| 476 | tests = product( |
| 477 | [32, 128, 256], # M |
| 478 | [128, 256, 67], # N |
| 479 | [0, 1, 3, 8], # B |
| 480 | ) |
| 481 | # Add a splitk |
| 482 | tests = list(tests) |
| 483 | tests.append((128, 16384, 0)) |
| 484 | modes = ["mxfp4", "nvfp4", "mxfp8"] |
| 485 | |
| 486 | for M, N, B in tests: |
| 487 | for mode in modes: |
| 488 | with self.subTest(shape=(B, M, N), mode=mode): |
| 489 | x_shape = (1, N) if B == 0 else (B, 1, N) |
| 490 | w_shape = (N, M) if B == 0 else (B, N, M) |
| 491 | x = mx.random.normal(shape=x_shape, key=k1) |
| 492 | w = mx.random.normal(shape=w_shape, key=k2) |
| 493 | w_q, scales = mx.quantize(w, mode=mode) |
| 494 | w_hat = mx.dequantize(w_q, scales, mode=mode) |
| 495 | y_q = mx.quantized_matmul( |
| 496 | x, |
| 497 | w_q, |
| 498 | scales, |
| 499 | transpose=False, |
| 500 | mode=mode, |
| 501 | ) |
| 502 | y_hat = x @ w_hat |
| 503 | self.assertEqual(y_q.shape, y_hat.shape) |
| 504 | self.assertLess((y_q - y_hat).abs().max(), 2e-3) |
| 505 | |
| 506 | def test_mode_error_cases(self): |
| 507 | w = mx.random.normal(shape=(256, 256)) |
nothing calls this directly
no test coverage detected