Skip to content

Commit 70d6f64

Browse files
authored
First documentation of the light API (#44)
* documentation * remove rstcheck, too many bugs * add missing link * fix unit test * fix documentation * unstable * windows * update titles * minorchanges
1 parent daf4402 commit 70d6f64

File tree

22 files changed

+1012
-61
lines changed

22 files changed

+1012
-61
lines changed

.github/workflows/rstcheck.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

CHANGELOGS.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Change Logs
22
===========
33

4-
0.2.0
4+
0.1.2
55
+++++
66

77
* :pr:`42`: first sketch for a very simple API to create onnx graph in one or two lines

README.rst

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. image:: https://github.com/sdpython/onnx-array-api/raw/main/_doc/_static/logo.png
33
:width: 120
44

5-
onnx-array-api: (Numpy) Array API for ONNX
5+
onnx-array-api: APIs to create ONNX Graphs
66
==========================================
77

88
.. image:: https://dev.azure.com/xavierdupre3/onnx-array-api/_apis/build/status/sdpython.onnx-array-api
@@ -29,7 +29,9 @@ onnx-array-api: (Numpy) Array API for ONNX
2929
.. image:: https://codecov.io/gh/sdpython/onnx-array-api/branch/main/graph/badge.svg?token=Wb9ZGDta8J
3030
:target: https://codecov.io/gh/sdpython/onnx-array-api
3131

32-
**onnx-array-api** implements a numpy API for ONNX.
32+
**onnx-array-api** implements APIs to create custom ONNX graphs.
33+
The objective is to speed up the implementation of converter libraries.
34+
The first one matches **numpy API**.
3335
It gives the user the ability to convert functions written
3436
following the numpy API to convert that function into ONNX as
3537
well as to execute it.
@@ -111,6 +113,31 @@ It supports eager mode as well:
111113
l2_loss=[0.002]
112114
[0.042]
113115

116+
The second API ir **Light API** tends to do every thing in one line.
117+
The euclidean distance looks like the following:
118+
119+
::
120+
121+
import numpy as np
122+
from onnx_array_api.light_api import start
123+
from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
124+
125+
model = (
126+
start()
127+
.vin("X")
128+
.vin("Y")
129+
.bring("X", "Y")
130+
.Sub()
131+
.rename("dxy")
132+
.cst(np.array([2], dtype=np.int64), "two")
133+
.bring("dxy", "two")
134+
.Pow()
135+
.ReduceSum()
136+
.rename("Z")
137+
.vout()
138+
.to_onnx()
139+
)
140+
114141
The library is released on
115142
`pypi/onnx-array-api <https://pypi.org/project/onnx-array-api/>`_
116143
and its documentation is published at

_doc/api/docs.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
validation.docs
2+
===============
3+
4+
make_euclidean
5+
++++++++++++++
6+
7+
.. autofunction:: onnx_array_api.validation.docs.make_euclidean

_doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ API
2222
tools
2323
profiling
2424
f8
25+
docs

_doc/api/light_api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ Var
2424

2525
.. autoclass:: onnx_array_api.light_api.Var
2626
:members:
27+
:inherited-members:
2728

2829
Vars
2930
====
3031

3132
.. autoclass:: onnx_array_api.light_api.Vars
3233
:members:
34+
:inherited-members:

_doc/conf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,34 @@
114114
"https://data-apis.org/array-api/",
115115
("2022.12/API_specification/generated/array_api.{0}.html", 1),
116116
),
117+
"ast": "https://docs.python.org/3/library/ast.html",
117118
"cProfile.Profile": "https://docs.python.org/3/library/profile.html#profile.Profile",
118119
"DOT": "https://graphviz.org/doc/info/lang.html",
120+
"inner API": "https://onnx.ai/onnx/intro/python.html",
119121
"JIT": "https://en.wikipedia.org/wiki/Just-in-time_compilation",
120122
"onnx": "https://onnx.ai/onnx/",
123+
"onnx.helper": "https://onnx.ai/onnx/api/helper.html",
121124
"ONNX": "https://onnx.ai/",
125+
"ONNX Operators": "https://onnx.ai/onnx/operators/",
122126
"onnxruntime": "https://onnxruntime.ai/",
127+
"onnxruntime-training": "https://onnxruntime.ai/docs/get-started/training-on-device.html",
123128
"numpy": "https://numpy.org/",
124129
"numba": "https://numba.pydata.org/",
125130
"onnx-array-api": ("https://sdpython.github.io/doc/onnx-array-api/dev/"),
131+
"onnxscript": "https://github.com/microsoft/onnxscript",
126132
"pyinstrument": "https://github.com/joerick/pyinstrument",
127133
"python": "https://www.python.org/",
134+
"pytorch": "https://pytorch.org/",
135+
"reverse Polish notation": "https://en.wikipedia.org/wiki/Reverse_Polish_notation",
128136
"scikit-learn": "https://scikit-learn.org/stable/",
129137
"scipy": "https://scipy.org/",
138+
"sklearn-onnx": "https://onnx.ai/sklearn-onnx/",
139+
"spox": "https://github.com/Quantco/spox",
130140
"sphinx-gallery": "https://github.com/sphinx-gallery/sphinx-gallery",
141+
"tensorflow": "https://www.tensorflow.org/",
142+
"tensorflow-onnx": "https://github.com/onnx/tensorflow-onnx",
131143
"torch": "https://pytorch.org/docs/stable/torch.html",
144+
"torch.onnx": "https://pytorch.org/docs/stable/onnx.html",
132145
#
133146
"C_OrtValue": (
134147
"http://www.xavierdupre.fr/app/onnxcustom/helpsphinx/"

_doc/index.rst

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
onnx-array-api: (Numpy) Array API for ONNX
2+
onnx-array-api: APIs to create ONNX Graphs
33
==========================================
44

55
.. image:: https://dev.azure.com/xavierdupre3/onnx-array-api/_apis/build/status/sdpython.onnx-array-api
@@ -26,10 +26,8 @@ onnx-array-api: (Numpy) Array API for ONNX
2626
.. image:: https://codecov.io/gh/sdpython/onnx-array-api/branch/main/graph/badge.svg?token=Wb9ZGDta8J
2727
:target: https://codecov.io/gh/sdpython/onnx-array-api
2828

29-
**onnx-array-api** implements a numpy API for ONNX.
30-
It gives the user the ability to convert functions written
31-
following the numpy API to convert that function into ONNX as
32-
well as to execute it.
29+
**onnx-array-api** implements APIs to create custom ONNX graphs.
30+
The objective is to speed up the implementation of converter libraries.
3331

3432
.. toctree::
3533
:maxdepth: 1
@@ -47,6 +45,8 @@ well as to execute it.
4745
CHANGELOGS
4846
license
4947

48+
**Numpy API**
49+
5050
Sources available on
5151
`github/onnx-array-api <https://github.com/sdpython/onnx-array-api>`_.
5252

@@ -57,7 +57,7 @@ Sources available on
5757

5858
import numpy as np # A
5959
from onnx_array_api.npx import absolute, jit_onnx
60-
from onnx_array_api.plotting.dot_plot import to_dot
60+
from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
6161

6262
def l1_loss(x, y):
6363
return absolute(x - y).sum()
@@ -78,6 +78,8 @@ Sources available on
7878
res = jitted_myloss(x, y)
7979
print(res)
8080

81+
print(onnx_simple_text_plot(jitted_myloss.get_onnx()))
82+
8183
.. gdot::
8284
:script: DOT-SECTION
8385
:process:
@@ -106,3 +108,30 @@ Sources available on
106108
y = np.array([[0.11, 0.22], [0.33, 0.44]], dtype=np.float32)
107109
res = jitted_myloss(x, y)
108110
print(to_dot(jitted_myloss.get_onnx()))
111+
112+
**Light API**
113+
114+
.. runpython::
115+
:showcode:
116+
117+
import numpy as np
118+
from onnx_array_api.light_api import start
119+
from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
120+
121+
model = (
122+
start()
123+
.vin("X")
124+
.vin("Y")
125+
.bring("X", "Y")
126+
.Sub()
127+
.rename("dxy")
128+
.cst(np.array([2], dtype=np.int64), "two")
129+
.bring("dxy", "two")
130+
.Pow()
131+
.ReduceSum()
132+
.rename("Z")
133+
.vout()
134+
.to_onnx()
135+
)
136+
137+
print(onnx_simple_text_plot(model))

_doc/tech/aapi.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
.. _l-array-api-painpoint:
12

2-
Difficulty to implement an an Array API for ONNX
3-
================================================
3+
Difficulty to implement an Array API for ONNX
4+
=============================================
45

56
Implementing the full array API is not always easy with :epkg:`onnx`.
67
Python is not strongly typed and many different types can be used

_doc/tutorial/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ Tutorial
66
.. toctree::
77
:maxdepth: 1
88

9-
overview
9+
onnx_api
10+
light_api
11+
numpy_api
1012
benchmarks

0 commit comments

Comments
 (0)