tf.distribute.experimental.rpc.Server
Stay organized with collections
Save and categorize content based on your preferences.
A Server base class for accepting RPCs for registered tf.functions.
Functions can be registered on the server and are exposed via RPCs.
Methods
create
View source
@staticmethod
create(
rpc_layer, address
)
Create TF RPC server at given address.
Args |
rpc_layer
|
Communication layer between client and server. Only "grpc" rpc
layer is supported at the moment.
|
address
|
Address where RPC server is hosted.
|
Raises |
A ValueError if rpc_layer other than "grpc" is used. Only GRPC
is supported at the moment.
|
Example usage |
>>> 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()
|
register
View source
register(
method_name: str,
func: Union[def_function.Function, tf_function.ConcreteFunction]
)
Method for registering tf.function on server.
Registered methods can be invoked remotely from clients.
Args |
method_name
|
Name of the tf.function. Clients use this method_name to make
RPCs.
|
func
|
A tf.function or ConcreteFunction to register.
|
start
View source
start()
Starts the RPC server on provided address.
Server listens for new requests from client, once it is started.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.distribute.experimental.rpc.Server\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/distribute/experimental/rpc/rpc_ops.py#L50-L114) |\n\nA Server base class for accepting RPCs for registered tf.functions.\n\nFunctions can be registered on the server and are exposed via RPCs.\n\nMethods\n-------\n\n### `create`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/distribute/experimental/rpc/rpc_ops.py#L57-L91) \n\n @staticmethod\n create(\n rpc_layer, address\n )\n\nCreate TF RPC server at given address.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------|--------------------------------------------------------------------------------------------------|\n| `rpc_layer` | Communication layer between client and server. Only \"grpc\" rpc layer is supported at the moment. |\n| `address` | Address where RPC server is hosted. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| An instance of [`tf.distribute.experimental.rpc.Server`](../../../../tf/distribute/experimental/rpc/Server) class. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---|---|\n| A ValueError if rpc_layer other than \"grpc\" is used. Only GRPC is supported at the moment. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Example usage ||\n|---|---|\n| \u003cbr /\u003e \u003e\u003e\u003e import portpicker \u003e\u003e\u003e @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() \u003cbr /\u003e ||\n\n\u003cbr /\u003e\n\n### `register`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/distribute/experimental/rpc/rpc_ops.py#L93-L106) \n\n register(\n method_name: str,\n func: Union[def_function.Function, tf_function.ConcreteFunction]\n )\n\nMethod for registering tf.function on server.\n\nRegistered methods can be invoked remotely from clients.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------------|-----------------------------------------------------------------------------|\n| `method_name` | Name of the tf.function. Clients use this method_name to make RPCs. |\n| `func` | A [`tf.function`](../../../../tf/function) or ConcreteFunction to register. |\n\n\u003cbr /\u003e\n\n### `start`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/distribute/experimental/rpc/rpc_ops.py#L108-L114) \n\n start()\n\nStarts the RPC server on provided address.\n\nServer listens for new requests from client, once it is started."]]