Skip to content

Commit

Permalink
chore: minor update to 1.5 doc (#603)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Bredehoft <[email protected]>
  • Loading branch information
jfrery and RomanBredehoft authored Apr 12, 2024
1 parent 1ea5d46 commit 847c2cb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Refer to the API, review product architecture, and access additional resources f
- [Advanced features](explanations/advanced_features.md)
- [Project architecture](explanations/inner-workings/)

### Supports
### Support channels

Ask technical questions and discuss with the community. Our team of experts usually answers within 24 hours in working days.

Expand Down
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- [Documentation](developer/documenting.md)
- [Support and issues](developer/debug_support_submit_issues.md)
- [Contributing](developer/contributing.md)
- [Support new ONNX node](developer/support_new_onnx_node.md)
- [Release note](https://github.com/zama-ai/concrete-ml/releases)
- [Feature request](https://github.com/zama-ai/concrete-ml/issues/new?assignees=&labels=feature&projects=&template=feature_request.md)
- [Bug report](https://github.com/zama-ai/concrete-ml/issues/new?assignees=&labels=bug&projects=&template=bug_report.md)
2 changes: 1 addition & 1 deletion docs/developer/project_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ rm -rf .venv
make setup_env
```

At this point, you should consider using Docker as nobody will have the exact same setup as you. If, however, you need to develop on your OS directly, you can [ask Zama for help](../README.md#supports).
At this point, you should consider using Docker as nobody will have the exact same setup as you. If, however, you need to develop on your OS directly, you can [ask Zama for help](../README.md#support-channels).

#### in Docker

Expand Down
48 changes: 48 additions & 0 deletions docs/developer/support_new_onnx_node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Supporting New ONNX Nodes in Concrete ML

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`](../../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`](../../src/concrete/ml/onnx/ops_impl.py), you need to import it into [`onnx_utils.py`](../../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`](../../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:

<!--pytest-codeblocks:skip-->

```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`](../../tests/onnx/test_onnx_ops_impl.py): Tests the implementation of the ONNX node in floating points.
- [`test_quantized_ops.py`](../../tests/quantization/test_quantized_ops.py): Tests the implementation of the ONNX node in integer arithmetic.
- Optional: [`test_compile_torch.py`](../../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`](../../src/concrete/ml/pytest/torch_models.py).

## Update Documentation

Finally, update the documentation to reflect the newly supported ONNX node.
1 change: 1 addition & 0 deletions docs/index.toc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
developer/documenting.md
developer/debug_support_submit_issues.md
developer/contributing.md
developer/support_new_onnx_node.md


0 comments on commit 847c2cb

Please sign in to comment.