> 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.2/developper-explanations/hummingbird_usage.md). Agents can also search and read this documentation through its [MCP server](https://docs.zama.org/concrete-ml/~gitbook/mcp).

# Hummingbird Usage

## Why Hummingbird?

Hummingbird contains an interesting feature for **Concrete-ML**: it converts many algorithms (see [supported algorithms](https://microsoft.github.io/hummingbird/api/hummingbird.ml.supported.html)) to tensor computations using a specific backend (torch, torchscript, ONNX and TVM).

**Concrete-ML** allows the conversion of an ONNX inference to NumPy inference (note that NumPy is always our entry point to run models in FHE).

## Usage

We use a simple functionnality of Hummingbird, which is the `convert` function that can be imported as follows from the `hummingbird.ml` package:

```python
# Disable Hummingbird warnings for pytest.
import warnings
warnings.filterwarnings("ignore")
from hummingbird.ml import convert
```

This function can be used to convert a machine learning model to an ONNX as follows:

```python
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression

# Instantiate the logistic regression from sklearn
lr = LogisticRegression()

# Create synthetic data
X, y = make_classification(
    n_samples=100, n_features=20, n_classes=2
)

# Fit the model
lr.fit(X, y)

# Convert the model to ONNX
onnx_model = convert(lr, backend="onnx", test_input=X).model
```

In theory, we can directly use this `onnx_model` within our `get_equivalent_numpy_forward` (as long as all operators present in the ONNX model are implemented in NumPy) and get the NumPy inference.

In practice, we have some steps to clean the ONNX and make the graph compatible with our framework such as:

* applying quantization where needed
* deleting non-FHE friendly ONNX operators, such as *Softmax* and *ArgMax*


---

# 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.2/developper-explanations/hummingbird_usage.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.
