Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c62184c

Browse filesBrowse files
authored
Improves documentation (#66)
1 parent d93af40 commit c62184c
Copy full SHA for c62184c

File tree

3 files changed

+126
-32
lines changed
Filter options

3 files changed

+126
-32
lines changed

‎CODE_OF_CONDUCT.md

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Code of Conduct
2+
3+
We are a community based on openness, as well as friendly and didactic discussions.
4+
5+
We aspire to treat everybody equally, and value their contributions.
6+
7+
Decisions are made based on technical merit and consensus.
8+
9+
Code is not the only way to help the project. Reviewing pull requests,
10+
answering questions to help others on mailing lists or issues, organizing and
11+
teaching tutorials, working on the website, improving the documentation, are
12+
all priceless contributions.
13+
14+
We abide by the principles of openness, respect, and consideration of others of
15+
the Python Software Foundation: https://www.python.org/psf/codeofconduct/

‎README.rst

Copy file name to clipboardExpand all lines: README.rst
+37-1Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ onnx-array-api: APIs to create ONNX Graphs
3131

3232
**onnx-array-api** implements APIs to create custom ONNX graphs.
3333
The objective is to speed up the implementation of converter libraries.
34+
35+
Numpy API
36+
+++++++++
37+
3438
The first one matches **numpy API**.
3539
It gives the user the ability to convert functions written
3640
following the numpy API to convert that function into ONNX as
@@ -113,10 +117,15 @@ It supports eager mode as well:
113117
l2_loss=[0.002]
114118
[0.042]
115119

120+
Light API
121+
+++++++++
122+
116123
The second API or **Light API** tends to do every thing in one line.
124+
It is inspired from the `Reverse Polish Notation
125+
<https://en.wikipedia.org/wiki/Reverse_Polish_notation>`_.
117126
The euclidean distance looks like the following:
118127

119-
::
128+
.. code-block:: python
120129
121130
import numpy as np
122131
from onnx_array_api.light_api import start
@@ -142,3 +151,30 @@ The library is released on
142151
`pypi/onnx-array-api <https://pypi.org/project/onnx-array-api/>`_
143152
and its documentation is published at
144153
`APIs to create ONNX Graphs <https://sdpython.github.io/doc/onnx-array-api/dev/>`_.
154+
155+
GraphBuilder API
156+
++++++++++++++++
157+
158+
Almost every converting library (converting a machine learned model to ONNX) is implementing
159+
its own graph builder and customizes it for its needs.
160+
It handles some frequent tasks such as giving names to intermediate
161+
results, loading, saving onnx models. It can be used as well to extend an existing graph.
162+
163+
.. code-block:: python
164+
165+
import numpy as np
166+
from onnx_array_api.graph_api import GraphBuilder
167+
168+
g = GraphBuilder()
169+
g.make_tensor_input("X", np.float32, (None, None))
170+
g.make_tensor_input("Y", np.float32, (None, None))
171+
r1 = g.make_node("Sub", ["X", "Y"]) # the name given to the output is given by the class,
172+
# it ensures the name is unique
173+
init = g.make_initializer(np.array([2], dtype=np.int64)) # the class automatically
174+
# converts the array to a tensor
175+
r2 = g.make_node("Pow", [r1, init])
176+
g.make_node("ReduceSum", [r2], outputs=["Z"]) # the output name is given because
177+
# the user wants to choose the name
178+
g.make_tensor_output("Z", np.float32, (None, None))
179+
180+
onx = g.to_onnx() # final conversion to onnx

‎_doc/index.rst

Copy file name to clipboardExpand all lines: _doc/index.rst
+74-31Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,83 @@ The objective is to speed up the implementation of converter libraries.
4545
CHANGELOGS
4646
license
4747

48+
Sources available on
49+
`github/onnx-array-api <https://github.com/sdpython/onnx-array-api>`_.
50+
51+
GraphBuilder API
52+
++++++++++++++++
53+
54+
Almost every converting library (converting a machine learned model to ONNX) is implementing
55+
its own graph builder and customizes it for its needs.
56+
It handles some frequent tasks such as giving names to intermediate
57+
results, loading, saving onnx models. It can be used as well to extend an existing graph.
58+
See :ref:`l-graph-api`.
59+
60+
.. runpython::
61+
:showcode:
62+
63+
import numpy as np
64+
from onnx_array_api.graph_api import GraphBuilder
65+
from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
66+
67+
g = GraphBuilder()
68+
g.make_tensor_input("X", np.float32, (None, None))
69+
g.make_tensor_input("Y", np.float32, (None, None))
70+
r1 = g.make_node("Sub", ["X", "Y"]) # the name given to the output is given by the class,
71+
# it ensures the name is unique
72+
init = g.make_initializer(np.array([2], dtype=np.int64)) # the class automatically
73+
# converts the array to a tensor
74+
r2 = g.make_node("Pow", [r1, init])
75+
g.make_node("ReduceSum", [r2], outputs=["Z"]) # the output name is given because
76+
# the user wants to choose the name
77+
g.make_tensor_output("Z", np.float32, (None, None))
78+
79+
onx = g.to_onnx() # final conversion to onnx
80+
81+
print(onnx_simple_text_plot(onx))
82+
83+
Light API
84+
+++++++++
85+
86+
The syntax is inspired from the
87+
`Reverse Polish Notation <https://en.wikipedia.org/wiki/Reverse_Polish_notation>`_.
88+
This kind of API is easy to use to build new graphs,
89+
less easy to extend an existing graph. See :ref:`l-light-api`.
90+
91+
.. runpython::
92+
:showcode:
93+
94+
import numpy as np
95+
from onnx_array_api.light_api import start
96+
from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
97+
98+
model = (
99+
start()
100+
.vin("X")
101+
.vin("Y")
102+
.bring("X", "Y")
103+
.Sub()
104+
.rename("dxy")
105+
.cst(np.array([2], dtype=np.int64), "two")
106+
.bring("dxy", "two")
107+
.Pow()
108+
.ReduceSum()
109+
.rename("Z")
110+
.vout()
111+
.to_onnx()
112+
)
113+
114+
print(onnx_simple_text_plot(model))
115+
48116
Numpy API
49117
+++++++++
50118

51-
Sources available on
52-
`github/onnx-array-api <https://github.com/sdpython/onnx-array-api>`_.
119+
Writing ONNX graphs requires to know ONNX syntax unless
120+
it is possible to reuse an existing syntax such as :epkg:`numpy`.
121+
This is what this API is doing.
122+
This kind of API is easy to use to build new graphs,
123+
almost impossible to use to extend new graphs as it usually requires
124+
to know onnx for that. See :ref:`l-numpy-api-onnx`.
53125

54126
.. runpython::
55127
:showcode:
@@ -110,35 +182,6 @@ Sources available on
110182
res = jitted_myloss(x, y)
111183
print(to_dot(jitted_myloss.get_onnx()))
112184

113-
Light API
114-
+++++++++
115-
116-
.. runpython::
117-
:showcode:
118-
119-
import numpy as np
120-
from onnx_array_api.light_api import start
121-
from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
122-
123-
model = (
124-
start()
125-
.vin("X")
126-
.vin("Y")
127-
.bring("X", "Y")
128-
.Sub()
129-
.rename("dxy")
130-
.cst(np.array([2], dtype=np.int64), "two")
131-
.bring("dxy", "two")
132-
.Pow()
133-
.ReduceSum()
134-
.rename("Z")
135-
.vout()
136-
.to_onnx()
137-
)
138-
139-
print(onnx_simple_text_plot(model))
140-
141-
142185
Older versions
143186
++++++++++++++
144187

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.