> 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.onnx.convert.md).

# concrete.ml.onnx.convert

[![](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/onnx/convert.py#L0)

## module `concrete.ml.onnx.convert`

ONNX conversion related code.

### **Global Variables**

* **IMPLEMENTED\_ONNX\_OPS**
* **OPSET\_VERSION\_FOR\_ONNX\_EXPORT**

***

[![](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/onnx/convert.py#L17)

### function `get_equivalent_numpy_forward_and_onnx_model`

```python
get_equivalent_numpy_forward_and_onnx_model(
    torch_module: Module,
    dummy_input: Union[Tensor, Tuple[Tensor, ]],
    output_onnx_file: Optional[Path, str] = None
) → Tuple[Callable[, Tuple[ndarray, ]], GraphProto]
```

Get the numpy equivalent forward of the provided torch Module.

**Args:**

* **`torch_module`** (torch.nn.Module): the torch Module for which to get the equivalent numpy forward.
* **`dummy_input`** (Union\[torch.Tensor, Tuple\[torch.Tensor, ...]]): dummy inputs for ONNX export.
* **`output_onnx_file`** (Optional\[Union\[Path, str]], optional): Path to save the ONNX file to. Will use a temp file if not provided. Defaults to None.

**Returns:**

* **`Tuple[Callable[..., Tuple[numpy.ndarray, ...]], onnx.GraphProto]`**: The function that will execute the equivalent numpy code to the passed torch\_module and the generated ONNX 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/onnx/convert.py#L68)

### function `get_equivalent_numpy_forward`

```python
get_equivalent_numpy_forward(
    onnx_model: ModelProto,
    check_model: bool = True
) → Callable[, Tuple[ndarray, ]]
```

Get the numpy equivalent forward of the provided ONNX model.

**Args:**

* **`onnx_model`** (onnx.ModelProto): the ONNX model for which to get the equivalent numpy forward.
* **`check_model`** (bool): set to True to run the onnx checker on the model. Defaults to True.

**Raises:**

* **`ValueError`**: Raised if there is an unsupported ONNX operator required to convert the torch model to numpy.

**Returns:**

* **`Callable[..., Tuple[numpy.ndarray, ...]]`**: The function that will execute the equivalent numpy function.


---

# 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.onnx.convert.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.
