Skip to content

Commit 375a622

Browse files
authored
Check on bigger inputs (#179)
* Patches eager_mode for whisper-tiny * fix * fix ut * ut * fix * Change the meaning of inputs2, add_second_input * mechanism for inputs2 * fix ut
1 parent 3e6108d commit 375a622

18 files changed

+117
-41
lines changed

_unittests/ut_torch_models/test_hghub_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestHuggingFaceHubModel(ExtTestCase):
1717
@hide_stdout()
1818
def test_get_untrained_model_with_inputs_tiny_llm(self):
1919
mid = "arnir0/Tiny-LLM"
20-
data = get_untrained_model_with_inputs(mid, verbose=1)
20+
data = get_untrained_model_with_inputs(mid, verbose=1, add_second_input=0)
2121
self.assertEqual(
2222
set(data),
2323
{

onnx_diagnostic/_command_lines_parser.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,15 @@ def get_parser_validate() -> ArgumentParser:
349349
python -m onnx_diagnostic validate -m microsoft/Phi-4-mini-reasoning \\
350350
--run -v 1 -o dump_test --no-quiet --repeat 2 --warmup 2 \\
351351
--dtype float16 --device cuda --export modelbuilder
352+
353+
position_ids is usually not needed, they can be removed by adding:
354+
355+
--drop position_ids
356+
357+
The behaviour may be modified compare the original configuration,
358+
the following argument can be rope_scaling to dynamic:
359+
360+
--mop \"rope_scaling={'rope_type': 'dynamic', 'factor': 10.0}\""
352361
"""
353362
),
354363
formatter_class=RawTextHelpFormatter,
@@ -403,10 +412,12 @@ def get_parser_validate() -> ArgumentParser:
403412
)
404413
parser.add_argument(
405414
"--inputs2",
406-
default=True,
407-
action=BooleanOptionalAction,
415+
default=1,
416+
type=int,
408417
help="Validates the model on a second set of inputs\n"
409-
"to check the exported model supports dynamism.",
418+
"to check the exported model supports dynamism. The values is used "
419+
"as an increment to the first set of inputs. A high value may trick "
420+
"a different behavior in the model and missed by the exporter.",
410421
)
411422
parser.add_argument(
412423
"--runtime",
@@ -422,7 +433,8 @@ def get_parser_validate() -> ArgumentParser:
422433
parser.add_argument(
423434
"--drop",
424435
help="Drops the following inputs names, it should be a list\n"
425-
"with comma separated values.",
436+
"with comma separated values, example:\n"
437+
"--drop position_ids",
426438
)
427439
parser.add_argument(
428440
"--opset",

onnx_diagnostic/tasks/automatic_speech_recognition.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_inputs(
3333
head_dim: int,
3434
batch_size: int = 2,
3535
sequence_length: int = 30,
36-
add_second_input: bool = False,
36+
add_second_input: int = 1,
3737
**kwargs, # unused
3838
):
3939
"""
@@ -132,6 +132,9 @@ def get_inputs(
132132
)
133133
res = dict(inputs=inputs, dynamic_shapes=shapes)
134134
if add_second_input:
135+
assert (
136+
add_second_input > 0
137+
), f"Not implemented for add_second_input={add_second_input}."
135138
res["inputs2"] = get_inputs(
136139
model=model,
137140
config=config,
@@ -144,7 +147,8 @@ def get_inputs(
144147
decoder_layers=decoder_layers,
145148
head_dim=head_dim,
146149
batch_size=batch_size + 1,
147-
sequence_length=sequence_length + 1,
150+
sequence_length=sequence_length + add_second_input,
151+
add_second_input=0,
148152
**kwargs,
149153
)["inputs"]
150154
return res

onnx_diagnostic/tasks/feature_extraction.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_inputs(
2222
batch_size: int,
2323
sequence_length: int,
2424
dummy_max_token_id: int,
25-
add_second_input: bool = False,
25+
add_second_input: int = 1,
2626
**kwargs, # unused
2727
):
2828
"""
@@ -52,12 +52,16 @@ def get_inputs(
5252
)
5353
res = dict(inputs=inputs, dynamic_shapes=shapes)
5454
if add_second_input:
55+
assert (
56+
add_second_input > 0
57+
), f"Not implemented for add_second_input={add_second_input}."
5558
res["inputs2"] = get_inputs(
5659
model=model,
5760
config=config,
5861
batch_size=batch_size + 1,
59-
sequence_length=sequence_length + 1,
62+
sequence_length=sequence_length + add_second_input,
6063
dummy_max_token_id=dummy_max_token_id,
64+
add_second_input=0,
6165
**kwargs,
6266
)["inputs"]
6367
return res

onnx_diagnostic/tasks/fill_mask.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_inputs(
2222
batch_size: int,
2323
sequence_length: int,
2424
dummy_max_token_id: int,
25-
add_second_input: bool = False,
25+
add_second_input: int = 1,
2626
**kwargs, # unused
2727
):
2828
"""
@@ -54,12 +54,16 @@ def get_inputs(
5454
)
5555
res = dict(inputs=inputs, dynamic_shapes=shapes)
5656
if add_second_input:
57+
assert (
58+
add_second_input > 0
59+
), f"Not implemented for add_second_input={add_second_input}."
5760
res["inputs2"] = get_inputs(
5861
model=model,
5962
config=config,
6063
batch_size=batch_size + 1,
61-
sequence_length=sequence_length + 1,
64+
sequence_length=sequence_length + add_second_input,
6265
dummy_max_token_id=dummy_max_token_id,
66+
add_second_input=0,
6367
**kwargs,
6468
)["inputs"]
6569
return res

onnx_diagnostic/tasks/image_classification.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_inputs(
3434
input_channels: int,
3535
batch_size: int = 2,
3636
dynamic_rope: bool = False,
37-
add_second_input: bool = False,
37+
add_second_input: int = 1,
3838
**kwargs, # unused
3939
):
4040
"""
@@ -75,14 +75,18 @@ def get_inputs(
7575
shapes["interpolate_pos_encoding"] = None # type: ignore[assignment]
7676
res = dict(inputs=inputs, dynamic_shapes=shapes)
7777
if add_second_input:
78+
assert (
79+
add_second_input > 0
80+
), f"Not implemented for add_second_input={add_second_input}."
7881
res["inputs2"] = get_inputs(
7982
model=model,
8083
config=config,
81-
input_width=input_width + 1,
82-
input_height=input_height + 1,
84+
input_width=input_width + add_second_input,
85+
input_height=input_height + add_second_input,
8386
input_channels=input_channels,
8487
batch_size=batch_size + 1,
8588
dynamic_rope=dynamic_rope,
89+
add_second_input=0,
8690
**kwargs,
8791
)["inputs"]
8892
return res

onnx_diagnostic/tasks/image_text_to_text.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_inputs(
3232
sequence_length2: int = 3,
3333
n_images: int = 2,
3434
dynamic_rope: bool = False,
35-
add_second_input: bool = False,
35+
add_second_input: int = 1,
3636
**kwargs, # unused
3737
):
3838
"""
@@ -105,6 +105,9 @@ def get_inputs(
105105
)
106106
res = dict(inputs=inputs, dynamic_shapes=shapes)
107107
if add_second_input:
108+
assert (
109+
add_second_input > 0
110+
), f"Not implemented for add_second_input={add_second_input}."
108111
res["inputs2"] = get_inputs(
109112
model=model,
110113
config=config,
@@ -116,10 +119,11 @@ def get_inputs(
116119
height=height,
117120
num_channels=num_channels,
118121
batch_size=batch_size + 1,
119-
sequence_length=sequence_length + 1,
122+
sequence_length=sequence_length + add_second_input,
120123
sequence_length2=sequence_length2 + 1,
121124
n_images=n_images + 1,
122125
dynamic_rope=dynamic_rope,
126+
add_second_input=0,
123127
**kwargs,
124128
)["inputs"]
125129
return res

onnx_diagnostic/tasks/mixture_of_expert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_inputs(
4141
sequence_length2: int = 3,
4242
n_images: int = 2,
4343
dynamic_rope: bool = False,
44-
add_second_input: bool = False,
44+
add_second_input: int = 1,
4545
**kwargs, # unused
4646
):
4747
"""

onnx_diagnostic/tasks/object_detection.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_inputs(
2727
input_channels: int,
2828
batch_size: int = 2,
2929
dynamic_rope: bool = False,
30-
add_second_input: bool = False,
30+
add_second_input: int = 1,
3131
**kwargs, # unused
3232
):
3333
"""
@@ -65,14 +65,18 @@ def get_inputs(
6565
)
6666
res = dict(inputs=inputs, dynamic_shapes=shapes)
6767
if add_second_input:
68+
assert (
69+
add_second_input > 0
70+
), f"Not implemented for add_second_input={add_second_input}."
6871
res["inputs2"] = get_inputs(
6972
model=model,
7073
config=config,
71-
input_width=input_width + 1,
72-
input_height=input_height + 1,
74+
input_width=input_width + add_second_input,
75+
input_height=input_height + add_second_input,
7376
input_channels=input_channels,
7477
batch_size=batch_size + 1,
7578
dynamic_rope=dynamic_rope,
79+
add_second_input=0,
7680
**kwargs,
7781
)["inputs"]
7882
return res

onnx_diagnostic/tasks/sentence_similarity.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_inputs(
2222
batch_size: int,
2323
sequence_length: int,
2424
dummy_max_token_id: int,
25-
add_second_input: bool = False,
25+
add_second_input: int = 1,
2626
**kwargs, # unused
2727
):
2828
"""
@@ -54,12 +54,16 @@ def get_inputs(
5454
)
5555
res = dict(inputs=inputs, dynamic_shapes=shapes)
5656
if add_second_input:
57+
assert (
58+
add_second_input > 0
59+
), f"Not implemented for add_second_input={add_second_input}."
5760
res["inputs2"] = get_inputs(
5861
model=model,
5962
config=config,
6063
batch_size=batch_size + 1,
61-
sequence_length=sequence_length + 1,
64+
sequence_length=sequence_length + add_second_input,
6265
dummy_max_token_id=dummy_max_token_id,
66+
add_second_input=0,
6367
**kwargs,
6468
)["inputs"]
6569
return res

0 commit comments

Comments
 (0)