syft.workers.node_client

Module Contents

class syft.workers.node_client.NodeClient(hook, address, credential: AbstractCredential = None, id: Union[int, str] = 0, is_client_worker: bool = False, log_msgs: bool = False, verbose: bool = False, encoding: str = 'ISO-8859-1')

Bases: syft.workers.websocket_client.WebsocketClientWorker, syft.federated.federated_client.FederatedClient

Federated Node Client.

property url(self)

Get Node URL Address. :returns: Node’s address. :rtype: address (str)

property models(self)

Get models stored at remote node.

Returns

List of models stored in this node.

Return type

models (List)

_authenticate(self)

Perform Authentication Process using credentials grid credentials. :raises RuntimeError: If authentication process fail.

_update_node_reference(self, new_id: str)

Update worker references changing node id references at hook structure. :param new_id: New worker ID. :type new_id: str

_parse_address(self, address: str)

Parse Address string to define secure flag and split into host and port. :param address: Adress of remote worker. :type address: str

_get_node_id(self)

Get Node ID from remote node worker :returns: node id used by remote worker. :rtype: node_id (str)

_forward_json_to_websocket_server_worker(self, message: dict)

Prepare/send a JSON message to a remote node and receive the response. :param message: message payload. :type message: dict

Returns

response payload.

Return type

node_response (dict)

_forward_to_websocket_server_worker(self, message: bin)

Send a bin message to a remote node and receive the response. :param message: message payload. :type message: bytes

Returns

response payload.

Return type

node_response (bytes)

_return_bool_result(self, result, return_key=None)
connect_nodes(self, node)

Connect two remote workers between each other. :param node: Node that will be connected with this remote worker. :type node: WebsocketFederatedClient

Returns

node response.

Return type

node_response (dict)

serve_model(self, model, model_id: str = None, mpc: bool = False, allow_download: bool = False, allow_remote_inference: bool = False)

Hosts the model and optionally serve it using a Socket / Rest API. :param model: A jit model or Syft Plan. :param model_id: An integer/string representing the model id. :type model_id: str :param If it isn’t provided and the model is a Plan we use model.id,: :param if the model is a jit model we raise an exception.: :param allow_download: Allow to copy the model to run it locally. :type allow_download: bool :param allow_remote_inference: Allow to run remote inferences. :type allow_remote_inference: bool

Returns

True if model was served sucessfully.

Return type

result (bool)

Raises
  • ValueError – model_id isn’t provided and model is a jit model.

  • RunTimeError – if there was a problem during model serving.

run_remote_inference(self, model_id, data)

Run a dataset inference using a remote model.

Parameters
  • model_id (str) – Model ID.

  • data (Tensor) – dataset to be inferred.

Returns

Inference result

Return type

inference (Tensor)

Raises

RuntimeError – If an unexpected behavior happen.

delete_model(self, model_id: str)

Delete a model previously registered.

Parameters

model_id (String) – ID of the model that will be deleted.

Returns

If succeeded, return True.

Return type

result (bool)

__str__(self)