Skip to content

Implements GraphBuilder for the graph_api #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add graph_builder
  • Loading branch information
xadupre committed Dec 20, 2023
commit 33b8850756e1cd9888ac66048275cd7b30cea493
52 changes: 52 additions & 0 deletions _doc/sg_execution_times.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

:orphan:

.. _sphx_glr_sg_execution_times:


Computation times
=================
**00:00.000** total execution time for 6 files **from all galleries**:

.. container::

.. raw:: html

<style scoped>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
</style>
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
<script type="text/javascript" class="init">
$(document).ready( function () {
$('table.sg-datatable').DataTable({order: [[1, 'desc']]});
} );
</script>

.. list-table::
:header-rows: 1
:class: table table-striped sg-datatable

* - Example
- Time
- Mem (MB)
* - :ref:`sphx_glr_auto_examples_plot_benchmark_rf.py` (``examples/plot_benchmark_rf.py``)
- 00:00.000
- 0.0
* - :ref:`sphx_glr_auto_examples_plot_f8.py` (``examples/plot_f8.py``)
- 00:00.000
- 0.0
* - :ref:`sphx_glr_auto_examples_plot_first_example.py` (``examples/plot_first_example.py``)
- 00:00.000
- 0.0
* - :ref:`sphx_glr_auto_examples_plot_onnxruntime.py` (``examples/plot_onnxruntime.py``)
- 00:00.000
- 0.0
* - :ref:`sphx_glr_auto_examples_plot_optimization.py` (``examples/plot_optimization.py``)
- 00:00.000
- 0.0
* - :ref:`sphx_glr_auto_examples_plot_profiling.py` (``examples/plot_profiling.py``)
- 00:00.000
- 0.0
58 changes: 58 additions & 0 deletions _unittests/ut_graph_api/test_graph_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import unittest
import onnx
from onnx_array_api.ext_test_case import ExtTestCase
from onnx_array_api.graph_api.graph_builder import GraphBuilder


class TestGraphSimplification(ExtTestCase):
def call_optimizer(self, onx):
gr = GraphBuilder(onx)
gr.remove_unused()
return gr.to_onnx()

def test_remove_unused_nodes(self):
model = onnx.parser.parse_model(
"""
<ir_version: 8, opset_import: [ "": 18]>
agraph (float[N] x) => (float[N] z) {
two = Constant <value_float=2.0> ()
four = Add(two, two)
z = Mul(x, x)
}"""
)
onx = self.call_optimizer(model)
self.assertEqual(len(onx.graph.node), 1)
self.assertEqual(onx.graph.node[0].op_type, "Mul")

def test_initializers(self):
model = onnx.parser.parse_model(
"""
<ir_version: 8, opset_import: [ "": 18]>
agraph (float[N] x) => (float[N] z)
<float two = {2.0}> {
four = Add(two, two)
z = Mul(x, x)
}"""
)
self.assertEqual(len(model.graph.initializer), 1)
onx = self.call_optimizer(model)
self.assertEqual(len(onx.graph.node), 1)
self.assertEqual(onx.graph.node[0].op_type, "Mul")
self.assertEqual(len(onx.graph.initializer), 0)

def test_keep_unused_outputs(self):
model = onnx.parser.parse_model(
"""
<ir_version: 8, opset_import: [ "": 18]>
agraph (float[N] x) => (float[M] z) {
w1, w2, w3 = Split (x)
z = Mul(w3, w3)
}"""
)
onx = self.call_optimizer(model)
self.assertEqual(len(onx.graph.node), 2)
self.assertEqual(onx.graph.node[0].op_type, "Split")


if __name__ == "__main__":
unittest.main(verbosity=2)
1 change: 1 addition & 0 deletions onnx_array_api/graph_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy