Ejemplo n.º 1
0
    def testXnorAny(self):
        """
        General matmul test with randomized inputs (random stuff in tests but whatever...)
        Simulate 235 batches of 440-width input for 200 nodes (all irregular)
        """
        with self.test_session():
            BATCH_SIZE = 235
            INPUT_WIDTH = 440
            NEURONS = 200

            features = tf.random_uniform(minval=-10, maxval=10, shape=[BATCH_SIZE, INPUT_WIDTH], dtype=tf.float32).eval()
            weights = tf.random_uniform(minval=-10, maxval=10, shape=[INPUT_WIDTH, NEURONS], dtype=tf.float32).eval()

            # binarize both using sign and cast to integer
            bin_features = tf.sign(tf.sign(features) - 0.5)
            bin_weights = tf.sign(tf.sign(weights) - 0.5)

            # weights squeezed transed
            bqt = binarize_rows(tf.transpose(bin_weights), qtype=tf.int32)
            bqt2 = binarize_cols(bin_weights)

            self.assertAllEqual(bqt.eval(), bqt2.eval())

            xnor_result = xgemm(bin_features, bin_weights, otype=tf.float32)
            tf_result = tf.matmul(bin_features, bin_weights)
            self.assertAllEqual(xnor_result.eval(), tf_result.eval())
Ejemplo n.º 2
0
    def testBSTvsBS3(self):
        with self.test_session():
            X = tf.random_uniform(minval=-10, maxval=10, shape=[2000, 2000], dtype=tf.float32)
            X = tf.sign(tf.sign(X) - 0.5).eval()

            bst = binarize_rows(X, qtype=tf.int32)
            Xt = tf.transpose(X)
            bst2 = binarize_cols(Xt)
            self.assertAllEqual(bst.eval(), bst2.eval())
Ejemplo n.º 3
0
    def testPythonSqueeze(self):
        with self.test_session():
            m = generate_matrix(200)
            mm = tf.constant(m, dtype=tf.float32)
            pp = tf.constant(python_binarize_rows(m)).eval()

            with tf.device('gpu:0'):
                mm_squeeze = binarize_rows(mm, qtype=tf.int32).eval()

            self.assertAllEqual(mm_squeeze, pp)
Ejemplo n.º 4
0
    def testBinarizeColsTranposeUnaligned(self):
        with self.test_session():
            M = tf.constant(
                [[-1, -1, -1],
                 [-1, -1, 1],
                 [-1, 1, -1],
                 [-1, 1, 1],
                 [-1, -1, -1],
                 [-1, -1, 1]], dtype=tf.int32
            )

            bst = binarize_rows(tf.transpose(M), qtype=tf.int32)
            b_squeeze = binarize_cols(M)
            self.assertAllEqual(bst.eval(), b_squeeze.eval())
Ejemplo n.º 5
0
 def testBinsqueezeA_GPU_32bit(self):
     with self.test_session():
         with tf.device('/gpu:0'):
             a_squeeze = binarize_rows(self.A, qtype=tf.int32).eval()
         self.assertAllEqual(a_squeeze, self.AC.eval())
Ejemplo n.º 6
0
 def testBinsqueezeB_CPU(self):
     with self.test_session():
         with tf.device('/cpu:0'):
             b_squeeze = tf.transpose(binarize_rows(tf.transpose(self.B), qtype=tf.int32))
         self.assertAllEqual(b_squeeze.eval(), self.BC.eval())
Ejemplo n.º 7
0
 def testBinsqueezeA_CPU_16bit(self):
     with self.test_session():
         with tf.device('/cpu:0'):
             a_squeeze = binarize_rows(self.A, qtype=tf.int16).eval()
         self.assertAllEqual(a_squeeze, self.AC16.eval())