syft.grid.public_grid

Module Contents

class syft.grid.public_grid.PublicGridNetwork(hook, gateway_url: str, credential: AbstractCredential = None)

Bases: syft.grid.abstract_grid.AbstractGrid

search(self, *query: Union[str])

Search a set of tags across the grid network.

Parameters

query – A set of dataset tags.

Returns

matrix of tensor pointers.

Return type

tensor_results

serve_model(self, model, id: Union[str, int], mpc: bool = False, allow_remote_inference: bool = False, allow_download: bool = False, n_replica: int = 1)

Choose n (number of replicas defined at gateway) grid nodes registered in the grid network to host a model. :param model: Model to be hosted. :param id: Model’s ID. :param mpc: Boolean flag to serve plan models in an encrypted/unencrypted format. :param allow_remote_inference: Allow workers to run inference in this model. :param allow_download: Allow workers to copy the model and run it locally.

query_model_hosts(self, id: str, mpc: bool = False)

This method will search for a specific model registered on grid network, if found, It will return all grid nodes that contains the desired model. :param id: Model’s ID. :param mpc: Boolean flag to search plan models in an encrypted/unencrypted format.

Returns

Worker / list of workers that contains the desired model.

Return type

workers

Raises
  • RuntimeError – If grid network doesn’t have enough workers to host

  • an encrypted model, or if model isn't a plan.

run_remote_inference(self, id: str, data: torch.Tensor, mpc: bool = False)

This method will search for a specific model registered on the grid network, if found, It will run inference. :param id: Model’s ID. :param dataset: Data used to run inference. :param mpc: Boolean flag to run encrypted/unencrypted inferences.

Returns

Inference’s result.

Return type

Tensor

Raises

RuntimeError – If model id not registered on the grid network.

_serve_unencrypted_model(self, model, id, allow_remote_inference: bool, allow_download: bool)

This method will choose one of grid nodes registered in the grid network to host a plain text model. :param model: Model to be hosted. :param id: Model’s ID. :param allow_remote_inference: Allow workers to run inference in this model. :param allow_download: Allow workers to copy the model and run it locally.

_serve_encrypted_model(self, model)

This method wiil choose some grid nodes at grid network to host an encrypted model.

Parameters

model – Model to be hosted.

Raises
  • RuntimeError – If grid network doesn’t have enough workers to host

  • an encrypted model, or if model isn't a plan.

_query_unencrypted_models(self, id)

Search for a specific model registered on grid network, if found, It will return the first node that contains the desired model. :param id: Model’s ID.

Returns

worker that contains the desired model.

Return type

worker

_query_encrypted_models(self, id)

Search for a specific encrypted model registered on grid network, if found, It will return the first node that hosts the desired model and mpc shares. :param id: Model’s ID.

Returns

List of workers that contains the desired mpc model.

Return type

workers

_run_unencrypted_inference(self, id, data)

Search for an unencrypted model and perform data inference. :param id: Model’s ID. :param data: Dataset to be inferred.

Returns

Inference’s result.

Return type

Tensor

Raises

RuntimeError – If model if not found.

_run_encrypted_inference(self, id, data, copy=True)

Search for an encrypted model and perform inference.

Parameters
  • model_id – Model’s ID.

  • data – Dataset to be shared/inferred.

  • copy – Boolean flag to perform encrypted inference without lose plan.

Returns

Inference’s result.

Return type

Tensor

Raises

RuntimeError – If model id not found.

__connect_with_node(self, node_id, node_url)
_ask_gateway(self, request_method, endpoint: str, body: Dict = {})