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.
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.
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.
-
class ModelIoEncoder : public helayers::Saveable#
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.
Public Functions
-
ModelIoEncoder(const HeContext &he)#
Construct an empty ModelIoEncoder object to be loaded using load().
- Parameters:
he – The HE context.
-
ModelIoEncoder(const HeModel &heModel)#
Construct a ModelIoEncoder object for the given model.
- Parameters:
heModel – The HeModel to construct the ModelIoEncoder for.
-
void encodeEncrypt(EncryptedData &res, const std::vector<DoubleTensorCPtr> &inputs) const#
Encodes and encrypts the given HeModel inputs.
- Parameters:
res – An output parameter to store the encrypted inputs in.
inputs – The plaintext inputs.
-
void encodeEncryptRandomInputs(EncryptedData &res, size_t numBatches = 1) const#
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.
numBatches – The desired number of batches to encrypt.
-
std::vector<DoubleTensorCPtr> decryptDecodeOutputs(const EncryptedData &outputs) const#
Decrypts and decodes the outputs of predict.
- Parameters:
outputs – The encrypted outputs of predict.
-
std::vector<DoubleTensorCPtr> decryptDecodeOutputs(const EncryptedBatch &outputs) const#
Decrypts and decodes the outputs of predict over a single batch.
- Parameters:
outputs – The encrypted outputs of predict over a single batch.
-
DoubleTensorCPtr decryptDecodeOutput(const EncryptedData &output) const#
Decrypts and decodes the output of predict, assuming a single output.
- Parameters:
output – The single encrypted output of predict.
-
void setHeContext(const HeContext &he)#
Sets a new HE context to be used by this IO processor.
- Parameters:
he – The new HE context.
-
bool adjustGenericPackingInputs(EncryptedData &res, const std::vector<CTileTensorCPtr> &inputs) const#
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.
Public Static Functions
-
static void validateNumInputs(int actual, int expected)#
Validates the number of inputs for fit or predict matches the expected.
- Parameters:
actual – The number of given inputs.
expected – The number of expected inputs.
-
ModelIoEncoder(const HeContext &he)#