W3cubDocs

/TensorFlow Python

tf.test.create_local_cluster

tf.test.create_local_cluster(
    num_workers,
    num_ps,
    protocol='grpc',
    worker_config=None,
    ps_config=None
)

Defined in tensorflow/python/framework/test_util.py.

Create and start local servers and return the associated Server objects.

Example:

workers, _ = tf.test.create_local_cluster(num_workers=2, num_ps=2)

worker_sessions = [tf.Session(w.target) for w in workers]

with tf.device("/job:ps/task:0"):
  ...
with tf.device("/job:ps/task:1"):
  ...
with tf.device("/job:worker/task:0"):
  ...
with tf.device("/job:worker/task:1"):
  ...

worker_sessions[0].run(...)

Args:

  • num_workers: Number of worker servers to start.
  • num_ps: Number of PS servers to start.
  • protocol: Communication protocol. Allowed values are documented in the documentation of tf.train.Server.
  • worker_config: (optional) ConfigProto to initialize workers. Can be used to instantiate multiple devices etc.
  • ps_config: (optional) ConfigProto to initialize PS servers.

Returns:

A tuple (worker_servers, ps_servers). worker_servers is a list of num_workers objects of type tf.train.Server (all running locally); and ps_servers is a list of num_ps objects of similar type.

Raises:

  • ImportError: if portpicker module was not found at load time

© 2018 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/test/create_local_cluster