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

Method test_shape

python/tests/test_quantized.py:768–820  ·  view source on GitHub ↗
(
            M,
            N,
            K,
            dtype=mx.float32,
            batch_A=(),
            batch_B=(),
            lhs_indices=None,
            rhs_indices=None,
            transpose=True,
            group_size=None,
            bits=None,
            mode="affine",
        )

Source from the content-addressed store, hash-verified

766 return w_hat, qw, s, b
767
768 def test_shape(
769 M,
770 N,
771 K,
772 dtype=mx.float32,
773 batch_A=(),
774 batch_B=(),
775 lhs_indices=None,
776 rhs_indices=None,
777 transpose=True,
778 group_size=None,
779 bits=None,
780 mode="affine",
781 ):
782 with self.subTest(
783 M=M,
784 N=N,
785 K=K,
786 dtype=dtype,
787 batch_A=batch_A,
788 batch_B=batch_B,
789 lhs_indices=lhs_indices,
790 rhs_indices=rhs_indices,
791 transpose=transpose,
792 group_size=group_size,
793 bits=bits,
794 mode=mode,
795 ):
796 x = mx.random.normal(shape=batch_A + (M, K)).astype(dtype)
797 w = mx.random.normal(
798 shape=batch_B + ((N, K) if transpose else (K, N))
799 ).astype(dtype)
800 w_hat, qw, s, b = quantize(w, transpose, group_size, bits, mode=mode)
801
802 if lhs_indices is not None:
803 lhs_indices = mx.array(lhs_indices)
804 if rhs_indices is not None:
805 rhs_indices = mx.array(rhs_indices)
806
807 c1 = mx.gather_mm(x, w_hat, lhs_indices, rhs_indices)
808 c2 = mx.gather_qmm(
809 x,
810 qw,
811 s,
812 b,
813 lhs_indices,
814 rhs_indices,
815 transpose=transpose,
816 group_size=group_size,
817 bits=bits,
818 mode=mode,
819 )
820 self.assertTrue(mx.allclose(c1, c2, atol=1e-4))
821
822 inputs = (
823 {

Callers

nothing calls this directly

Calls 3

gather_qmmMethod · 0.80
arrayMethod · 0.60
quantizeFunction · 0.50

Tested by

no test coverage detected