Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

First documentation of the light API#44

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sdpython merged 9 commits intomainfromdoc5
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
NextNext commit
fix documentation
  • Loading branch information
@xadupre
xadupre committedNov 7, 2023
commit00844ccd53fea4e95ccd0de76cee2e62b8380c05
15 changes: 10 additions & 5 deletions_doc/tutorial/light_api.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,15 +42,20 @@ Graph methods
Any graph must start with function :func:`start <onnx_array_api.light_api.start>`.
It is usually following by `vin` to add an input.

* bring (:meth:`cst <onnx_array_api.light_api.Var.bring>`, :meth:`cst <onnx_array_api.light_api.Vars.bring>`):
* bring (:meth:`Var.bring <onnx_array_api.light_api.Var.bring>`,
:meth:`Vars.bring <onnx_array_api.light_api.Vars.bring>`):
assembles multiple results into a set before calling an operator taking mulitple inputs,
* cst (:meth:`cst <onnx_array_api.light_api.Var.cst>`, :meth:`cst <onnx_array_api.light_api.Vars.cst>`):
* cst (:meth:`Var.cst <onnx_array_api.light_api.Var.cst>`,
:meth:`Vars.cst <onnx_array_api.light_api.Vars.cst>`):
adds a constant tensor to the graph,
* rename (:meth:`cst <onnx_array_api.light_api.Var.rename>`, :meth:`cst <onnx_array_api.light_api.Vars.rename>`):
* rename (:meth:`Var.rename <onnx_array_api.light_api.Var.rename>`,
:meth:`Vars.rename <onnx_array_api.light_api.Vars.rename>`):
renames or give a name to a variable in order to call it later.
* vin (:meth:`cst <onnx_array_api.light_api.Var.vin>`, :meth:`cst <onnx_array_api.light_api.Vars.vin>`):
* vin (:meth:`Var.vin <onnx_array_api.light_api.Var.vin>`,
:meth:`Vars.vin <onnx_array_api.light_api.Vars.vin>`):
adds an input to the graph,
* vout (:meth:`cst <onnx_array_api.light_api.Var.vout>`, :meth:`cst <onnx_array_api.light_api.Vars.vout>`):
* vout (:meth:`Var.vout <onnx_array_api.light_api.Var.vout>`,
:meth:`Vars.vout <onnx_array_api.light_api.Vars.vout>`):
declares an existing result as an output.

These methods are implemented in class :class:`onnx_array_api.light_api.var.BaseVar`
Expand Down
34 changes: 19 additions & 15 deletions_doc/tutorial/onnx_api.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ For example, the well known Euclidian distance
def euclidan(X: np.array, Y: np.array) -> float:
return ((X - Y) ** 2).sum()

The mathematical function must first betranslate with :epkg:`ONNX Operators` or
The mathematical function must first betranslated with :epkg:`ONNX Operators` or
primitives. It is usually easy because the primitives are very close to what
numpy defines. It can be expressed as (the syntax is just for illustration).

Expand DownExpand Up@@ -75,8 +75,8 @@ the true implementation would be the following.
return model


model = make_euclidean()
print(model)
model = make_euclidean()
print(model)

Since it is a second implementation of an existing function, it is necessary to
check the output is the same.
Expand DownExpand Up@@ -222,7 +222,7 @@ Many existing options are available to write custom onnx graphs.
The development is usually driven by what they are used for. Each of them
may not fully support all your needs and it is not always easy to understand
the error messages they provide when something goes wrong.
It is better to understand its own needfefore choosing one.
It is better to understand its own needbefore choosing one.
Here are some of the questions which may need to be answered.

* ability to easily write loops and tests (control flow)
Expand All@@ -246,7 +246,7 @@ onnxscript
It converts python code to onnx code by analyzing the python code
(through :epkg:`ast`). The package makes it very easy to use loops and tests in onnx.
It is very close to onnx syntax. It is not easy to support multiple
implementing depending on the opset version required by the user.
implementation depending on the opset version required by the user.

Example taken from the documentation :

Expand DownExpand Up@@ -319,9 +319,11 @@ An Eager mode is available to debug what the code does.
spox
++++

The syntax of epkg:`spox` is similar but it does not use :epkg:`ast`.
The syntax of:epkg:`spox` is similar but it does not use :epkg:`ast`.
Therefore, `loops and tests <https://spox.readthedocs.io/en/latest/guides/advanced.html#Control-flow>`_
are expressed in a very different way.
are expressed in a very different way. The tricky part with it is to handle
the local context. A variable created in the main graph is known by any
of its subgraphs.

Example taken from the documentation :

Expand DownExpand Up@@ -355,18 +357,19 @@ sklearn-onnx
++++++++++++

:epkg:`sklearn-onnx` also implements its own API to add custom graphs.
It was designed to shorten the timespend in reimplementingthescikit-learn
code into onnx code. It can be used to implement a newconverted as
described in this example:
It was designed to shorten the timespent in reimplementing:epkg:`scikit-learn`
code into:epkg:`onnx` code. It can be used to implement a newconverter
mapped a custom model asdescribed in this example:
`Implement a new converter
<https://onnx.ai/sklearn-onnx/auto_tutorial/plot_icustom_converter.html>`_.
But it can also be used to build standaloneexample:
But it can also be used to build standalonemodels.

.. runpython::
:showcode:

import numpy as np
import onnx
import onnx.helper as oh
from onnx_array_api.plotting.text_plot import onnx_simple_text_plot


Expand All@@ -389,15 +392,16 @@ But it can also be used to build standalone example:
dummy = np.empty([1], np_type)
return final.to_onnx({"X": dummy, "Y": dummy})

model = make_euclidean()
print(onnx_simple_text_plot(model))

model = make_euclidean_skl2onnx()
print(onnx_simple_text_plot(model))

onnxblocks
++++++++++

`onnxblocks <https://onnxruntime.ai/docs/api/python/on_device_training/training_artifacts.html#prepare-for-training>`_
was introduced in onnxruntime to define custom losses in order to train
a model with :epkg:`onnxruntime-training`.
a model with :epkg:`onnxruntime-training`. It is mostly used for this usage.

.. code-block:: python

Expand DownExpand Up@@ -446,7 +450,7 @@ a model with :epkg:`onnxruntime-training`.
numpy API for onnx
++++++++++++++++++

See :ref:`l-numpy-api-onnx`. This API was introduced to creategraph
See :ref:`l-numpy-api-onnx`. This API was introduced to creategraphs
by using numpy API. If a function is defined only with numpy,
it should be possible to use the exact same code to create the
corresponding onnx graph. That's what this API tries to achieve.
Expand Down
2 changes: 1 addition & 1 deletion_unittests/ut_validation/test_docs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,7 @@ def test_ort_make_euclidean(self):
Y = np.random.rand(3, 4).astype(np.float32)
expected = ((X - Y) ** 2).sum(keepdims=1)
got = ref.run(None, {"X": X, "Y": Y})[0]
self.assertEqualArray(expected, got)
self.assertEqualArray(expected, got, atol=1e-6)


if __name__ == "__main__":
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp