HeProfile#
- class HeProfile#
A class to hold a complete HE profile of a given model run, including the requirements it takes from the HE context to be init with, the tile layout and some estimated measurements with respect to its run.
- from_string(self: pyhelayers.HeProfile, content: str) None #
Loads the object from a string that contains content.
- Parameters:
content – The content to load, must be in the same format that is returned by “to_string”.
- get_context_name(self: pyhelayers.HeProfile) str #
Returns the name of the HE context to use for the HE model.
- get_he_config_requirement(self: pyhelayers.HeProfile) pyhelayers.HeConfigRequirement #
Returns the HE config requirement to use for the HE model.
- get_is_model_encrypted(self: pyhelayers.HeProfile) bool #
Returns indication to whether the model weights shall be encrypted.
- get_optimal_batch_size(self: pyhelayers.HeProfile) int #
Returns the batch size (number of elements in a single batch) the model was optimized for, or -1 if batching is not applicable for the model.
If batch size is applicable, providing inputs with number of elements along the batch dimension that is different than the batch size is supported.
Providing number of elements smaller than the batch size will not improve the running time and memory consumption with respect to fully-populated batch of elements. For example, if the batch size is 8, providing 1-7 elements will “cost” the same as 8 elements.
Providing number of elements bigger than the batch size will lead to increasing the running time and memory consumption, and in such case providing number of elements enough to fully-populate the batches will lead to better utilization of resources. For example, if the batch size is 8, providing 16 elements will lead to higher running time with respect to 8 elements, and providing 9-15 elements will “cost” the same as 16 elements. Providing 17-23 elements will “cost” the same as 24 elements and will lead to even higher running time.
- get_tile_layout(self: pyhelayers.HeProfile) pyhelayers.TTShape #
Returns the tile layout.
- set_not_secure(self: pyhelayers.HeProfile) None #
Sets the profile to be in non-secure setting (security level 0).
- set_not_secure_mockup(self: pyhelayers.HeProfile) None #
Sets the profile to be in non-secure setting (security level 0), and running with a mockup context
- to_string(self: pyhelayers.HeProfile) str #
“Returns a string with the content of the object.
-
class HeProfile : public helayers::Saveable#
Class to hold a complete HE profile of a given model run, including the requirements it takes from the HE context to be init with, the tile layout and some estimated measurements with respect to its run.
Public Functions
-
HeProfile()#
Construct an empty HE profile object.
-
const HeConfigRequirement &getHeConfigRequirement() const#
Returns the HE config requirement to use for the HE model.
-
const ModelMeasures &getModelMeasures() const#
Returns the model measures.
-
const std::string &getContextName() const#
Returns the name of the HE context to use for the HE model.
-
const std::string &getModeName() const#
Returns the mode name.
-
DimInt getOptimalBatchSize() const#
Returns the batch size (number of elements in a single batch) the model was optimized for, or -1 if batching is not applicable for the model.
If batch size is applicable, providing inputs with number of elements along the batch dimension that is different than the batch size is supported.
Providing number of elements smaller than the batch size will not improve the running time and memory consumption with respect to fully-populated batch of elements. For example, if the batch size is 8, providing 1-7 elements will “cost” the same as 8 elements.
Providing number of elements bigger than the batch size will lead to increasing the running time and memory consumption, and in such case providing number of elements enough to fully-populate the batches will lead to better utilization of resources. For example, if the batch size is 8, providing 16 elements will lead to higher running time with respect to 8 elements, and providing 9-15 elements will “cost” the same as 16 elements. Providing 17-23 elements will “cost” the same as 24 elements and will lead to even higher running time.
-
bool getIsModelEncrypted() const#
Returns indication to whether the model weights shall be encrypted.
-
bool getCircuitOptimization() const#
Returns indication to use circuit optimization when running the model.
-
std::string getCircuitSchedulingStrategy() const#
Returns the scheduling strategy of the circuit.
-
int getCircuitNumThreads() const#
Returns the number of threads to be used by the native worker.
-
int64_t getCircuitMemoryLimit() const#
Returns the RAM memory limit for the circuit native worker in bytes.
-
int getCircuitGpuWorkers() const#
Returns the number of GPU workers to use when running the model using a circuit.
-
int64_t getCircuitGpuMemoryLimit() const#
Returns the GPU memory limit for each of the circuit GPU in bytes.
-
LazyMode getLazyMode() const#
Returns the lazy mode of the model weights.
-
const std::string &getLazyLoadDir() const#
Returns directory to save content in disk when using lazy loading.
-
DeviceType getOptimizedDevice() const#
Returns the device type the profile was optimized for.
-
bool getHybridDeviceUtilization() const#
-
int getBaseChainIndex() const#
Returns the base chain index, which is the highest chain index the model should have in any of its internal weights and in its inputs.
-
void setNotSecure()#
Sets the profile to be in non-secure setting (security level 0)
-
void setNotSecureMockup()#
Sets the profile to be in non-secure setting (security level 0), and running with a mockup context.
-
void setNoCircuitOptimization()#
Turn off circuit optimization for this profile.
-
void setMultiPartyConfig(const MultiPartyConfig &config)#
Sets the profile’s multi-party configuration to be used to initialize the HeContext in multi-party setting.
-
double getOptimizationTargetValue(OPTIMIZATION_TARGET optimization) const#
Returns the estimated value of a measure that is a target to optimize for.
- Parameters:
optimization – the target measure to optimize for
-
std::string toString() const#
Returns a string with the content of the object.
-
void fromString(const std::string &content)#
Loads the object from a string that contains content.
- Parameters:
content – [in] the content to load, must be in the same format that is returned by “toString”
-
void toJsonFile(const std::string &path) const#
Writes the content of the object to JSON file.
- Parameters:
path – [in] the path to a JSON file to be populated
-
void fromJsonFile(const std::string &path)#
Loads the content of the object from JSON file.
- Parameters:
path – [in] the path to a JSON file to load from
-
virtual void debugPrint(const std::string &title = "", Verbosity verbosity = VERBOSITY_REGULAR, std::ostream &out = std::cout) const override#
Prints the content of this object.
- Parameters:
title – Text to add to the print
verbosity – Verbosity level
out – Output stream
Public Static Functions
-
static HeProfile createForTest(const HeConfigRequirement &heConfReq, const TTShape &tileLayout, const std::string &modeName, DimInt batchDim, bool isModelEncrypted = true, bool circuitOptimization = false, LazyMode lazyMode = NONE, bool handleOverflow = false, const std::string &contextName = "")#
Returns partially-populated HE profile object, to be used in tests.
The HE profile will not contain valid model measures, will not be on fit mode, and will have a base chain index equal to the multiplication depth of the HE config requirement.
- Parameters:
heConfReq – The configuration requirements from the HE library.
tileLayout – The tile tensor layout.
modeName – The mode name.
batchDim – The batch dimension (-1 means no batch dimension).
isModelEncrypted – An indication to whether the model weights are encrypted.
circuitOptimization – An indication to whether to use circuit optimization when running the model.
lazyMode – The lazy mode of the model weights.
handleOverflow – An indication to whether overflow handling should be applied.
contextName – The HE context name.
-
HeProfile()#