From 11d65c3448f6fe53d521edc51896fb309e5c6eb0 Mon Sep 17 00:00:00 2001 From: xadupre Date: Mon, 24 Mar 2025 08:47:34 +0100 Subject: [PATCH 1/2] if code coverage --- _unittests/ut_reference/test_ort_evaluator.py | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/_unittests/ut_reference/test_ort_evaluator.py b/_unittests/ut_reference/test_ort_evaluator.py index 74994f0b..5795b913 100644 --- a/_unittests/ut_reference/test_ort_evaluator.py +++ b/_unittests/ut_reference/test_ort_evaluator.py @@ -4,6 +4,7 @@ import ml_dtypes from onnx import ModelProto, TensorProto from onnx.checker import check_model +import onnx import onnx.helper as oh import onnx.numpy_helper as onh import torch @@ -248,6 +249,71 @@ def test_init_torch_bfloat16(self): self.assertIsInstance(got[0], (torch.Tensor, np.ndarray)) self.assertEqualArray(expected[0], got[0]) + @hide_stdout() + def test_if(self): + + def _mkv_(name): + value_info_proto = onnx.ValueInfoProto() + value_info_proto.name = name + return value_info_proto + + model = oh.make_model( + oh.make_graph( + [ + oh.make_node("ReduceSum", ["X"], ["Xred"]), + oh.make_node("Add", ["X", "two"], ["X0"]), + oh.make_node("Add", ["X0", "zero"], ["X00"]), + oh.make_node("CastLike", ["one", "Xred"], ["one_c"]), + oh.make_node("Greater", ["Xred", "one_c"], ["cond"]), + oh.make_node( + "If", + ["cond"], + ["Z_c"], + then_branch=oh.make_graph( + [ + oh.make_node("Constant", [], ["two"], value_floats=[2.1]), + oh.make_node("Add", ["X00", "two"], ["Y"]), + ], + "then", + [], + [_mkv_("Y")], + ), + else_branch=oh.make_graph( + [ + oh.make_node("Constant", [], ["two"], value_floats=[2.2]), + oh.make_node("Sub", ["X0", "two"], ["Y"]), + ], + "else", + [], + [_mkv_("Y")], + ), + ), + oh.make_node("CastLike", ["Z_c", "X"], ["Z"]), + ], + "test", + [ + oh.make_tensor_value_info("X", TensorProto.FLOAT, ["N"]), + oh.make_tensor_value_info("one", TensorProto.FLOAT, ["N"]), + ], + [oh.make_tensor_value_info("Z", TensorProto.UNDEFINED, ["N"])], + [ + onh.from_array(np.array([0], dtype=np.float32), name="zero"), + onh.from_array(np.array([2], dtype=np.float32), name="two"), + ], + ), + opset_imports=[oh.make_operatorsetid("", 18)], + ir_version=10, + ) + feeds = { + "X": np.array([1, 2, 3], dtype=np.float32), + "one": np.array([1], dtype=np.float32), + } + ref = ExtendedReferenceEvaluator(model, verbose=10) + expected = ref.run(None, feeds)[0] + sess = OnnxruntimeEvaluator(model, verbose=10) + got = sess.run(None, feeds)[0] + self.assertEqualArray(expected[0], got[0]) + if __name__ == "__main__": unittest.main(verbosity=2) From ec1f51318550c30509797257cece5c55fec7799c Mon Sep 17 00:00:00 2001 From: xadupre Date: Mon, 24 Mar 2025 08:58:50 +0100 Subject: [PATCH 2/2] fix issues --- .github/workflows/check-release.yml | 80 +++++++++++++++++++++++++++++ _doc/index.rst | 3 +- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-release.yml diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml new file mode 100644 index 00000000..60ad76cf --- /dev/null +++ b/.github/workflows/check-release.yml @@ -0,0 +1,80 @@ +name: Check Release +on: + workflow_dispatch: + schedule: + # every first day of the week + - cron: '0 0 * * *' + # push: + +jobs: + + release-linux-mac: + strategy: + matrix: + os: [ubuntu-latest, macOS-latest] + python-version: ['3.12', '3.11', '3.10'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install onnx-diagnostic + run: pip install onnx-diagnostic + - name: Version + run: | + python -c "import onnx_diagnostic;print(onnx_diagnostic.__version__)" + - name: Installation path + run: python -c "import onnx_diagnostic;print(onnx_diagnostic.__file__)" + - name: git checkout + run: | + git init + git remote add -f origin https://github.com/sdpython/onnx-diagnostic.git + git config core.sparsecheckout true + echo _unittests/ >> .git/info/sparse-checkout + echo _doc/examples/ >> .git/info/sparse-checkout + echo pyproject.toml >> .git/info/sparse-checkout + echo requirements-dev.txt >> .git/info/sparse-checkout + git pull origin main + VERSION=$(python -c "import onnx_diagnostic;print(onnx_diagnostic.__version__)") + git checkout tags/${VERSION} -b thistag + - name: ls + run: ls . + - name: Install requirements + run: pip install -r requirements-dev.txt + - name: Run pytest + run: pytest _unittests + + release-windows: + strategy: + matrix: + os: [windows-latest] + python-version: ['3.12', '3.11', '3.10'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install onnx-diagnostic + run: pip install onnx-diagnostic + - name: Version + run: | + python -c "import onnx_diagnostic;print(onnx_diagnostic.__version__)" + - name: Installation path + run: python -c "import onnx_diagnostic;print(onnx_diagnostic.__file__)" + - name: git checkout + run: | + git init + git remote add -f origin https://github.com/sdpython/onnx-diagnostic.git + git config core.sparsecheckout true + echo _unittests/ >> .git\info\sparse-checkout + echo _doc/examples/ >> .git\info\sparse-checkout + echo pyproject.toml >> .git\info\sparse-checkout + echo requirements-dev.txt >> .git/info/sparse-checkout + git pull origin main + git checkout tags/0.2.2 -b thistag + - name: ls + run: ls . + - name: Install requirements + run: pip install -r requirements-dev.txt + - name: Run pytest + run: pytest _unittests diff --git a/_doc/index.rst b/_doc/index.rst index e6231eb6..21b74fa1 100644 --- a/_doc/index.rst +++ b/_doc/index.rst @@ -18,7 +18,8 @@ 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** is mostly to experiment ideas. +**onnx-diagnostic** helps investgating onnx models, exporting models into onnx. +It implements tools used to understand issues. Source are `sdpython/onnx-diagnostic `_.