I'm using TensorFlow and the tf.data.Dataset
API to perform some text preprocessing. Without using num_parallel_calls
in my dataset.map
call, it takes 0.03s to preprocess 10K records.
When I use num_parallel_trials=8
(the number of cores on my machine), it also takes 0.03s to preprocess 10K records.
I googled around and came across this: Parallelism isn't reducing the time in dataset map
where they indicate that you need to use TensorFlow operations to see a speedup. Here's the thing: I am using only TensorFlow operations. Specifically, I'm mapping this function:
def preprocess(self, x, data_table):
x['reviews'] = tf.string_split(x['reviews'], delimiter=' ')
x['reviews'] = tf.sparse_tensor_to_dense(x['reviews'], default_value=' ')
x['reviews'] = tf.cast(data_table.lookup(x['reviews']), tf.int32)
nbatch = tf.cast(tf.shape(x['reviews'])[0], tf.int32)
nseq = tf.cast(tf.shape(x['reviews'])[1], tf.int32)
padding = tf.cond(tf.less(nseq, 100),
lambda: 0 * tf.ones([nbatch, 100 - nseq], tf.int32),
lambda: 0 * tf.ones([nbatch, 0], tf.int32))
x['reviews'] = tf.concat((x['reviews'], padding), axis=1)[:, :100]
x['reviews'].set_shape([None, 100])
return x
Any idea why I don't see any speedup?
Thanks!
from Tensorflow: Dataset Map With num_parallel_calls Offers No Speedup
No comments:
Post a Comment