Files
torus-ml/docs/references/api/torus.ml.deployment.fhe_client_server.md
zeekay e037e8f7ea torus: one name for the package, and it is ours
The distribution called itself torus-ml while shipping a package directory
named concrete, so the name a user installs and the name they import disagreed
— and most of the tree already said torus.ml, which could not resolve against
src/concrete. Moved src/concrete to src/torus and pointed the include at it.

The dependency was Zama's concrete-python from their index. It is torus-fhe
from ours, which is what luxfhe/torus already ships: that frontend declares
torus-fhe and ships a torus/fhe module, so every 'from torus.fhe' in this tree
was already naming our compiler and only the dependency lagged.

Two distributions share one namespace, which is the shape the upstream this
forked from used and the reason the split works: torus-fhe gives torus.fhe,
torus-ml gives torus.ml.

Swept every other spelling — identifiers, enum members, workflow variables,
filenames, notebooks. LICENSE and NOTICE keep the upstream attribution a fork
owes; the figures carry the old name in JPEG metadata a text sweep cannot
reach.
2026-08-27 13:20:50 -07:00

10 KiB

module torus.ml.deployment.fhe_client_server

APIs for FHE deployment.

Global Variables

  • CML_VERSION

function check_torus_versions

check_torus_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 (Torus FHE, Torus 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 DeploymentMode

Mode for the FHE API.


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: Union[bytes, Value, Tuple[bytes, ], Tuple[Value, ]],
    serialized_evaluation_keys: bytes
) → Union[bytes, Value, Tuple[bytes, ], Tuple[Value, ]]

Run the model on the server over encrypted data.

Args:

  • serialized_encrypted_quantized_data (Union[bytes, fhe.Value, Tuple[bytes, ...], Tuple[fhe.Value, ...]]): The encrypted and quantized values to consider. If these values are serialized (in bytes), they are first deserialized.
  • serialized_evaluation_keys (bytes): The evaluation keys. If they are serialized (in bytes), they are first deserialized.

Returns:

  • Union[bytes, fhe.Value, Tuple[bytes, ...], Tuple[fhe.Value, ...]]: The model's encrypted and quantized results. If the inputs were initially serialized, the outputs are also serialized.

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(
    mode: DeploymentMode = <DeploymentMode.INFERENCE: 'inference'>,
    via_mlir: bool = True
)

Export all needed artifacts for the client and server.

Arguments:

  • mode (DeploymentMode): the mode to save the FHE circuit, either "inference" or "training".
  • via_mlir (bool): serialize with via_mlir option from Torus-Python.

Raises:

  • Exception: path_dir is not empty or training module does not exist
  • ValueError: if mode is not "inference" or "training"

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: Optional[bytes]
) → Union[Any, Tuple[Any, ]]

Deserialize and decrypt the values.

Args:

  • serialized_encrypted_quantized_result (Optional[bytes]): The serialized, encrypted and quantized values.

Returns:

  • Union[Any, Tuple[Any, ...]]: The decrypted and deserialized values.

method deserialize_decrypt_dequantize

deserialize_decrypt_dequantize(
    *serialized_encrypted_quantized_result: Optional[bytes]
) → Union[ndarray, Tuple[ndarray, ]]

Deserialize, decrypt and de-quantize the values.

Args:

  • serialized_encrypted_quantized_result (Optional[bytes]): The serialized, encrypted and quantized result

Returns:

  • Union[numpy.ndarray, Tuple[numpy.ndarray, ...]]: The clear float 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(
    include_tfhers_key: bool = False
) → Union[bytes, Tuple[bytes, Union[bytes, NoneType]]]

Get the serialized evaluation keys.

Args:

  • include_tfhers_key (bool): Whether to include the serialized TFHE-rs public key.

Returns:

  • bytes: the evaluation keys

method get_tfhers_secret_key

get_tfhers_secret_key() → Union[bytes, NoneType]

Get the secret key that decrypts TFHE-rs ciphertexts.

This secret key use used by the client object to encrypt TFHE-rs ciphertexts that are sent to the server, but also to decrypt outputs produced by a server-side computation, that can be a Torus ML model or a TFHE-rs program.

Returns:

  • bytes: the serialized TFHE-rs secret key

method load

load()

Load the quantizers along with the FHE specs.


method quantize_encrypt_serialize

quantize_encrypt_serialize(
    *x: Optional[ndarray]
) → Union[bytes, NoneType, Tuple[Union[bytes, NoneType], ]]

Quantize, encrypt and serialize the values.

Args:

  • x (Optional[numpy.ndarray]): The values to quantize, encrypt and serialize.

Returns:

  • Union[bytes, Tuple[bytes, ...]]: The quantized, encrypted and serialized values.