Skip to content

Latest commit

 

History

History
263 lines (149 loc) · 8.29 KB

concrete.ml.deployment.fhe_client_server.md

File metadata and controls

263 lines (149 loc) · 8.29 KB

module concrete.ml.deployment.fhe_client_server

APIs for FHE deployment.

Global Variables

  • CML_VERSION

function check_concrete_versions

check_concrete_versions(zip_path: Path)

Check that current versions match the ones used in development.

This function loads the version JSON file found in client.zip or server.zip files and then checks that current package versions (Concrete Python, Concrete ML) as well as the Python current version all match the ones that are currently installed.

Args:

  • zip_path (Path): The path to the client or server zip file that contains the version.json file to check.

Raises:

  • ValueError: If at least one version mismatch is found.

class FHEModelServer

Server API to load and run the FHE circuit.

method __init__

__init__(path_dir: str)

Initialize the FHE API.

Args:

  • path_dir (str): the path to the directory where the circuit is saved

method load

load()

Load the circuit.


method run

run(
    serialized_encrypted_quantized_data: bytes,
    serialized_evaluation_keys: bytes
) → bytes

Run the model on the server over encrypted data.

Args:

  • serialized_encrypted_quantized_data (bytes): the encrypted, quantized and serialized data
  • serialized_evaluation_keys (bytes): the serialized evaluation keys

Returns:

  • bytes: the result of the model

class FHEModelDev

Dev API to save the model and then load and run the FHE circuit.

method __init__

__init__(path_dir: str, model: Any = None)

Initialize the FHE API.

Args:

  • path_dir (str): the path to the directory where the circuit is saved
  • model (Any): the model to use for the FHE API

method save

save(via_mlir: bool = False)

Export all needed artifacts for the client and server.

Arguments:

  • via_mlir (bool): serialize with via_mlir option from Concrete-Python. For more details on the topic please refer to Concrete-Python's documentation.

Raises:

  • Exception: path_dir is not empty

class FHEModelClient

Client API to encrypt and decrypt FHE data.

method __init__

__init__(path_dir: str, key_dir: Optional[str] = None)

Initialize the FHE API.

Args:

  • path_dir (str): the path to the directory where the circuit is saved
  • key_dir (str): the path to the directory where the keys are stored

method deserialize_decrypt

deserialize_decrypt(serialized_encrypted_quantized_result: bytes) → ndarray

Deserialize and decrypt the values.

Args:

  • serialized_encrypted_quantized_result (bytes): the serialized, encrypted and quantized result

Returns:

  • numpy.ndarray: the decrypted and deserialized values

method deserialize_decrypt_dequantize

deserialize_decrypt_dequantize(
    serialized_encrypted_quantized_result: bytes
) → ndarray

Deserialize, decrypt and de-quantize the values.

Args:

  • serialized_encrypted_quantized_result (bytes): the serialized, encrypted and quantized result

Returns:

  • numpy.ndarray: the decrypted (de-quantized) values

method generate_private_and_evaluation_keys

generate_private_and_evaluation_keys(force=False)

Generate the private and evaluation keys.

Args:

  • force (bool): if True, regenerate the keys even if they already exist

method get_serialized_evaluation_keys

get_serialized_evaluation_keys() → bytes

Get the serialized evaluation keys.

Returns:

  • bytes: the evaluation keys

method load

load()

Load the quantizers along with the FHE specs.


method quantize_encrypt_serialize

quantize_encrypt_serialize(x: ndarray) → bytes

Quantize, encrypt and serialize the values.

Args:

  • x (numpy.ndarray): the values to quantize, encrypt and serialize

Returns:

  • bytes: the quantized, encrypted and serialized values