用法
@staticmethod
create(
    rpc_layer, address, name='', timeout_in_ms=0
)参数
- 
rpc_layer客户端和服务器之间的通信层。目前仅支持"grpc" rpc 层。
- 
address连接 RPC 客户端的服务器地址。
- 
nameRPC 客户端的名称。您可以创建多个连接到同一服务器的客户端并使用不同的名称来区分它们。
- 
timeout_in_ms用于来自客户端的传出 RPC 的默认超时。 0 表示没有超时。在 RPC 期间超过超时将引发 DeadlineExceeded 错误。
返回
- 
一个实例tf.distribute.experimental.rpc.Client为即刻创建的客户端使用以下动态添加的方法:- Registered methods例如multiply(**args):如果客户端在即刻执行时创建,客户端将在客户端创建期间向服务器请求注册方法列表。 RPC 的便利方法将动态添加到创建的客户端实例中。- 例如,当服务器注册了 "multiply" 方法时,以即刻模式创建的客户端对象将具有可用的 'multiply' 方法。用户可以使用 client.multiply(..) 来进行 RPC,而不是 client.call("multiply", ...) - 在 tf.function 中创建 Client 时,这些方法不可用。 
 
抛出
- 如果使用 rpc_layer 而不是 "grpc",则会出现 ValueError。目前仅支持 GRPC。如果在创建和列出客户端方法时超时超过了即刻模式下的 DeadlineExceeded 异常。
创建 TF RPC 客户端以连接到给定地址。
示例用法:
# Have server already started.
import portpicker
@tf.function(input_signature=[
     tf.TensorSpec([], tf.int32),
     tf.TensorSpec([], tf.int32)])
def remote_fn(a, b):
  return tf.add(a, b)port = portpicker.pick_unused_port()
address = "localhost:{}".format(port)
server = tf.distribute.experimental.rpc.Server.create("grpc", address)
server.register("addition", remote_fn)
server.start()# Start client
client = tf.distribute.experimental.rpc.Client.create("grpc",
     address=address, name="test_client")a = tf.constant(2, dtype=tf.int32)
b = tf.constant(3, dtype=tf.int32)result = client.call(
   args=[a, b],
   method_name="addition",
   output_specs=tf.TensorSpec((), tf.int32))if result.is_ok():
  result.get_value()result = client.addition(a, b)if result.is_ok():
  result.get_value()相关用法
- Python tf.distribute.experimental.rpc.Server.create用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.gather用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.experimental_distribute_dataset用法及代码示例
- Python tf.distribute.experimental.partitioners.Partitioner.__call__用法及代码示例
- Python tf.distribute.experimental.TPUStrategy.experimental_distribute_values_from_function用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.run用法及代码示例
- Python tf.distribute.experimental.partitioners.MaxSizePartitioner.__call__用法及代码示例
- Python tf.distribute.experimental.partitioners.FixedShardsPartitioner用法及代码示例
- Python tf.distribute.experimental.TPUStrategy.experimental_distribute_dataset用法及代码示例
- Python tf.distribute.experimental.ParameterServerStrategy.gather用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.scope用法及代码示例
- Python tf.distribute.experimental.TPUStrategy用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.reduce用法及代码示例
- Python tf.distribute.experimental.partitioners.MinSizePartitioner用法及代码示例
- Python tf.distribute.experimental.ParameterServerStrategy.experimental_distribute_values_from_function用法及代码示例
- Python tf.distribute.experimental.CentralStorageStrategy.experimental_distribute_values_from_function用法及代码示例
- Python tf.distribute.experimental.CentralStorageStrategy用法及代码示例
- Python tf.distribute.experimental.coordinator.ClusterCoordinator.fetch用法及代码示例
- Python tf.distribute.experimental.ParameterServerStrategy.experimental_distribute_dataset用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.distribute.experimental.rpc.Client.create。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
