# Support new ONNX node

Concrete ML supports a wide range of models through the integration of ONNX nodes. In case a specific ONNX node is missing, developers need to add support for the new ONNX nodes.

## Operator Implementation

### Floating-point Implementation

The [`ops_impl.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/src/concrete/ml/onnx/ops_impl.py) file is responsible for implementing the computation of ONNX operators using floating-point arithmetic. The implementation should mirror the behavior of the corresponding ONNX operator precisely. This includes adhering to the expected inputs, outputs, and operational semantics.

Refer to the [ONNX documentation](https://github.com/onnx/onnx/blob/main/docs/Operators.md) to grasp the expected behavior, inputs and outputs of the operator.

### Operator Mapping

After implementing the operator in [`ops_impl.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/src/concrete/ml/onnx/ops_impl.py), you need to import it into [`onnx_utils.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/src/concrete/ml/onnx/onnx_utils.py) and map it within the `ONNX_OPS_TO_NUMPY_IMPL` dictionary. This mapping is crucial for the framework to recognize and utilize the new operator.

### Quantized Operator

Quantized operators are defined in [`quantized_ops.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/src/concrete/ml/quantization/quantized_ops.py) and are used to handle integer arithmetic. Their implementation is required for the new ONNX to be executed in FHE.

There exist two types of quantized operators:

* **Univariate Non-Linear Operators**: Such operator applies transformation on every element of the input without changing its shape. Sigmoid, Tanh, ReLU are examples of such operation. The sigmoid in this file is simply supported as follows:

```python
class QuantizedSigmoid(QuantizedOp):
    """Quantized sigmoid op."""

    _impl_for_op_named: str = "Sigmoid"
```

* **Linear Layers**: Linear layers like `Gemm` and `Conv` require specific implementations for integer arithmetic. Please refer to the `QuantizedGemm` and `QuantizedConv` implementations for reference.

## Adding Tests

Proper testing is essential to ensure the correctness of the new ONNX node support.

There are many locations where tests can be added:

* [`test_onnx_ops_impl.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/tests/onnx/test_onnx_ops_impl.py): Tests the implementation of the ONNX node in floating points.
* [`test_quantized_ops.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/tests/quantization/test_quantized_ops.py): Tests the implementation of the ONNX node in integer arithmetic.
* Optional: [`test_compile_torch.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/tests/torch/test_compile_torch.py): Tests the implementation of a specific torch model that contains the new ONNX operator. The model needs to be added in [`torch_models.py`](https://github.com/zama-ai/concrete-ml/blob/release/1.9.x/src/concrete/ml/pytest/torch_models.py).

## Update Documentation

Finally, update the documentation to reflect the newly supported ONNX node.


---

# 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/developers/support_new_onnx_node.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.
