MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _make_server_def

Function _make_server_def

tensorflow/python/training/server_lib.py:31–95  ·  view source on GitHub ↗

Creates a `tf.train.ServerDef` protocol buffer. Args: server_or_cluster_def: A `tf.train.ServerDef` or `tf.train.ClusterDef` protocol buffer, or a `tf.train.ClusterSpec` object, describing the server to be defined and/or the cluster of which it is a member. job_name: (Optional

(server_or_cluster_def, job_name, task_index, protocol,
                     config)

Source from the content-addressed store, hash-verified

29import os
30
31def _make_server_def(server_or_cluster_def, job_name, task_index, protocol,
32 config):
33 """Creates a `tf.train.ServerDef` protocol buffer.
34
35 Args:
36 server_or_cluster_def: A `tf.train.ServerDef` or `tf.train.ClusterDef`
37 protocol buffer, or a `tf.train.ClusterSpec` object, describing the server
38 to be defined and/or the cluster of which it is a member.
39 job_name: (Optional.) Specifies the name of the job of which the server is a
40 member. Defaults to the value in `server_or_cluster_def`, if specified.
41 task_index: (Optional.) Specifies the task index of the server in its job.
42 Defaults to the value in `server_or_cluster_def`, if specified. Otherwise
43 defaults to 0 if the server's job has only one task.
44 protocol: (Optional.) Specifies the protocol to be used by the server.
45 Acceptable values include `"grpc", "grpc+verbs"`. Defaults to the value in
46 `server_or_cluster_def`, if specified. Otherwise defaults to `"grpc"`.
47 config: (Options.) A `tf.compat.v1.ConfigProto` that specifies default
48 configuration options for all sessions that run on this server.
49
50 Returns:
51 A `tf.train.ServerDef`.
52
53 Raises:
54 TypeError: If the arguments do not have the appropriate type.
55 ValueError: If an argument is not specified and cannot be inferred.
56 """
57 server_def = tensorflow_server_pb2.ServerDef()
58 if isinstance(server_or_cluster_def, tensorflow_server_pb2.ServerDef):
59 server_def.MergeFrom(server_or_cluster_def)
60 if job_name is not None:
61 server_def.job_name = job_name
62 if task_index is not None:
63 server_def.task_index = task_index
64 if protocol is not None:
65 server_def.protocol = protocol
66 if config is not None:
67 server_def.default_session_config.MergeFrom(config)
68 else:
69 try:
70 cluster_spec = ClusterSpec(server_or_cluster_def)
71 except TypeError:
72 raise TypeError("Could not convert `server_or_cluster_def` to a "
73 "`tf.train.ServerDef` or `tf.train.ClusterSpec`.")
74 if job_name is None:
75 if len(cluster_spec.jobs) == 1:
76 job_name = cluster_spec.jobs[0]
77 else:
78 raise ValueError("Must specify an explicit `job_name`.")
79 if task_index is None:
80 task_indices = cluster_spec.task_indices(job_name)
81 if len(task_indices) == 1:
82 task_index = task_indices[0]
83 else:
84 raise ValueError("Must specify an explicit `task_index`.")
85 if protocol is None:
86 protocol = "grpc"
87
88 server_def = tensorflow_server_pb2.ServerDef(

Callers 1

__init__Method · 0.85

Calls 3

task_indicesMethod · 0.95
as_cluster_defMethod · 0.95
ClusterSpecClass · 0.85

Tested by

no test coverage detected