Skip to content

Commit 33b8850

Browse files
committed
add graph_builder
1 parent bd1a441 commit 33b8850

File tree

4 files changed

+879
-0
lines changed

4 files changed

+879
-0
lines changed

_doc/sg_execution_times.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
:orphan:
3+
4+
.. _sphx_glr_sg_execution_times:
5+
6+
7+
Computation times
8+
=================
9+
**00:00.000** total execution time for 6 files **from all galleries**:
10+
11+
.. container::
12+
13+
.. raw:: html
14+
15+
<style scoped>
16+
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet" />
17+
<link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
18+
</style>
19+
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
20+
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
21+
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
22+
<script type="text/javascript" class="init">
23+
$(document).ready( function () {
24+
$('table.sg-datatable').DataTable({order: [[1, 'desc']]});
25+
} );
26+
</script>
27+
28+
.. list-table::
29+
:header-rows: 1
30+
:class: table table-striped sg-datatable
31+
32+
* - Example
33+
- Time
34+
- Mem (MB)
35+
* - :ref:`sphx_glr_auto_examples_plot_benchmark_rf.py` (``examples/plot_benchmark_rf.py``)
36+
- 00:00.000
37+
- 0.0
38+
* - :ref:`sphx_glr_auto_examples_plot_f8.py` (``examples/plot_f8.py``)
39+
- 00:00.000
40+
- 0.0
41+
* - :ref:`sphx_glr_auto_examples_plot_first_example.py` (``examples/plot_first_example.py``)
42+
- 00:00.000
43+
- 0.0
44+
* - :ref:`sphx_glr_auto_examples_plot_onnxruntime.py` (``examples/plot_onnxruntime.py``)
45+
- 00:00.000
46+
- 0.0
47+
* - :ref:`sphx_glr_auto_examples_plot_optimization.py` (``examples/plot_optimization.py``)
48+
- 00:00.000
49+
- 0.0
50+
* - :ref:`sphx_glr_auto_examples_plot_profiling.py` (``examples/plot_profiling.py``)
51+
- 00:00.000
52+
- 0.0
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import unittest
2+
import onnx
3+
from onnx_array_api.ext_test_case import ExtTestCase
4+
from onnx_array_api.graph_api.graph_builder import GraphBuilder
5+
6+
7+
class TestGraphSimplification(ExtTestCase):
8+
def call_optimizer(self, onx):
9+
gr = GraphBuilder(onx)
10+
gr.remove_unused()
11+
return gr.to_onnx()
12+
13+
def test_remove_unused_nodes(self):
14+
model = onnx.parser.parse_model(
15+
"""
16+
<ir_version: 8, opset_import: [ "": 18]>
17+
agraph (float[N] x) => (float[N] z) {
18+
two = Constant <value_float=2.0> ()
19+
four = Add(two, two)
20+
z = Mul(x, x)
21+
}"""
22+
)
23+
onx = self.call_optimizer(model)
24+
self.assertEqual(len(onx.graph.node), 1)
25+
self.assertEqual(onx.graph.node[0].op_type, "Mul")
26+
27+
def test_initializers(self):
28+
model = onnx.parser.parse_model(
29+
"""
30+
<ir_version: 8, opset_import: [ "": 18]>
31+
agraph (float[N] x) => (float[N] z)
32+
<float two = {2.0}> {
33+
four = Add(two, two)
34+
z = Mul(x, x)
35+
}"""
36+
)
37+
self.assertEqual(len(model.graph.initializer), 1)
38+
onx = self.call_optimizer(model)
39+
self.assertEqual(len(onx.graph.node), 1)
40+
self.assertEqual(onx.graph.node[0].op_type, "Mul")
41+
self.assertEqual(len(onx.graph.initializer), 0)
42+
43+
def test_keep_unused_outputs(self):
44+
model = onnx.parser.parse_model(
45+
"""
46+
<ir_version: 8, opset_import: [ "": 18]>
47+
agraph (float[N] x) => (float[M] z) {
48+
w1, w2, w3 = Split (x)
49+
z = Mul(w3, w3)
50+
}"""
51+
)
52+
onx = self.call_optimizer(model)
53+
self.assertEqual(len(onx.graph.node), 2)
54+
self.assertEqual(onx.graph.node[0].op_type, "Split")
55+
56+
57+
if __name__ == "__main__":
58+
unittest.main(verbosity=2)

onnx_array_api/graph_api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)
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