> For the complete documentation index, see [llms.txt](https://docs.zama.org/concrete-ml/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/concrete-ml/0.4/developer-guide/api/concrete.ml.quantization.quantized_module.md).

# concrete.ml.quantization.quantized\_module

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

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

QuantizedModule API.

### **Global Variables**

* **DEFAULT\_P\_ERROR\_PBS**

***

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

### 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/0.4.x/src/concrete/ml/quantization/quantized_module.py#L27)

#### 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
)
```

***

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

***

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

#### method `compile`

```python
compile(
    q_inputs: Union[Tuple[ndarray, ], ndarray],
    configuration: Optional[Configuration] = None,
    compilation_artifacts: Optional[DebugArtifacts] = None,
    show_mlir: bool = False,
    use_virtual_lib: bool = False,
    p_error: Optional[float] = 6.3342483999973e-05
) → Circuit
```

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.

***

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

#### method `dequantize_output`

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

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.

***

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

#### method `forward`

```python
forward(*qvalues: ndarray) → ndarray
```

Forward pass with numpy function only.

**Args:**

* **`*qvalues (numpy.ndarray)`**: numpy.array containing the quantized values.

**Returns:**

* **`(numpy.ndarray)`**: Predictions of the quantized model

***

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

#### method `forward_and_dequant`

```python
forward_and_dequant(*q_x: ndarray) → ndarray
```

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

***

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

#### method `post_processing`

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

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

***

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

#### method `quantize_input`

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

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.

***

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

#### 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
