Skip to content

Commit 4d55177

Browse files
committed
command line
1 parent 64999f9 commit 4d55177

File tree

8 files changed

+521
-0
lines changed

8 files changed

+521
-0
lines changed

_doc/cmds/config.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
-m onnx_diagnostic config ... prints the config for a model id
2+
==============================================================
3+
4+
Description
5+
+++++++++++
6+
7+
The command lines prints out the configuration file a model id
8+
available on :epkg:`HuggingFace`.
9+
10+
.. runpython::
11+
12+
from onnx_diagnostic._command_lines_parser import get_parser_config
13+
14+
get_parser_config().print_help()
15+
16+
Example
17+
+++++++
18+
19+
.. code-block:: bash
20+
21+
python -m onnx_diagnostic config HuggingFaceM4/tiny-random-idefics
22+
23+
.. code-block:: text
24+
25+
IdeficsConfig {
26+
"additional_vocab_size": 2,
27+
"alpha_initializer": "ones",
28+
"alpha_type": "vector",
29+
"alphas_initializer_range": 0.0,
30+
"architectures": [
31+
"IdeficsForVisionText2Text"
32+
],
33+
"bos_token_id": 1,
34+
"cross_layer_activation_function": "swiglu",
35+
"cross_layer_interval": 1,
36+
"dropout": 0.0,
37+
"eos_token_id": 2,
38+
"ffn_dim": 64,
39+
"freeze_lm_head": false,
40+
"freeze_text_layers": false,
41+
"freeze_text_module_exceptions": [],
42+
"freeze_vision_layers": false,
43+
"freeze_vision_module_exceptions": [],
44+
"hidden_act": "silu",
45+
"hidden_size": 16,
46+
"initializer_range": 0.02,
47+
"intermediate_size": 11008,
48+
"max_new_tokens": 128,
49+
"max_position_embeddings": 128,
50+
"model_type": "idefics",
51+
"num_attention_heads": 4,
52+
"num_hidden_layers": 2,
53+
"pad_token_id": 0,
54+
"perceiver_config": {
55+
"model_type": "idefics_perciever",
56+
"qk_layer_norms_perceiver": false,
57+
"resampler_depth": 2,
58+
"resampler_head_dim": 8,
59+
"resampler_n_heads": 2,
60+
"resampler_n_latents": 16,
61+
"use_resampler": false
62+
},
63+
"qk_layer_norms": false,
64+
"rms_norm_eps": 1e-06,
65+
"tie_word_embeddings": false,
66+
"torch_dtype": "float16",
67+
"transformers_version": "4.51.0.dev0",
68+
"use_cache": true,
69+
"use_resampler": true,
70+
"vision_config": {
71+
"attention_dropout": 0.0,
72+
"embed_dim": 32,
73+
"hidden_act": "gelu",
74+
"image_size": 30,
75+
"initializer_factor": 1.0,
76+
"initializer_range": 0.02,
77+
"intermediate_size": 37,
78+
"layer_norm_eps": 1e-05,
79+
"model_type": "idefics_vision",
80+
"num_attention_heads": 4,
81+
"num_channels": 3,
82+
"num_hidden_layers": 5,
83+
"patch_size": 2,
84+
"vision_model_name": "hf-internal-testing/tiny-random-clip"
85+
},
86+
"vocab_size": 32000,
87+
"word_embed_proj_dim": 16
88+
}

_doc/cmds/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Command Lines
2+
=============
3+
4+
.. code-block:: bash
5+
6+
python -m onnx_diagnostic
7+
8+
.. toctree::
9+
:maxdepth: 1
10+
11+
config

_doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Source are `sdpython/onnx-diagnostic
2929
:caption: Contents
3030

3131
api/index
32+
cmds/index
3233
auto_examples/index
3334

3435
.. toctree::
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import unittest
2+
from contextlib import redirect_stdout
3+
from io import StringIO
4+
from onnx_diagnostic.ext_test_case import ExtTestCase
5+
from onnx_diagnostic._command_lines_parser import (
6+
get_main_parser,
7+
get_parser_find,
8+
get_parser_lighten,
9+
get_parser_print,
10+
get_parser_unlighten,
11+
get_parser_config,
12+
)
13+
14+
15+
class TestCommandLines(ExtTestCase):
16+
def test_main_parser(self):
17+
st = StringIO()
18+
with redirect_stdout(st):
19+
get_main_parser().print_help()
20+
text = st.getvalue()
21+
self.assertIn("lighten", text)
22+
23+
def test_parser_lighten(self):
24+
st = StringIO()
25+
with redirect_stdout(st):
26+
get_parser_lighten().print_help()
27+
text = st.getvalue()
28+
self.assertIn("model", text)
29+
30+
def test_parser_unlighten(self):
31+
st = StringIO()
32+
with redirect_stdout(st):
33+
get_parser_unlighten().print_help()
34+
text = st.getvalue()
35+
self.assertIn("model", text)
36+
37+
def test_parser_print(self):
38+
st = StringIO()
39+
with redirect_stdout(st):
40+
get_parser_print().print_help()
41+
text = st.getvalue()
42+
self.assertIn("pretty", text)
43+
44+
def test_parser_find(self):
45+
st = StringIO()
46+
with redirect_stdout(st):
47+
get_parser_find().print_help()
48+
text = st.getvalue()
49+
self.assertIn("names", text)
50+
51+
def test_parser_config(self):
52+
st = StringIO()
53+
with redirect_stdout(st):
54+
get_parser_config().print_help()
55+
text = st.getvalue()
56+
self.assertIn("mid", text)
57+
58+
59+
if __name__ == "__main__":
60+
unittest.main(verbosity=2)

onnx_diagnostic/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from ._command_lines_parser import main
2+
3+
if __name__ == "__main__":
4+
main()

0 commit comments

Comments
 (0)