diff options
author | 2015-11-12 16:47:36 -0800 | |
---|---|---|
committer | 2015-11-12 16:47:36 -0800 | |
commit | d50565b35e886e7c3a201ea2f088790ed4b28de4 (patch) | |
tree | fa6bfce7311467e6c03ec314bb7947a49df7dd8c /tensorflow/python/kernel_tests | |
parent | 4dffee7f62d81ec9173aba1b0ef6b96e47f8037c (diff) |
TensorFlow: Upstream changes from afternoon.
Changes:
- Ptrdiff -> DenseIndex change by @jiayq
- Fix to scoping the logging in logging.py by @dga
- Improvement to Conv2DBackpropFilter on CPU by Andy
- Remove lookup table wrappers for the time being (wasn't in our
public API yet) by Yukata
- Add a check similar to numpy to make sure the user isn't in the
tensorflow src directory by @vrv
- More changes for python 3 compat by @girving
- Make dropout preserve shape info from input (@mrry)
- Significant speed improvements by @zheng-xq to BFC allocator to bring
on par (CPU overhead-wise) to the region allocator. Make BFC
allocator the default now that it's working well for a variety
of models.
- Fix a bunch of typos reported by users (@vrv)
- Enable concat for bfloat16 on GPU by Ashish.
Base CL: 107733123
Diffstat (limited to 'tensorflow/python/kernel_tests')
4 files changed, 24 insertions, 226 deletions
diff --git a/tensorflow/python/kernel_tests/concat_op_test.py b/tensorflow/python/kernel_tests/concat_op_test.py index b495948554..16efddc697 100644 --- a/tensorflow/python/kernel_tests/concat_op_test.py +++ b/tensorflow/python/kernel_tests/concat_op_test.py @@ -75,18 +75,28 @@ class ConcatOpTest(tf.test.TestCase): # Random dim to concat on concat_dim = np.random.randint(5) params = {} + if dtype == tf.bfloat16: + dtype_feed = tf.float32 + else: + dtype_feed = dtype with self.test_session(use_gpu=use_gpu): p = [] for i in np.arange(num_tensors): input_shape = shape input_shape[concat_dim] = np.random.randint(1, 5) - placeholder = tf.placeholder(dtype, shape=input_shape) + placeholder = tf.placeholder(dtype_feed, shape=input_shape) p.append(placeholder) - t = dtype.as_numpy_dtype + t = dtype_feed.as_numpy_dtype params[placeholder] = np.random.rand(*input_shape).astype(t) - c = tf.concat(concat_dim, p) + if dtype != dtype_feed: + concat_inputs = [tf.cast(p_i, dtype) for p_i in p] + else: + concat_inputs = p + c = tf.concat(concat_dim, concat_inputs) + if dtype != dtype_feed: + c = tf.cast(c, dtype_feed) result = c.eval(feed_dict=params) self.assertEqual(result.shape, c.get_shape()) @@ -100,15 +110,17 @@ class ConcatOpTest(tf.test.TestCase): ind[concat_dim] = slice(cur_offset, cur_offset + params[p[i]].shape[concat_dim]) cur_offset += params[p[i]].shape[concat_dim] - self.assertAllEqual(result[ind], params[p[i]]) + if dtype == dtype_feed: + self.assertAllEqual(result[ind], params[p[i]]) + else: + self.assertAllClose(result[ind], params[p[i]], 0.01) def testRandom(self): self._testRandom(tf.float32) self._testRandom(tf.int16) self._testRandom(tf.int32, use_gpu=True) - # Note that the following does not work since bfloat16 is not supported in - # numpy. - # self._testRandom(tf.bfloat16) + self._testRandom(tf.bfloat16) + self._testRandom(tf.bfloat16, use_gpu=True) def _testGradientsSimple(self, use_gpu): with self.test_session(use_gpu=use_gpu): diff --git a/tensorflow/python/kernel_tests/embedding_ops_test.py b/tensorflow/python/kernel_tests/embedding_ops_test.py index 03844d6177..5a987c912c 100644 --- a/tensorflow/python/kernel_tests/embedding_ops_test.py +++ b/tensorflow/python/kernel_tests/embedding_ops_test.py @@ -262,7 +262,7 @@ class EmbeddingLookupTest(tf.test.TestCase): self.assertAllEqual(simple, tf.gather(params, ids).eval()) # Run a few random sharded versions for procs in 1, 2, 3: - stride = procs * tf.range(0, params.shape[0] // procs) + stride = procs * tf.range(params.shape[0] // procs) split_params = [tf.gather(params, stride + p) for p in xrange(procs)] sharded = tf.nn.embedding_lookup(split_params, ids).eval() diff --git a/tensorflow/python/kernel_tests/init_ops_test.py b/tensorflow/python/kernel_tests/init_ops_test.py index 1b9f1323e8..8036989a0e 100644 --- a/tensorflow/python/kernel_tests/init_ops_test.py +++ b/tensorflow/python/kernel_tests/init_ops_test.py @@ -190,6 +190,10 @@ class RangeTest(tf.test.TestCase): self._Range(100, 500, 100), np.array([100, 200, 300, 400]))) self.assertEqual(tf.range(0, 5, 1).dtype, tf.int32) + def testLimitOnly(self): + with self.test_session(): + self.assertAllEqual(np.arange(5), tf.range(5).eval()) + def testEmpty(self): for start in 0, 5: self.assertTrue(np.array_equal(self._Range(start, start, 1), [])) diff --git a/tensorflow/python/kernel_tests/lookup_table_op_test.py b/tensorflow/python/kernel_tests/lookup_table_op_test.py deleted file mode 100644 index 7b5942cacd..0000000000 --- a/tensorflow/python/kernel_tests/lookup_table_op_test.py +++ /dev/null @@ -1,218 +0,0 @@ -"""Tests for lookup table ops from tf.""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import tensorflow.python.platform - -import numpy as np -import tensorflow as tf - - -class HashTableOpTest(tf.test.TestCase): - - def testHashTable(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = tf.constant(['brain', 'salad', 'surgery']) - values = tf.constant([0, 1, 2], tf.int64) - init = table.initialize_from(keys, values) - init.run() - self.assertAllEqual(3, table.size().eval()) - - input_string = tf.constant(['brain', 'salad', 'tank']) - output = table.lookup(input_string) - - result = output.eval() - self.assertAllEqual([0, 1, -1], result) - - def testHashTableFindHighRank(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = tf.constant(['brain', 'salad', 'surgery']) - values = tf.constant([0, 1, 2], tf.int64) - init = table.initialize_from(keys, values) - init.run() - self.assertAllEqual(3, table.size().eval()) - - input_string = tf.constant([['brain', 'salad'], ['tank', 'tarkus']]) - output = table.lookup(input_string) - - result = output.eval() - self.assertAllEqual([[0, 1], [-1, -1]], result) - - def testHashTableInitWithPythonArrays(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - # Empty table. - self.assertAllEqual(0, table.size().eval()) - - # Initialize with keys and values tensors. - keys = ['brain', 'salad', 'surgery'] - values = [0, 1, 2] - init = table.initialize_from(keys, values) - init.run() - self.assertAllEqual(3, table.size().eval()) - - input_string = tf.constant(['brain', 'salad', 'tank']) - output = table.lookup(input_string) - - result = output.eval() - self.assertAllEqual([0, 1, -1], result) - - def testHashTableInitWithNumPyArrays(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = np.array(['brain', 'salad', 'surgery'], dtype=np.str) - values = np.array([0, 1, 2], dtype=np.int64) - init = table.initialize_from(keys, values) - init.run() - self.assertAllEqual(3, table.size().eval()) - - input_string = tf.constant(['brain', 'salad', 'tank']) - output = table.lookup(input_string) - - result = output.eval() - self.assertAllEqual([0, 1, -1], result) - - def testMultipleHashTables(self): - with self.test_session() as sess: - shared_name = '' - default_val = -1 - table1 = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - table2 = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - table3 = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - keys = tf.constant(['brain', 'salad', 'surgery']) - values = tf.constant([0, 1, 2], tf.int64) - table1.initialize_from(keys, values) - table2.initialize_from(keys, values) - table3.initialize_from(keys, values) - - tf.initialize_all_tables().run() - self.assertAllEqual(3, table1.size().eval()) - self.assertAllEqual(3, table2.size().eval()) - self.assertAllEqual(3, table3.size().eval()) - - input_string = tf.constant(['brain', 'salad', 'tank']) - output1 = table1.lookup(input_string) - output2 = table2.lookup(input_string) - output3 = table3.lookup(input_string) - - out1, out2, out3 = sess.run([output1, output2, output3]) - self.assertAllEqual([0, 1, -1], out1) - self.assertAllEqual([0, 1, -1], out2) - self.assertAllEqual([0, 1, -1], out3) - - def testHashTableWithTensorDefault(self): - with self.test_session(): - shared_name = '' - default_val = tf.constant(-1, tf.int64) - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = tf.constant(['brain', 'salad', 'surgery']) - values = tf.constant([0, 1, 2], tf.int64) - init = table.initialize_from(keys, values) - init.run() - - input_string = tf.constant(['brain', 'salad', 'tank']) - output = table.lookup(input_string) - - result = output.eval() - self.assertAllEqual([0, 1, -1], result) - - def testSignatureMismatch(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = tf.constant(['brain', 'salad', 'surgery']) - values = tf.constant([0, 1, 2], tf.int64) - init = table.initialize_from(keys, values) - init.run() - - input_string = tf.constant([1, 2, 3], tf.int64) - with self.assertRaises(TypeError): - table.lookup(input_string) - - with self.assertRaises(TypeError): - tf.HashTable(tf.string, tf.int64, 'UNK', shared_name) - - def testDTypes(self): - with self.test_session(): - shared_name = '' - default_val = -1 - with self.assertRaises(TypeError): - tf.HashTable([tf.string], tf.string, default_val, shared_name) - - def testNotInitialized(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - input_string = tf.constant(['brain', 'salad', 'surgery']) - output = table.lookup(input_string) - - with self.assertRaisesOpError('Table not initialized'): - output.eval() - - def testInitializeTwice(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = tf.constant(['brain', 'salad', 'surgery']) - values = tf.constant([0, 1, 2], tf.int64) - init = table.initialize_from(keys, values) - init.run() - - with self.assertRaisesOpError('Table already initialized'): - init.run() - - def testInitializationWithInvalidDimensions(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = tf.constant(['brain', 'salad', 'surgery']) - values = tf.constant([0, 1, 2, 3, 4], tf.int64) - with self.assertRaises(ValueError): - table.initialize_from(keys, values) - - def testInitializationWithInvalidDataTypes(self): - with self.test_session(): - shared_name = '' - default_val = -1 - table = tf.HashTable(tf.string, tf.int64, default_val, shared_name) - - # Initialize with keys and values tensors. - keys = [0, 1, 2] - values = ['brain', 'salad', 'surgery'] - with self.assertRaises(TypeError): - table.initialize_from(keys, values) - - -if __name__ == '__main__': - tf.test.main() |