Skip to content

Commit f1353ac

Browse files
committed
Add command line
1 parent e92c72b commit f1353ac

File tree

3 files changed

+65
-27
lines changed

3 files changed

+65
-27
lines changed
9.19 KB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import unittest
3+
from contextlib import redirect_stdout
4+
from io import StringIO
5+
from onnx_diagnostic.ext_test_case import ExtTestCase
6+
from onnx_diagnostic._command_lines_parser import main
7+
8+
9+
class TestCommandLines(ExtTestCase):
10+
@property
11+
def dummy_path(self):
12+
return os.path.abspath(
13+
os.path.join(os.path.dirname(__file__), "data", "two_nodes.onnx")
14+
)
15+
16+
def test_parser_print(self):
17+
st = StringIO()
18+
with redirect_stdout(st):
19+
main(["print", "raw", self.dummy_path])
20+
text = st.getvalue()
21+
self.assertIn("Add", text)
22+
23+
def test_parser_find(self):
24+
st = StringIO()
25+
with redirect_stdout(st):
26+
main(["find", "-i", self.dummy_path, "-n", "node_Add_188"])
27+
text = st.getvalue()
28+
self.assertIsInstance(text, str)
29+
30+
def test_parser_config(self):
31+
st = StringIO()
32+
with redirect_stdout(st):
33+
main(["config", "-m", "arnir0/Tiny-LLM"])
34+
text = st.getvalue()
35+
self.assertIn("LlamaForCausalLM", text)
36+
37+
38+
if __name__ == "__main__":
39+
unittest.main(verbosity=2)

onnx_diagnostic/_command_lines_parser.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,6 @@
77
from textwrap import dedent
88

99

10-
def get_main_parser() -> ArgumentParser:
11-
parser = ArgumentParser(
12-
prog="onnx_diagnostic",
13-
description="onnx_diagnostic main command line.\n",
14-
formatter_class=RawTextHelpFormatter,
15-
epilog=textwrap.dedent(
16-
"""
17-
Type 'python -m onnx_diagnostic <cmd> --help'
18-
to get help for a specific command.
19-
20-
lighten - makes an onnx model lighter by removing the weights,
21-
unlighten - restores an onnx model produces by the previous experiment
22-
run - runs a model and measure the inference time
23-
print - prints the model on standard output
24-
find - find node consuming or producing a result
25-
config - prints a configuration for a model id
26-
"""
27-
),
28-
)
29-
parser.add_argument(
30-
"cmd",
31-
choices=["lighten", "unlighten", "run", "print", "find", "config"],
32-
help="Selects a command.",
33-
)
34-
return parser
35-
36-
3710
def get_parser_lighten() -> ArgumentParser:
3811
parser = ArgumentParser(
3912
prog="lighten",
@@ -254,6 +227,32 @@ def _cmd_config(argv: List[Any]):
254227
print(f"task: {task_from_id(args.mid)}")
255228

256229

230+
def get_main_parser() -> ArgumentParser:
231+
parser = ArgumentParser(
232+
prog="onnx_diagnostic",
233+
description="onnx_diagnostic main command line.\n",
234+
formatter_class=RawTextHelpFormatter,
235+
epilog=textwrap.dedent(
236+
"""
237+
Type 'python -m onnx_diagnostic <cmd> --help'
238+
to get help for a specific command.
239+
240+
lighten - makes an onnx model lighter by removing the weights,
241+
unlighten - restores an onnx model produces by the previous experiment
242+
print - prints the model on standard output
243+
find - find node consuming or producing a result
244+
config - prints a configuration for a model id
245+
"""
246+
),
247+
)
248+
parser.add_argument(
249+
"cmd",
250+
choices=["lighten", "unlighten", "run", "print", "find", "config"],
251+
help="Selects a command.",
252+
)
253+
return parser
254+
255+
257256
def main(argv: Optional[List[Any]] = None):
258257
fcts = dict(
259258
lighten=_cmd_lighten,

0 commit comments

Comments
 (0)