Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPU-optimized pipeline #55

Open
qo4on opened this issue Mar 1, 2021 · 0 comments
Open

TPU-optimized pipeline #55

qo4on opened this issue Mar 1, 2021 · 0 comments

Comments

@qo4on
Copy link

qo4on commented Mar 1, 2021

Hi!
I compared Keras fit time for dataset and experimental_distribute_dataset from your great notebook using latest TF version. It turned out that distributed dataset adds no speedup. Are you sure that your distributed input pipeline is well optimized for TPU? Why don't you use other optimizations like these:

def input_fn(batch_size):
    """> 2000 images/sec"""
    files = tf.data.Dataset.list_files(FLAGS.data_dir)

    def tftecord_dataset(filename):
        buffer_size = 8 * 1024 * 1024   # 8 MiB per file
        return tf.data.TFRecordDataset(filename, buffer_size=buffer_size)

    dataset = files.apply(tf.contrib.data.parallel_interleave(
        tftecord_dataset, cycle_length=32, sloppy=True))
    dataset = dataset.apply(tf.contrib.data.shuffle_and_repeat(10000, NUM_EPOCHS))
    dataset = dataset.apply(tf.contrib.data.map_and_batch(
        parser_fn, batch_size, num_parallel_calls=4))
    return dataset.prefetch(4)

if FLAGS.use_tpu:
    # When using TPU, wrap the optimizer with CrossShardOptimizer which
    # handles synchronizarion details between different TPU cores.
    optimizer = tpu_optimizer.CrossShardOptimizer(optimizer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant