concrete.ml.quantization.quantized_module
Last updated
Last updated
concrete.ml.quantization.quantized_module
QuantizedModule API.
DEFAULT_P_ERROR_PBS
QuantizedModule
Inference for a quantized model.
__init__
property fhe_circuit
Get the FHE circuit.
Returns:
Circuit
: the FHE circuit
property is_compiled
Return the compiled status of the module.
Returns:
bool
: the compiled status of the module.
property onnx_model
Get the ONNX model.
.. # noqa: DAR201
Returns:
_onnx_model
(onnx.ModelProto): the ONNX model
property post_processing_params
Get the post-processing parameters.
Returns:
Dict[str, Any]
: the post-processing parameters
compile
Compile the forward function of the module.
Args:
q_inputs
(Union[Tuple[numpy.ndarray, ...], numpy.ndarray]): Needed for tracing and building the boundaries.
configuration
(Optional[Configuration]): Configuration object to use during compilation
compilation_artifacts
(Optional[DebugArtifacts]): Artifacts object to fill during
show_mlir
(bool): if set, the MLIR produced by the converter and which is going to be sent to the compiler backend is shown on the screen, e.g., for debugging or demo. Defaults to False.
use_virtual_lib
(bool): set to use the so called virtual lib simulating FHE computation. Defaults to False.
p_error
(Optional[float]): probability of error of a PBS.
Returns:
Circuit
: the compiled Circuit.
dequantize_output
Take the last layer q_out and use its dequant function.
Args:
qvalues
(numpy.ndarray): Quantized values of the last layer.
Returns:
numpy.ndarray
: Dequantized values of the last layer.
forward
Forward pass with numpy function only.
Args:
*qvalues (numpy.ndarray)
: numpy.array containing the quantized values.
Returns:
(numpy.ndarray)
: Predictions of the quantized model
forward_and_dequant
Forward pass with numpy function only plus dequantization.
Args:
*q_x (numpy.ndarray)
: numpy.ndarray containing the quantized input values. Requires the input dtype to be uint8.
Returns:
(numpy.ndarray)
: Predictions of the quantized model
post_processing
Post-processing of the quantized output.
Args:
qvalues
(numpy.ndarray): numpy.ndarray containing the quantized input values.
Returns:
(numpy.ndarray)
: Predictions of the quantized model
quantize_input
Take the inputs in fp32 and quantize it using the learned quantization parameters.
Args:
*values (numpy.ndarray)
: Floating point values.
Returns:
Union[numpy.ndarray, Tuple[numpy.ndarray, ...]]
: Quantized (numpy.uint32) values.
set_inputs_quantization_parameters
Set the quantization parameters for the module's inputs.
Args:
*input_q_params (UniformQuantizer)
: The quantizer(s) for the module.