# concrete.ml.quantization.quantized\_module.md

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L0)

## module `concrete.ml.quantization.quantized_module`

QuantizedModule API.

### **Global Variables**

* **SUPPORTED\_FLOAT\_TYPES**
* **SUPPORTED\_INT\_TYPES**

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L79)

### class `QuantizedModule`

Inference for a quantized model.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L89)

#### method `__init__`

```python
__init__(
    ordered_module_input_names: Iterable[str] = None,
    ordered_module_output_names: Iterable[str] = None,
    quant_layers_dict: Dict[str, Tuple[Tuple[str, ], QuantizedOp]] = None,
    onnx_model: ModelProto = None
)
```

***

**property is\_compiled**

Indicate if the model is compiled.

**Returns:**

* `bool`: If the model is compiled.

***

**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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L640)

#### method `bitwidth_and_range_report`

```python
bitwidth_and_range_report() → Union[Dict[str, Dict[str, Union[Tuple[int, ], int]]], NoneType]
```

Report the ranges and bit-widths for layers that mix encrypted integer values.

**Returns:**

* `op_names_to_report` (Dict): a dictionary with operation names as keys. For each operation, (e.g., conv/gemm/add/avgpool ops), a range and a bit-width are returned. The range contains the min/max values encountered when computing the operation and the bit-width gives the number of bits needed to represent this range.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L198)

#### method `check_model_is_compiled`

```python
check_model_is_compiled()
```

Check if the quantized module is compiled.

**Raises:**

* `AttributeError`: If the quantized module is not compiled.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L554)

#### method `compile`

```python
compile(
    inputs: Union[Tuple[ndarray, ], ndarray],
    configuration: Optional[Configuration] = None,
    artifacts: Optional[DebugArtifacts] = None,
    show_mlir: bool = False,
    p_error: Optional[float] = None,
    global_p_error: Optional[float] = None,
    verbose: bool = False
) → Circuit
```

Compile the module's forward function.

**Args:**

* `inputs` (numpy.ndarray): A representative set of input values used for building cryptographic parameters.
* `configuration` (Optional\[Configuration]): Options to use for compilation. Default to None.
* `artifacts` (Optional\[DebugArtifacts]): Artifacts information about the compilation process to store for debugging.
* `show_mlir` (bool): Indicate if the MLIR graph should be printed during compilation.
* `p_error` (Optional\[float]): Probability of error of a single PBS. A p\_error value cannot be given if a global\_p\_error value is already set. Default to None, which sets this error to a default value.
* `global_p_error` (Optional\[float]): Probability of error of the full circuit. A global\_p\_error value cannot be given if a p\_error value is already set. This feature is not supported during simulation, meaning the probability is currently set to 0. Default to None, which sets this error to a default value.
* `verbose` (bool): Indicate if compilation information should be printed during compilation. Default to False.

**Returns:**

* `Circuit`: The compiled Circuit.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L519)

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: ndarray) → ndarray
```

Take the last layer q\_out and use its de-quant function.

**Args:**

* `q_y_preds` (numpy.ndarray): Quantized output values of the last layer.

**Returns:**

* `numpy.ndarray`: De-quantized output values of the last layer.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L181)

#### method `dump`

```python
dump(file: <class 'TextIO'>) → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L128)

#### method `dump_dict`

```python
dump_dict() → Dict
```

Dump itself to a dict.

**Returns:**

* `metadata` (Dict): Dict of serialized objects.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L173)

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L289)

#### method `forward`

```python
forward(
    *x: ndarray,
    fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>,
    debug: bool = False
) → Union[ndarray, Tuple[ndarray, Union[Dict[Any, Any], NoneType]]]
```

Forward pass with numpy function only on floating points.

This method executes the forward pass in the clear, with simulation or in FHE. Input values are expected to be floating points, as the method handles the quantization step. The returned values are floating points as well.

**Args:**

* `*x (numpy.ndarray)`: Input float values to consider.
* `fhe` (Union\[FheMode, str]): The mode to use for prediction. Can be FheMode.DISABLE for Concrete ML Python inference, FheMode.SIMULATE for FHE simulation and FheMode.EXECUTE for actual FHE execution. Can also be the string representation of any of these values. Default to FheMode.DISABLE.
* `debug` (bool): In debug mode, returns quantized intermediary values of the computation. This is useful when a model's intermediary values in Concrete ML need to be compared with the intermediary values obtained in pytorch/onnx. When set, the second return value is a dictionary containing ONNX operation names as keys and, as values, their input QuantizedArray or ndarray. The use can thus extract the quantized or float values of quantized inputs. This feature is only available in FheMode.DISABLE mode. Default to False.

**Returns:**

* `numpy.ndarray`: Predictions of the quantized model, in floating points.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L147)

#### method `load_dict`

```python
load_dict(metadata: Dict)
```

Load itself from a string.

**Args:**

* `metadata` (Dict): Dict of serialized objects.

**Returns:**

* `QuantizedModule`: The loaded object.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L229)

#### method `post_processing`

```python
post_processing(values: ndarray) → ndarray
```

Apply post-processing to the de-quantized values.

For quantized modules, there is no post-processing step but the method is kept to make the API consistent for the client-server API.

**Args:**

* `values` (numpy.ndarray): The de-quantized values to post-process.

**Returns:**

* `numpy.ndarray`: The post-processed values.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L494)

#### method `quantize_input`

```python
quantize_input(*x: ndarray) → Union[ndarray, Tuple[ndarray, ]]
```

Take the inputs in fp32 and quantize it using the learned quantization parameters.

**Args:**

* `x` (numpy.ndarray): Floating point x.

**Returns:**

* `Union[numpy.ndarray, Tuple[numpy.ndarray, ...]]`: Quantized (numpy.int64) x.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L355)

#### method `quantized_forward`

```python
quantized_forward(
    *q_x: ndarray,
    fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
```

Forward function for the FHE circuit.

**Args:**

* `*q_x (numpy.ndarray)`: Input integer values to consider.
* `fhe` (Union\[FheMode, str]): The mode to use for prediction. Can be FheMode.DISABLE for Concrete ML Python inference, FheMode.SIMULATE for FHE simulation and FheMode.EXECUTE for actual FHE execution. Can also be the string representation of any of these values. Default to FheMode.DISABLE.

**Returns:**

* `(numpy.ndarray)`: Predictions of the quantized model, with integer values.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/quantization/quantized_module.py#L536)

#### method `set_inputs_quantization_parameters`

```python
set_inputs_quantization_parameters(*input_q_params: UniformQuantizer)
```

Set the quantization parameters for the module's inputs.

**Args:**

* `*input_q_params (UniformQuantizer)`: The quantizer(s) for the module.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zama.org/concrete-ml/1.1/developer-guide/api/concrete.ml.quantization.quantized_module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
