diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml
new file mode 100644
index 00000000..3ceaf172
--- /dev/null
+++ b/.github/workflows/spell-check.yml
@@ -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
diff --git a/.github/workflows/wheels-any.yml b/.github/workflows/wheels-any.yml
index 614c1594..f294adb7 100644
--- a/.github/workflows/wheels-any.yml
+++ b/.github/workflows/wheels-any.yml
@@ -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:
diff --git a/README.rst b/README.rst
index 3b10abbc..fd04d8d1 100644
--- a/README.rst
+++ b/README.rst
@@ -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 `_.
+See `documentation of onnx-diagnostic `_.
Getting started
+++++++++++++++
@@ -43,7 +43,10 @@ or
pip install onnx-diagnostic
-**Enlightening Examples**
+Enlightening Examples
++++++++++++++++++++++
+
+**Torch Export**
* `Use DYNAMIC or AUTO when exporting if dynamic shapes has constraints
`_
@@ -51,10 +54,15 @@ or
`_
* `Steel method forward to guess the dynamic shapes
`_
-* `Running ReferenceEvaluator on a failing model
- `_
+
+**Investigate ONNX models**
+
* `Find where a model is failing by running submodels
`_
+* `Intermediate results with (ONNX) ReferenceEvaluator
+ `_
+* `Intermediate results with onnxruntime
+ `_
Snapshot of usefuls tools
+++++++++++++++++++++++++
@@ -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.
diff --git a/_doc/_static/custom.css b/_doc/_static/custom.css
new file mode 100644
index 00000000..c0f80feb
--- /dev/null
+++ b/_doc/_static/custom.css
@@ -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;
+}
diff --git a/_doc/conf.py b/_doc/conf.py
index 3203df41..a95d4714 100644
--- a/_doc/conf.py
+++ b/_doc/conf.py
@@ -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"
diff --git a/_doc/examples/plot_export_tiny_llm.py b/_doc/examples/plot_export_tiny_llm.py
index 8785cf13..deb308bd 100644
--- a/_doc/examples/plot_export_tiny_llm.py
+++ b/_doc/examples/plot_export_tiny_llm.py
@@ -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
@@ -15,7 +15,7 @@
We focus on the model
`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
diff --git a/_doc/examples/plot_export_with_dynamic_cache.py b/_doc/examples/plot_export_with_dynamic_cache.py
index 98da9efe..4c19d173 100644
--- a/_doc/examples/plot_export_with_dynamic_cache.py
+++ b/_doc/examples/plot_export_with_dynamic_cache.py
@@ -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])
@@ -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):
diff --git a/_doc/examples/plot_export_with_dynamic_shapes_auto.py b/_doc/examples/plot_export_with_dynamic_shapes_auto.py
index 2055f715..e7fcd246 100644
--- a/_doc/examples/plot_export_with_dynamic_shapes_auto.py
+++ b/_doc/examples/plot_export_with_dynamic_shapes_auto.py
@@ -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?
diff --git a/_doc/examples/plot_failing_model_extract.py b/_doc/examples/plot_failing_model_extract.py
index 591fbd1b..c1311e66 100644
--- a/_doc/examples/plot_failing_model_extract.py
+++ b/_doc/examples/plot_failing_model_extract.py
@@ -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"]),
diff --git a/_doc/examples/plot_failing_onnxruntime_evaluator.py b/_doc/examples/plot_failing_onnxruntime_evaluator.py
index be274919..205ef9cc 100644
--- a/_doc/examples/plot_failing_onnxruntime_evaluator.py
+++ b/_doc/examples/plot_failing_onnxruntime_evaluator.py
@@ -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 `.
-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
` or
@@ -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"]),
@@ -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.
diff --git a/_doc/examples/plot_failing_reference_evaluator.py b/_doc/examples/plot_failing_reference_evaluator.py
index c3e2a202..f43962e4 100644
--- a/_doc/examples/plot_failing_reference_evaluator.py
+++ b/_doc/examples/plot_failing_reference_evaluator.py
@@ -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
@@ -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"]),
@@ -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.
diff --git a/_doc/index.rst b/_doc/index.rst
index 4abb688c..2d85f012 100644
--- a/_doc/index.rst
+++ b/_doc/index.rst
@@ -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
@@ -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`
@@ -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>`_
diff --git a/_unittests/ut_xrun_doc/test_helpers.py b/_unittests/ut_xrun_doc/test_helpers.py
index 0fef8bd1..7eb5abb4 100644
--- a/_unittests/ut_xrun_doc/test_helpers.py
+++ b/_unittests/ut_xrun_doc/test_helpers.py
@@ -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"]),
@@ -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"]),
@@ -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"]),
diff --git a/onnx_diagnostic/export/dynamic_shapes.py b/onnx_diagnostic/export/dynamic_shapes.py
index bb952ebe..4f8eb880 100644
--- a/onnx_diagnostic/export/dynamic_shapes.py
+++ b/onnx_diagnostic/export/dynamic_shapes.py
@@ -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
@@ -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 = []
diff --git a/onnx_diagnostic/ext_test_case.py b/onnx_diagnostic/ext_test_case.py
index a6f38c8b..db552bac 100644
--- a/onnx_diagnostic/ext_test_case.py
+++ b/onnx_diagnostic/ext_test_case.py
@@ -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
@@ -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
@@ -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
diff --git a/onnx_diagnostic/helpers.py b/onnx_diagnostic/helpers.py
index b3fbe468..dab640c4 100644
--- a/onnx_diagnostic/helpers.py
+++ b/onnx_diagnostic/helpers.py
@@ -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
diff --git a/onnx_diagnostic/onnx_tools.py b/onnx_diagnostic/onnx_tools.py
index 1bdc3548..e2075e3c 100644
--- a/onnx_diagnostic/onnx_tools.py
+++ b/onnx_diagnostic/onnx_tools.py
@@ -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 ``.stats``,
it assumes it is json format
:param verbose: verbosity
diff --git a/onnx_diagnostic/reference/ort_evaluator.py b/onnx_diagnostic/reference/ort_evaluator.py
index 501017f5..209558db 100644
--- a/onnx_diagnostic/reference/ort_evaluator.py
+++ b/onnx_diagnostic/reference/ort_evaluator.py
@@ -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
@@ -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
"""
diff --git a/onnx_diagnostic/torch_export_patches/onnx_export_errors.py b/onnx_diagnostic/torch_export_patches/onnx_export_errors.py
index 0fbc0da6..26354624 100644
--- a/onnx_diagnostic/torch_export_patches/onnx_export_errors.py
+++ b/onnx_diagnostic/torch_export_patches/onnx_export_errors.py
@@ -123,7 +123,7 @@ def _unregister(cls: type, verbose: int = 0):
torch.utils._pytree._deregister_pytree_node(cls)
optree.unregister_pytree_node(cls, namespace="torch")
assert cls not in torch.utils._pytree.SUPPORTED_NODES, (
- f"{cls} was not successfull unregistered "
+ f"{cls} was not successful unregistered "
f"from torch.utils._pytree.SUPPORTED_NODES="
f"{pprint.pformat(list(torch.utils._pytree.SUPPORTED_NODES))}"
)
@@ -201,8 +201,8 @@ def bypass_export_some_errors(
* ``torch._subclasses.fake_impls.infer_size``
* fix missing method ``name`` for ``sympy.S.IntegerConstant``
* ``AttentionMaskConverter._make_causal_mask``
- * Serialialization of ``MambaCache`` (in :epkg:`transformers`)
- * Serialialization of ``DynamicCache`` (in :epkg:`transformers`)
+ * Serialization of ``MambaCache`` (in :epkg:`transformers`)
+ * Serialization of ``DynamicCache`` (in :epkg:`transformers`)
* reduce errors due to shape inference
* replaces :class:`transformers.cache_utils.DynamicCache` with
:class:`patched_DynamicCache
diff --git a/onnx_diagnostic/torch_test_helper.py b/onnx_diagnostic/torch_test_helper.py
index 46c1d3b6..6008dad1 100644
--- a/onnx_diagnostic/torch_test_helper.py
+++ b/onnx_diagnostic/torch_test_helper.py
@@ -11,7 +11,7 @@
def to_numpy(tensor: "torch.Tensor"): # noqa: F821
"""
- Convets a torch tensor to numy.
+ Converts a torch tensor to numy.
"""
try:
return tensor.numpy()
diff --git a/setup.py b/setup.py
index f1c50293..3bce0bf1 100644
--- a/setup.py
+++ b/setup.py
@@ -40,6 +40,7 @@
version=version_str,
description="Investigate ONNX models",
long_description=long_description,
+ long_description_content_type="text/x-rst",
author="Xavier Dupré",
author_email="xavier.dupre@gmail.com",
url="https://github.com/sdpython/onnx-diagnostic",