aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python
diff options
context:
space:
mode:
authorGravatar Akshay Modi <nareshmodi@google.com>2018-06-19 10:25:10 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-06-19 10:28:19 -0700
commitc740b345e8c17cde0dd4691c7e240a065cb8c88c (patch)
treedd85bcff39031ec09de4507a335b541fb183adb4 /tensorflow/python
parentccaf2ca02739792a8a8e50a95246f2db1197aa97 (diff)
Allow setting server def on the eager context, and add the eager service to the grpc_tensorflow_server.
PiperOrigin-RevId: 201198350
Diffstat (limited to 'tensorflow/python')
-rw-r--r--tensorflow/python/eager/context.py10
-rw-r--r--tensorflow/python/framework/ops.py31
-rw-r--r--tensorflow/python/pywrap_tfe.i1
3 files changed, 39 insertions, 3 deletions
diff --git a/tensorflow/python/eager/context.py b/tensorflow/python/eager/context.py
index 9e146f021e..85b9491903 100644
--- a/tensorflow/python/eager/context.py
+++ b/tensorflow/python/eager/context.py
@@ -143,7 +143,11 @@ class Context(object):
# TODO(agarwal): create and link in some documentation for `execution_mode`.
# pylint: disable=redefined-outer-name
- def __init__(self, config=None, device_policy=None, execution_mode=None):
+ def __init__(self,
+ config=None,
+ device_policy=None,
+ execution_mode=None,
+ server_def=None):
"""Creates a new Context.
Args:
@@ -192,6 +196,7 @@ class Context(object):
if execution_mode is None:
execution_mode = SYNC
self._execution_mode = execution_mode
+ self._server_def = server_def
# pylint: enable=redefined-outer-name
@@ -231,6 +236,9 @@ class Context(object):
opts, self._device_policy)
if self._execution_mode == ASYNC:
pywrap_tensorflow.TFE_ContextOptionsSetAsync(opts, True)
+ if self._server_def is not None:
+ server_def_str = self._server_def.SerializeToString()
+ pywrap_tensorflow.TFE_ContextOptionsSetServerDef(opts, server_def_str)
self._context_handle = pywrap_tensorflow.TFE_NewContext(opts)
finally:
pywrap_tensorflow.TFE_DeleteContextOptions(opts)
diff --git a/tensorflow/python/framework/ops.py b/tensorflow/python/framework/ops.py
index ec3c829840..0d2f8a3acc 100644
--- a/tensorflow/python/framework/ops.py
+++ b/tensorflow/python/framework/ops.py
@@ -5147,7 +5147,8 @@ def init_scope():
@tf_export("enable_eager_execution")
-def enable_eager_execution(config=None, device_policy=None,
+def enable_eager_execution(config=None,
+ device_policy=None,
execution_mode=None):
"""Enables eager execution for the lifetime of this program.
@@ -5207,6 +5208,31 @@ def enable_eager_execution(config=None, device_policy=None,
TensorFlow graph, or if options provided conflict with a previous call
to this function.
"""
+ return enable_eager_execution_internal(
+ config, device_policy, execution_mode, None)
+
+
+def enable_eager_execution_internal(config=None,
+ device_policy=None,
+ execution_mode=None,
+ server_def=None):
+ """Enables eager execution for the lifetime of this program.
+
+ Most of the doc string for enable_eager_execution is relevant here as well.
+ Args:
+ config: See enable_eager_execution doc string
+ device_policy: See enable_eager_execution doc string
+ execution_mode: See enable_eager_execution doc string
+ server_def: (Optional.) A tensorflow::ServerDef proto.
+ Enables execution on remote devices. GrpcServers need to be started by
+ creating an identical server_def to this, and setting the appropriate
+ task_indexes, so that the servers can communicate. It will then be
+ possible to execute operations on remote devices.
+
+ Raises:
+ ValueError
+
+ """
if config is not None and not isinstance(config, config_pb2.ConfigProto):
raise TypeError(
"config must be a tf.ConfigProto, but got %s" % type(config))
@@ -5234,7 +5260,8 @@ def enable_eager_execution(config=None, device_policy=None,
context._context = context.Context(
config=config,
device_policy=device_policy,
- execution_mode=execution_mode)
+ execution_mode=execution_mode,
+ server_def=server_def)
elif ((config is not None and config is not context._context._config) or
(device_policy is not None and
device_policy is not context._context._device_policy) or
diff --git a/tensorflow/python/pywrap_tfe.i b/tensorflow/python/pywrap_tfe.i
index 500dc30cc3..5d7535cf34 100644
--- a/tensorflow/python/pywrap_tfe.i
+++ b/tensorflow/python/pywrap_tfe.i
@@ -59,6 +59,7 @@ limitations under the License.
%rename("%s") TFE_ContextOptionsSetConfig;
%rename("%s") TFE_ContextOptionsSetDevicePlacementPolicy;
%rename("%s") TFE_ContextOptionsSetAsync;
+%rename("%s") TFE_ContextOptionsSetServerDef;
%rename("%s") TFE_DeleteContextOptions;
%rename("%s") TFE_Py_TensorShapeSlice;
%rename("%s") TFE_Py_TensorShapeOnDevice;