Skip to content

Commit bea8445

Browse files
authored
increase code coverage (#10)
* if code coverage * fix issues
1 parent 525ae26 commit bea8445

File tree

3 files changed

+148
-1
lines changed

3 files changed

+148
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Check Release
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
# every first day of the week
6+
- cron: '0 0 * * *'
7+
# push:
8+
9+
jobs:
10+
11+
release-linux-mac:
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macOS-latest]
15+
python-version: ['3.12', '3.11', '3.10']
16+
runs-on: ${{ matrix.os }}
17+
steps:
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install onnx-diagnostic
22+
run: pip install onnx-diagnostic
23+
- name: Version
24+
run: |
25+
python -c "import onnx_diagnostic;print(onnx_diagnostic.__version__)"
26+
- name: Installation path
27+
run: python -c "import onnx_diagnostic;print(onnx_diagnostic.__file__)"
28+
- name: git checkout
29+
run: |
30+
git init
31+
git remote add -f origin https://github.com/sdpython/onnx-diagnostic.git
32+
git config core.sparsecheckout true
33+
echo _unittests/ >> .git/info/sparse-checkout
34+
echo _doc/examples/ >> .git/info/sparse-checkout
35+
echo pyproject.toml >> .git/info/sparse-checkout
36+
echo requirements-dev.txt >> .git/info/sparse-checkout
37+
git pull origin main
38+
VERSION=$(python -c "import onnx_diagnostic;print(onnx_diagnostic.__version__)")
39+
git checkout tags/${VERSION} -b thistag
40+
- name: ls
41+
run: ls .
42+
- name: Install requirements
43+
run: pip install -r requirements-dev.txt
44+
- name: Run pytest
45+
run: pytest _unittests
46+
47+
release-windows:
48+
strategy:
49+
matrix:
50+
os: [windows-latest]
51+
python-version: ['3.12', '3.11', '3.10']
52+
runs-on: ${{ matrix.os }}
53+
steps:
54+
- uses: actions/setup-python@v4
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
- name: Install onnx-diagnostic
58+
run: pip install onnx-diagnostic
59+
- name: Version
60+
run: |
61+
python -c "import onnx_diagnostic;print(onnx_diagnostic.__version__)"
62+
- name: Installation path
63+
run: python -c "import onnx_diagnostic;print(onnx_diagnostic.__file__)"
64+
- name: git checkout
65+
run: |
66+
git init
67+
git remote add -f origin https://github.com/sdpython/onnx-diagnostic.git
68+
git config core.sparsecheckout true
69+
echo _unittests/ >> .git\info\sparse-checkout
70+
echo _doc/examples/ >> .git\info\sparse-checkout
71+
echo pyproject.toml >> .git\info\sparse-checkout
72+
echo requirements-dev.txt >> .git/info/sparse-checkout
73+
git pull origin main
74+
git checkout tags/0.2.2 -b thistag
75+
- name: ls
76+
run: ls .
77+
- name: Install requirements
78+
run: pip install -r requirements-dev.txt
79+
- name: Run pytest
80+
run: pytest _unittests

_doc/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ onnx-diagnostic: investigate onnx models
1818
.. image:: https://codecov.io/gh/sdpython/onnx-diagnostic/branch/main/graph/badge.svg?token=Wb9ZGDta8J
1919
:target: https://codecov.io/gh/sdpython/onnx-diagnostic
2020

21-
**onnx-diagnostic** is mostly to experiment ideas.
21+
**onnx-diagnostic** helps investgating onnx models, exporting models into onnx.
22+
It implements tools used to understand issues.
2223

2324
Source are `sdpython/onnx-diagnostic
2425
<https://github.com/sdpython/onnx-diagnostic>`_.

_unittests/ut_reference/test_ort_evaluator.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ml_dtypes
55
from onnx import ModelProto, TensorProto
66
from onnx.checker import check_model
7+
import onnx
78
import onnx.helper as oh
89
import onnx.numpy_helper as onh
910
import torch
@@ -248,6 +249,71 @@ def test_init_torch_bfloat16(self):
248249
self.assertIsInstance(got[0], (torch.Tensor, np.ndarray))
249250
self.assertEqualArray(expected[0], got[0])
250251

252+
@hide_stdout()
253+
def test_if(self):
254+
255+
def _mkv_(name):
256+
value_info_proto = onnx.ValueInfoProto()
257+
value_info_proto.name = name
258+
return value_info_proto
259+
260+
model = oh.make_model(
261+
oh.make_graph(
262+
[
263+
oh.make_node("ReduceSum", ["X"], ["Xred"]),
264+
oh.make_node("Add", ["X", "two"], ["X0"]),
265+
oh.make_node("Add", ["X0", "zero"], ["X00"]),
266+
oh.make_node("CastLike", ["one", "Xred"], ["one_c"]),
267+
oh.make_node("Greater", ["Xred", "one_c"], ["cond"]),
268+
oh.make_node(
269+
"If",
270+
["cond"],
271+
["Z_c"],
272+
then_branch=oh.make_graph(
273+
[
274+
oh.make_node("Constant", [], ["two"], value_floats=[2.1]),
275+
oh.make_node("Add", ["X00", "two"], ["Y"]),
276+
],
277+
"then",
278+
[],
279+
[_mkv_("Y")],
280+
),
281+
else_branch=oh.make_graph(
282+
[
283+
oh.make_node("Constant", [], ["two"], value_floats=[2.2]),
284+
oh.make_node("Sub", ["X0", "two"], ["Y"]),
285+
],
286+
"else",
287+
[],
288+
[_mkv_("Y")],
289+
),
290+
),
291+
oh.make_node("CastLike", ["Z_c", "X"], ["Z"]),
292+
],
293+
"test",
294+
[
295+
oh.make_tensor_value_info("X", TensorProto.FLOAT, ["N"]),
296+
oh.make_tensor_value_info("one", TensorProto.FLOAT, ["N"]),
297+
],
298+
[oh.make_tensor_value_info("Z", TensorProto.UNDEFINED, ["N"])],
299+
[
300+
onh.from_array(np.array([0], dtype=np.float32), name="zero"),
301+
onh.from_array(np.array([2], dtype=np.float32), name="two"),
302+
],
303+
),
304+
opset_imports=[oh.make_operatorsetid("", 18)],
305+
ir_version=10,
306+
)
307+
feeds = {
308+
"X": np.array([1, 2, 3], dtype=np.float32),
309+
"one": np.array([1], dtype=np.float32),
310+
}
311+
ref = ExtendedReferenceEvaluator(model, verbose=10)
312+
expected = ref.run(None, feeds)[0]
313+
sess = OnnxruntimeEvaluator(model, verbose=10)
314+
got = sess.run(None, feeds)[0]
315+
self.assertEqualArray(expected[0], got[0])
316+
251317

252318
if __name__ == "__main__":
253319
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)