(self)
| 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)) |
| 508 | x = mx.random.normal(shape=(1, 256)) |
| 509 | |
| 510 | # Invalid mode |
| 511 | with self.assertRaises(ValueError): |
| 512 | mx.quantize(w, mode="xyz") |
| 513 | |
| 514 | wq, scales, biases = mx.quantize(w, bits=4, group_size=32) |
| 515 | |
| 516 | with self.assertRaises(ValueError): |
| 517 | mx.dequantize(wq, scales, biases, bits=4, group_size=32, mode="xyz") |
| 518 | |
| 519 | with self.assertRaises(ValueError): |
| 520 | mx.quantized_matmul( |
| 521 | x, wq, scales, biases, bits=4, group_size=32, mode="xyz" |
| 522 | ) |
| 523 | |
| 524 | rhs_indices = mx.array(0) |
| 525 | with self.assertRaises(ValueError): |
| 526 | mx.gather_qmm( |
| 527 | x, |
| 528 | wq, |
| 529 | scales, |
| 530 | biases, |
| 531 | rhs_indices=rhs_indices, |
| 532 | bits=4, |
| 533 | group_size=32, |
| 534 | mode="xyz", |
| 535 | ) |
| 536 | |
| 537 | # Only quantize floating point types |
| 538 | with self.assertRaises(ValueError): |
| 539 | mx.quantize(mx.zeros((128, 128), mx.int32)) |
| 540 | |
| 541 | with self.assertRaises(ValueError): |
| 542 | mx.quantize(mx.zeros((128, 128), mx.int32), mode="mxfp4") |
| 543 | |
| 544 | # Must have bias for affine |
| 545 | with self.assertRaises(ValueError): |
| 546 | mx.dequantize(wq, scales, None, bits=4, group_size=32) |
| 547 | |
| 548 | with self.assertRaises(ValueError): |
| 549 | mx.quantized_matmul(x, wq, scales, None, bits=4, group_size=32) |
| 550 | |
| 551 | with self.assertRaises(ValueError): |
| 552 | mx.gather_qmm( |
| 553 | x, wq, scales, None, rhs_indices=rhs_indices, bits=4, group_size=32 |
| 554 | ) |
| 555 | |
| 556 | # Must be floating point |
| 557 | x = mx.zeros(shape=(256,), dtype=mx.int32) |
| 558 | scales = mx.zeros(scales.shape, dtype=mx.int32) |
| 559 | biases = mx.zeros(scales.shape, dtype=mx.int32) |
| 560 | with self.assertRaises(ValueError): |
| 561 | mx.dequantize(wq, scales, biases, bits=4, group_size=32) |
| 562 | |
| 563 | with self.assertRaises(ValueError): |
nothing calls this directly
no test coverage detected