用法
@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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
