MCPcopy Create free account
hub / github.com/ml-explore/mlx / test_non_multiples

Method test_non_multiples

python/tests/test_quantized.py:623–695  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

621 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
622
623 def test_non_multiples(self):
624 w = mx.random.normal(shape=(33, 256))
625 w_q, scales, biases = mx.quantize(w)
626 w_hat = mx.dequantize(w_q, scales, biases)
627
628 # Test qmv
629 x = mx.random.normal(shape=(1, 256))
630 y_q = mx.quantized_matmul(x, w_q, scales, biases, transpose=True)
631 y_hat = x @ w_hat.T
632 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
633
634 # Test qmm_t
635 x = mx.random.normal(shape=(10, 256))
636 y_q = mx.quantized_matmul(x, w_q, scales, biases, transpose=True)
637 y_hat = x @ w_hat.T
638 self.assertEqual(y_q.shape, y_hat.shape)
639 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
640
641 # Test qvm
642 x = mx.random.normal(shape=(1, 33))
643 y_q = mx.quantized_matmul(x, w_q, scales, biases, transpose=False)
644 y_hat = x @ w_hat
645 self.assertEqual(y_q.shape, y_hat.shape)
646 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
647
648 # Test qmm
649 x = mx.random.normal(shape=(10, 33))
650 y_q = mx.quantized_matmul(x, w_q, scales, biases, transpose=False)
651 y_hat = x @ w_hat
652 self.assertEqual(y_q.shape, y_hat.shape)
653 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
654
655 # Smaller than 8
656 w = mx.random.normal(shape=(3, 256))
657 w_q, scales, biases = mx.quantize(w)
658 w_hat = mx.dequantize(w_q, scales, biases)
659
660 # Test qmv
661 x = mx.random.normal(shape=(1, 256))
662 y_q = mx.quantized_matmul(x, w_q, scales, biases, transpose=True)
663 y_hat = x @ w_hat.T
664 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
665
666 # Test qmm_t
667 x = mx.random.normal(shape=(10, 256))
668 y_q = mx.quantized_matmul(x, w_q, scales, biases, transpose=True)
669 y_hat = x @ w_hat.T
670 self.assertEqual(y_q.shape, y_hat.shape)
671 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
672
673 # Test qvm
674 x = mx.random.normal(shape=(1, 3))
675 y_q = mx.quantized_matmul(x, w_q, scales, biases, transpose=False)
676 y_hat = x @ w_hat
677 self.assertEqual(y_q.shape, y_hat.shape)
678 self.assertLess((y_q - y_hat).abs().max(), 1e-3)
679
680 # Test qmm

Callers

nothing calls this directly

Calls 3

dequantizeMethod · 0.80
quantizeMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected