tf.data.experimental.service.MasterServer

View source on GitHub

An in-process tf.data service master server.

A tf.data.experimental.service.MasterServer coordinates a cluster of tf.data.experimental.service.WorkerServers. When the workers start, they register themselves with the master.

master = tf.data.experimental.service.MasterServer(port=0)
master_address = master.target.split("://")[1]
worker = tf.data.experimental.service.WorkerServer(
    port=0, master_address=master_address)
dataset = tf.data.Dataset.range(10)
dataset = dataset.apply(tf.data.experimental.service.distribute(
    processing_mode="parallel_epochs", service=master.target))
print(list(dataset.as_numpy_iterator()))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

When starting a dedicated tf.data master process, use join() to block indefinitely after starting up the server.

master = tf.data.experimental.service.MasterServer(port=5050)
master.join()

port Specifies the port to bind to.
protocol (Optional.) Specifies the protocol to be used by the server. Acceptable values include "grpc", "grpc+local". Defaults to "grpc".
start (Optional.) Boolean, indicating whether to start the server after creating it. Defaults to True.

tf.errors.OpError Or one of its subclasses if an error occurs while creating the TensorFlow server.

target Returns a target that can be used to connect to the server.

master = tf.data.experimental.service.MasterServer(port=0)
dataset = tf.data.Dataset.range(10)
dataset = dataset.apply(tf.data.experimental.service.distribute(
    processing_mode="parallel_epochs", service=master.target))

The returned string will be in the form protocol://address, e.g. "grpc://localhost:5050".

Methods

join

View source

Blocks until the server has shut down.

This is useful when starting a dedicated master process.

master = tf.data.experimental.service.MasterServer(port=5050)
master.join()

Raises
tf.errors.OpError Or one of its subclasses if an error occurs while joining the server.

start

View source

Starts this server.

master = tf.data.experimental.service.MasterServer(port=0, start=False)
master.start()

Raises
tf.errors.OpError Or one of its subclasses if an error occurs while starting the server.