Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions .github/workflows/spell-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Spell Check

on:
push:
branches:
- main
pull_request:

jobs:
spell-check:
runs-on: ubuntu-latest

steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v3

# Install codespell
- name: Install codespell
run: pip install codespell

# Run codespell
- name: Run codespell
run: codespell --skip="*.png,*.jpg,*.jpeg,*.gif,*.svg,*.ico,*.pdf,*.js" --ignore-words-list="nd,te,OT" --check-filenames
8 changes: 7 additions & 1 deletion .github/workflows/wheels-any.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ jobs:
python-version: '3.12'

- name: build wheel
run: python -m pip wheel .
run: python -m pip wheel . -v

- name: install twine
run: python -m pip install twine

- name: check wheel
run: python -m twine check ./onnx_diagnostic*.whl

- uses: actions/upload-artifact@v4
with:
Expand Down
18 changes: 13 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ onnx-diagnostic: investigate onnx models
:target: https://codecov.io/gh/sdpython/onnx-diagnostic

Helps investigating onnx models, exporting modes into onnx.
See :epkg:`documentation of onnx-diagnostic <https://sdpython.github.io/doc/onnx-diagnostic/dev/>`_.
See `documentation of onnx-diagnostic <https://sdpython.github.io/doc/onnx-diagnostic/dev/>`_.

Getting started
+++++++++++++++
Expand All @@ -43,18 +43,26 @@ or

pip install onnx-diagnostic

**Enlightening Examples**
Enlightening Examples
+++++++++++++++++++++

**Torch Export**

* `Use DYNAMIC or AUTO when exporting if dynamic shapes has constraints
<https://sdpython.github.io/doc/onnx-diagnostic/dev/auto_examples/plot_export_with_dynamic_shapes_auto.html>`_
* `Export with DynamicCache and dynamic shapes
<https://sdpython.github.io/doc/onnx-diagnostic/dev/auto_examples/plot_export_with_dynamic_cache.html>`_
* `Steel method forward to guess the dynamic shapes
<https://sdpython.github.io/doc/onnx-diagnostic/dev/auto_examples/plot_export_tiny_llm.html>`_
* `Running ReferenceEvaluator on a failing model
<https://sdpython.github.io/doc/onnx-diagnostic/dev/auto_examples/plot_failing_reference_evaluator.html>`_

**Investigate ONNX models**

* `Find where a model is failing by running submodels
<https://sdpython.github.io/doc/onnx-diagnostic/dev/auto_examples/plot_failing_model_extract.html>`_
* `Intermediate results with (ONNX) ReferenceEvaluator
<https://sdpython.github.io/doc/onnx-diagnostic/dev/auto_examples/plot_failing_reference_evaluator.html>`_
* `Intermediate results with onnxruntime
<https://sdpython.github.io/doc/onnx-diagnostic/dev/auto_examples/plot_failing_onnxruntime_evaluator.html>`_

Snapshot of usefuls tools
+++++++++++++++++++++++++
Expand Down Expand Up @@ -99,4 +107,4 @@ Snapshot of usefuls tools

**max_diff**

Returns the maximum discrancies accross nested containers containing tensors.
Returns the maximum discrancies across nested containers containing tensors.
13 changes: 13 additions & 0 deletions _doc/_static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.output {
background-color: #f8f9fa;
border-left: 4px solid #0078d4;
padding: 10px;
font-family: monospace;
font-size: 0.9em;
}
.sphx-glr-script-out {
padding: 10px;
font-family: monospace;
font-size: 0.9em;
overflow-x: auto;
}
1 change: 1 addition & 0 deletions _doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
html_theme_path = ["_static"]
html_theme_options = {}
html_static_path = ["_static"]
html_css_files = ["custom.css"]
html_sourcelink_suffix = ""

issues_github_path = "sdpython/onnx-diagnostic"
Expand Down
4 changes: 2 additions & 2 deletions _doc/examples/plot_export_tiny_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Steel method forward to guess the dynamic shapes
================================================

Inputs are always dynamic with LLMs that is why dyanmic shapes
Inputs are always dynamic with LLMs that is why dynamic shapes
needs to be specified when a LLM is exported with:func:`torch.export.export`.
Most of the examples on :epkg:`HuggingFace` use method
:meth:`transformers.GenerationMixin.generate` but we only want to
Expand All @@ -15,7 +15,7 @@

We focus on the model
`Tiny-LLM <https://huggingface.co/arnir0/Tiny-LLM>`_.
To avoid downloading any weigths, we write a function creating a
To avoid downloading any weights, we write a function creating a
random model based on the same architecture.

Steel the forward method
Expand Down
6 changes: 3 additions & 3 deletions _doc/examples/plot_export_with_dynamic_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def forward(self, x, y):
pprint.pprint(ds)

# %%
# The function returns a tuple with two objets.
# The function returns a tuple with two objects.
# The first one for the positional arguments, the other one
# for the named arguments. There is no named argements. We
# for the named arguments. There is no named arguments. We
# we used the first result to export.

ep = torch.export.export(model, (x, y), dynamic_shapes=ds[0])
Expand All @@ -66,7 +66,7 @@ def forward(self, x, y):
# kwargs
# ++++++
#
# We do the same with named argments.
# We do the same with named arguments.


class Model(torch.nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_export_with_dynamic_shapes_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Use DYNAMIC or AUTO when exporting if dynamic shapes has constraints
====================================================================

Settings the dynamic shapes is not always easy.
Setting the dynamic shapes is not always easy.
Here are a few tricks to make it work.

dx + dy not allowed?
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_failing_model_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
oh.make_node("Cast", ["C"], ["X999"], to=999, name="failing"),
oh.make_node("CastLike", ["X999", "Y"], ["Z"], name="n4"),
],
"nd",
"-nd-",
[
oh.make_tensor_value_info("X", TFLOAT, ["a", "b", "c"]),
oh.make_tensor_value_info("Y", TFLOAT, ["a", "b", "c"]),
Expand Down
10 changes: 5 additions & 5 deletions _doc/examples/plot_failing_onnxruntime_evaluator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
.. _l-plot-failing-onnxruntime-evaluator:

Running OnnxruntimeEvaluator on a failing model
===============================================
Intermediate results with onnxruntime
=====================================

Example :ref:`l-plot-failing-reference-evaluator` demonstrated
how to run a python runtime on a model but it may very slow sometimes
and it could show some discrepancies if the only provider is not CPU.
Let's use :class:`OnnxruntimeEvaluator <onnx_diagnostic.reference.OnnxruntimeEvaluator>`.
It splits the model into node and runs them independantly until it succeeds
It splits the model into node and runs them independently until it succeeds
or fails. This class converts every node into model based on the types
discovered during the execution. It relies on :class:`InferenceSessionForTorch
<onnx_diagnostic.ort_session.InferenceSessionForTorch>` or
Expand Down Expand Up @@ -43,7 +43,7 @@
oh.make_node("Cast", ["C"], ["X999"], to=999, name="failing"),
oh.make_node("CastLike", ["X999", "Y"], ["Z"], name="n4"),
],
"nd",
"-nd-",
[
oh.make_tensor_value_info("X", TBFLOAT16, ["a", "b", "c"]),
oh.make_tensor_value_info("Y", TBFLOAT16, ["a", "b", "c"]),
Expand Down Expand Up @@ -100,7 +100,7 @@
# %%
# We can see it run until it reaches `Cast` and stops.
# The error message is not always obvious to interpret.
# It gets improved everytime from time to time.
# It gets improved every time from time to time.
# This runtime is useful when it fails for a numerical reason.
# It is possible to insert prints in the python code to print
# more information or debug if needed.
8 changes: 4 additions & 4 deletions _doc/examples/plot_failing_reference_evaluator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
.. _l-plot-failing-reference-evaluator:

Running ReferenceEvaluator on a failing model
=============================================
Intermediate results with (ONNX) ReferenceEvaluator
===================================================

Let's assume :epkg:`onnxruntime` crashes without telling why or where.
The first thing is do is to locate where. For that, we run a python runtime
Expand Down Expand Up @@ -33,7 +33,7 @@
oh.make_node("Cast", ["C"], ["X999"], to=999, name="failing"),
oh.make_node("CastLike", ["X999", "Y"], ["Z"], name="n4"),
],
"nd",
"-nd-",
[
oh.make_tensor_value_info("X", TFLOAT, ["a", "b", "c"]),
oh.make_tensor_value_info("Y", TFLOAT, ["a", "b", "c"]),
Expand Down Expand Up @@ -75,7 +75,7 @@
# %%
# We can see it run until it reaches `Cast` and stops.
# The error message is not always obvious to interpret.
# It gets improved everytime from time to time.
# It gets improved every time from time to time.
# This runtime is useful when it fails for a numerical reason.
# It is possible to insert prints in the python code to print
# more information or debug if needed.
29 changes: 26 additions & 3 deletions _doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ onnx-diagnostic: investigate onnx models
.. image:: https://codecov.io/gh/sdpython/onnx-diagnostic/branch/main/graph/badge.svg?token=Wb9ZGDta8J
:target: https://codecov.io/gh/sdpython/onnx-diagnostic

**onnx-diagnostic** helps investgating onnx models, exporting models into onnx.
**onnx-diagnostic** helps investigating onnx models, exporting models into onnx.
It implements tools used to understand issues.

Source are `sdpython/onnx-diagnostic
Expand All @@ -38,12 +38,33 @@ Source are `sdpython/onnx-diagnostic
CHANGELOGS
license

**Enlightening Examples**
Getting started
+++++++++++++++

::

git clone https://github.com/sdpython/onnx-diagnostic.git
cd onnx-diagnostic
pip install -e .

or

::

pip install onnx-diagnostic

Enlightening Examples
+++++++++++++++++++++

**Torch Export**

* :ref:`l-plot-export-cond`
* :ref:`l-plot-sxport-with-dynamio-shapes-auto`
* :ref:`l-plot-export-with-dynamic-shape`
* :ref:`l-plot-tiny-llm-export`

**Investigate ONNX models**

* :ref:`l-plot-failing-reference-evaluator`
* :ref:`l-plot-failing-onnxruntime-evaluator`
* :ref:`l-plot-failing-model-extract`
Expand Down Expand Up @@ -137,6 +158,8 @@ Size of the package:
gr = df[["dir", "ext", "lines", "chars"]].groupby(["ext", "dir"]).sum()
print(gr)

**Older versions**
Older versions
++++++++++++++

* `0.2.0 <../v0.2.0/index.html>`_
* `0.1.0 <../v0.1.0/index.html>`_
6 changes: 3 additions & 3 deletions _unittests/ut_xrun_doc/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_pretty_onnx(self):
oh.make_node("Mul", ["Y", "sy"], ["ysy"]),
oh.make_node("Mul", ["X", "ysy"], ["final"]),
],
"nd",
"-nd-",
[
oh.make_tensor_value_info("X", TFLOAT, [1, "b", "c"]),
oh.make_tensor_value_info("Y", TFLOAT, ["a", "b", "c"]),
Expand All @@ -111,7 +111,7 @@ def test_print_pretty_onnx(self):
oh.make_node("Mul", ["Y", "sy"], ["ysy"]),
oh.make_node("Mul", ["X", "ysy"], ["final"]),
],
"nd",
"-nd-",
[
oh.make_tensor_value_info("X", TFLOAT, [1, "b", "c"]),
oh.make_tensor_value_info("Y", TFLOAT, ["a", "b", "c"]),
Expand All @@ -136,7 +136,7 @@ def test_get_onnx_signature(self):
oh.make_node("Mul", ["Y", "sy"], ["ysy"]),
oh.make_node("Mul", ["X", "ysy"], ["final"]),
],
"nd",
"-nd-",
[
oh.make_tensor_value_info("X", TFLOAT, [1, "b", "c"]),
oh.make_tensor_value_info("Y", TFLOAT, ["a", "b", "c"]),
Expand Down
4 changes: 2 additions & 2 deletions onnx_diagnostic/export/dynamic_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(
), f"unexpected type for model={type(model)}, it must be a torch.nn.Module"
assert name, (
f"name={name!r} cannot be empty this string is used to "
f"display meaningfull error messages"
f"display meaningful error messages"
)
self.name = name
self.model = model
Expand Down Expand Up @@ -195,7 +195,7 @@ def process_inputs(
"""
if not isinstance(inputs, list):
raise ValueError(
f"inputs should be specifed as a list of sets of "
f"inputs should be specified as a list of sets of "
f"inputs but type(inputs) is {type(inputs)}"
)
new_inputs = []
Expand Down
12 changes: 7 additions & 5 deletions onnx_diagnostic/ext_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def measure_time(
real measurement
:param div_by_number: divide by the number of executions
:param max_time: execute the statement until the total goes
beyond this time (approximatively), *repeat* is ignored,
beyond this time (approximately), *repeat* is ignored,
*div_by_number* must be set to True
:return: dictionary

Expand Down Expand Up @@ -678,7 +678,7 @@ def requires_cuda(msg: str = "", version: str = "", memory: int = 0):

:param msg: to overwrite the message
:param version: minimum version
:param memory: minimun number of Gb to run the test
:param memory: minimum number of Gb to run the test
"""
import torch

Expand Down Expand Up @@ -1073,9 +1073,11 @@ def statistics_on_folder(
"""
if isinstance(folder, list):
rows = []
for fo in folder:
last = fo.replace("\\", "/").split("/")[-1]
r = statistics_on_folder(fo, pattern=pattern, aggregation=max(aggregation - 1, 0))
for fold in folder:
last = fold.replace("\\", "/").split("/")[-1]
r = statistics_on_folder(
fold, pattern=pattern, aggregation=max(aggregation - 1, 0)
)
if aggregation == 0:
rows.extend(r)
continue
Expand Down
2 changes: 1 addition & 1 deletion onnx_diagnostic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ def max_diff(
allow a comparison between a single tensor and a list of one tensor
:return: dictionary with many values

* abs: max abolute error
* abs: max absolute error
* rel: max relative error
* sum: sum of the errors
* n: number of outputs values, if there is one
Expand Down
2 changes: 1 addition & 1 deletion onnx_diagnostic/onnx_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def onnx_unlighten(
The model is modified inplace.

:param onx: model
:param stats: statics, can be None if onx is a file,
:param stats: statistics, can be None if onx is a file,
then it loads the file ``<filename>.stats``,
it assumes it is json format
:param verbose: verbosity
Expand Down
4 changes: 2 additions & 2 deletions onnx_diagnostic/reference/ort_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OnnxruntimeEvaluator:
This class loads an onnx model and the executes one by one the nodes
with onnxruntime. This class is mostly meant for debugging.

:param proto: proto or filaname
:param proto: proto or filename
:param session_options: options
:param providers: providers
:param nvtx: enable nvidia events
Expand All @@ -37,7 +37,7 @@ class OnnxruntimeEvaluator:
:param use_training_api: use onnxruntime-traning API
:param verbose: verbosity
:param local_functions: additional local function
:param ir_version: ir verions to use when unknown
:param ir_version: ir version to use when unknown
:param opsets: opsets to use when unknown
"""

Expand Down
Loading
Loading