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())
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())
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())
def testBinarizeColsTranposeB(self): with self.test_session(): b_squeeze = binarize_cols(self.B) self.assertAllEqual(b_squeeze.eval(), tf.transpose(self.BC).eval())
def testBinarizeColsB_GPU(self): with self.test_session(): with tf.device('/gpu:0'): b_squeeze = tf.transpose(binarize_cols(self.B)) self.assertAllEqual(b_squeeze.eval(), self.BC.eval())
def testBinarizeColsA_GPU_32bit(self): with self.test_session(): with tf.device('/gpu:0'): a_squeeze = binarize_cols(tf.transpose(self.A)).eval() self.assertAllEqual(a_squeeze, self.AC.eval())