ModelIoEncoder#

class ModelIoEncoder#

A class to handle the IO of an HE model, mainly, encoding and encrypting the inputs to be used for predict and fit, and decrypting and decoding the outputs of predict.

adjust_generic_packing_inputs(self: pyhelayers.ModelIoEncoder, res: pyhelayers.EncryptedData, inputs: List[pyhelayers.CTileTensor]) bool#

Adjusts generically-packed inputs to be used by the model. Returns whether a chain index was consumed during the adjustment process.

Parameters:
  • res – An output parameter to store the adjusted inputs in.

  • inputs – The given generically-packed inputs.

decrypt_decode_output(self: pyhelayers.ModelIoEncoder, output: pyhelayers.EncryptedData) numpy.ndarray[numpy.float64]#

Decrypts and decodes the output of predict, assuming a single output.

Parameters:

output – The single encrypted output of predict.

decrypt_decode_outputs(*args, **kwargs)#

Overloaded function.

  1. decrypt_decode_outputs(self: pyhelayers.ModelIoEncoder, outputs: pyhelayers.EncryptedData) -> List[numpy.ndarray[numpy.float64]]

    Decrypts and decodes the outputs of predict.

    param outputs:

    The encrypted outputs of predict.

  2. decrypt_decode_outputs(self: pyhelayers.ModelIoEncoder, outputs: pyhelayers.EncryptedBatch) -> List[numpy.ndarray[numpy.float64]]

    Decrypts and decodes the outputs of predict over a single batch.

    param outputs:

    The encrypted outputs of predict over a single batch.

encode_encrypt(self: pyhelayers.ModelIoEncoder, res: pyhelayers.EncryptedData, inputs: List[numpy.ndarray[numpy.float64]]) None#

Encodes and encrypts the given HeModel inputs.

Parameters:
  • res – An output parameter to store the encrypted inputs in.

  • inputs – The plaintext inputs.

encode_encrypt_random_inputs(self: pyhelayers.ModelIoEncoder, res: pyhelayers.EncryptedData, num_batches: int = 1) None#

Encodes and encrypts random inputs for fit or predict. May be useful for running simulations in which the actual content of the tensors is not important.

Parameters:
  • res – An output parameter to store the encrypted inputs in.

  • inputs – The desired number of batches to encrypt. Defaults to 1.

get_data_packing(self: pyhelayers.ModelIoEncoder, num_elements: int | None = None) pyhelayers.DataPacking#

Returns the data packing required by the HE model for its inputs.

Parameters:

num_elements – The number of elements along the batch dimension, if applicable.