> 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.onnx_model_manipulations.md).

# concrete.ml.onnx.onnx\_model\_manipulations

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

## module `concrete.ml.onnx.onnx_model_manipulations`

Some code to manipulate models.

***

[![](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/onnx_model_manipulations.py#L11)

### function `simplify_onnx_model`

```python
simplify_onnx_model(onnx_model: ModelProto)
```

Simplify an ONNX model, removes unused Constant nodes and Identity nodes.

**Args:**

* **`onnx_model`** (onnx.ModelProto): the model to simplify.

***

[![](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/onnx_model_manipulations.py#L21)

### function `remove_unused_constant_nodes`

```python
remove_unused_constant_nodes(onnx_model: ModelProto)
```

Remove unused Constant nodes in the provided onnx model.

**Args:**

* **`onnx_model`** (onnx.ModelProto): the model for which we want to remove unused Constant nodes.

***

[![](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/onnx_model_manipulations.py#L52)

### function `remove_identity_nodes`

```python
remove_identity_nodes(onnx_model: ModelProto)
```

Remove identity nodes from a model.

**Args:**

* **`onnx_model`** (onnx.ModelProto): the model for which we want to remove Identity nodes.

***

[![](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/onnx_model_manipulations.py#L82)

### function `keep_following_outputs_discard_others`

```python
keep_following_outputs_discard_others(
    onnx_model: ModelProto,
    outputs_to_keep: Iterable[str]
)
```

Keep the outputs given in outputs\_to\_keep and remove the others from the model.

**Args:**

* **`onnx_model`** (onnx.ModelProto): the ONNX model to modify.
* **`outputs_to_keep`** (Iterable\[str]): the outputs to keep by name.

***

[![](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/onnx_model_manipulations.py#L113)

### function `remove_node_types`

```python
remove_node_types(onnx_model: ModelProto, op_types_to_remove: List[str])
```

Remove unnecessary nodes from the ONNX graph.

**Args:**

* **`onnx_model`** (onnx.ModelProto): The ONNX model to modify.
* **`op_types_to_remove`** (List\[str]): The node types to remove from the graph.

**Raises:**

* **`ValueError`**: Wrong replacement by an Identity node.

***

[![](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/onnx_model_manipulations.py#L167)

### function `clean_graph_after_node`

```python
clean_graph_after_node(onnx_model: ModelProto, node_name: str)
```

Clean the graph of the onnx model by removing nodes after the given node name.

**Args:**

* **`onnx_model`** (onnx.ModelProto): The onnx model.
* **`node_name`** (str): The node's name whose following nodes will be removed.


---

# 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.onnx_model_manipulations.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.
