Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _unittests/ut_torch_models/test_hghub_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestHuggingFaceHubModel(ExtTestCase):
@hide_stdout()
def test_get_untrained_model_with_inputs_tiny_llm(self):
mid = "arnir0/Tiny-LLM"
data = get_untrained_model_with_inputs(mid, verbose=1)
data = get_untrained_model_with_inputs(mid, verbose=1, add_second_input=0)
self.assertEqual(
set(data),
{
Expand Down
20 changes: 16 additions & 4 deletions onnx_diagnostic/_command_lines_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ def get_parser_validate() -> ArgumentParser:
python -m onnx_diagnostic validate -m microsoft/Phi-4-mini-reasoning \\
--run -v 1 -o dump_test --no-quiet --repeat 2 --warmup 2 \\
--dtype float16 --device cuda --export modelbuilder

position_ids is usually not needed, they can be removed by adding:

--drop position_ids

The behaviour may be modified compare the original configuration,
the following argument can be rope_scaling to dynamic:

--mop \"rope_scaling={'rope_type': 'dynamic', 'factor': 10.0}\""
"""
),
formatter_class=RawTextHelpFormatter,
Expand Down Expand Up @@ -403,10 +412,12 @@ def get_parser_validate() -> ArgumentParser:
)
parser.add_argument(
"--inputs2",
default=True,
action=BooleanOptionalAction,
default=1,
type=int,
help="Validates the model on a second set of inputs\n"
"to check the exported model supports dynamism.",
"to check the exported model supports dynamism. The values is used "
"as an increment to the first set of inputs. A high value may trick "
"a different behavior in the model and missed by the exporter.",
)
parser.add_argument(
"--runtime",
Expand All @@ -422,7 +433,8 @@ def get_parser_validate() -> ArgumentParser:
parser.add_argument(
"--drop",
help="Drops the following inputs names, it should be a list\n"
"with comma separated values.",
"with comma separated values, example:\n"
"--drop position_ids",
)
parser.add_argument(
"--opset",
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/automatic_speech_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_inputs(
head_dim: int,
batch_size: int = 2,
sequence_length: int = 30,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -132,6 +132,9 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
Expand All @@ -144,7 +147,8 @@ def get_inputs(
decoder_layers=decoder_layers,
head_dim=head_dim,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_inputs(
batch_size: int,
sequence_length: int,
dummy_max_token_id: int,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -52,12 +52,16 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
dummy_max_token_id=dummy_max_token_id,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/fill_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_inputs(
batch_size: int,
sequence_length: int,
dummy_max_token_id: int,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -54,12 +54,16 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
dummy_max_token_id=dummy_max_token_id,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
10 changes: 7 additions & 3 deletions onnx_diagnostic/tasks/image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_inputs(
input_channels: int,
batch_size: int = 2,
dynamic_rope: bool = False,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -75,14 +75,18 @@ def get_inputs(
shapes["interpolate_pos_encoding"] = None # type: ignore[assignment]
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
input_width=input_width + 1,
input_height=input_height + 1,
input_width=input_width + add_second_input,
input_height=input_height + add_second_input,
input_channels=input_channels,
batch_size=batch_size + 1,
dynamic_rope=dynamic_rope,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/image_text_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_inputs(
sequence_length2: int = 3,
n_images: int = 2,
dynamic_rope: bool = False,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -105,6 +105,9 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
Expand All @@ -116,10 +119,11 @@ def get_inputs(
height=height,
num_channels=num_channels,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
sequence_length2=sequence_length2 + 1,
n_images=n_images + 1,
dynamic_rope=dynamic_rope,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
2 changes: 1 addition & 1 deletion onnx_diagnostic/tasks/mixture_of_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_inputs(
sequence_length2: int = 3,
n_images: int = 2,
dynamic_rope: bool = False,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down
10 changes: 7 additions & 3 deletions onnx_diagnostic/tasks/object_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_inputs(
input_channels: int,
batch_size: int = 2,
dynamic_rope: bool = False,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -65,14 +65,18 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
input_width=input_width + 1,
input_height=input_height + 1,
input_width=input_width + add_second_input,
input_height=input_height + add_second_input,
input_channels=input_channels,
batch_size=batch_size + 1,
dynamic_rope=dynamic_rope,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/sentence_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_inputs(
batch_size: int,
sequence_length: int,
dummy_max_token_id: int,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -54,12 +54,16 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
dummy_max_token_id=dummy_max_token_id,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_inputs(
batch_size: int = 2,
sequence_length: int = 30,
sequence_length2: int = 3,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -144,6 +144,9 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
Expand All @@ -154,8 +157,9 @@ def get_inputs(
head_dim_encoder=head_dim_encoder,
head_dim_decoder=head_dim_decoder,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
sequence_length2=sequence_length2 + 1,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/text2text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_inputs(
batch_size: int = 2,
sequence_length: int = 30,
sequence_length2: int = 3,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -149,6 +149,9 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
Expand All @@ -160,8 +163,9 @@ def get_inputs(
head_dim_decoder=head_dim_decoder,
encoder_dim=encoder_dim,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
sequence_length2=sequence_length2 + 1,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 6 additions & 2 deletions onnx_diagnostic/tasks/text_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_inputs(
batch_size: int,
sequence_length: int,
dummy_max_token_id: int,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -54,12 +54,16 @@ def get_inputs(
)
res = dict(inputs=inputs, dynamic_shapes=shapes)
if add_second_input:
assert (
add_second_input > 0
), f"Not implemented for add_second_input={add_second_input}."
res["inputs2"] = get_inputs(
model=model,
config=config,
batch_size=batch_size + 1,
sequence_length=sequence_length + 1,
sequence_length=sequence_length + add_second_input,
dummy_max_token_id=dummy_max_token_id,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
8 changes: 5 additions & 3 deletions onnx_diagnostic/tasks/text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_inputs(
num_key_value_heads: Optional[int] = None,
head_dim: Optional[int] = None,
cls_cache: Optional[Union[type, str]] = None,
add_second_input: bool = False,
add_second_input: int = 1,
**kwargs, # unused
):
"""
Expand Down Expand Up @@ -260,13 +260,15 @@ def get_inputs(
config=config,
dummy_max_token_id=dummy_max_token_id,
num_hidden_layers=num_hidden_layers,
batch_size=batch_size + 1,
batch_size=(batch_size + 1) if add_second_input > 0 else 1,
sequence_length=sequence_length + 1,
sequence_length2=sequence_length2 + 1,
sequence_length2=sequence_length2
+ (add_second_input if add_second_input > 0 else -add_second_input),
dynamic_rope=dynamic_rope,
num_key_value_heads=num_key_value_heads,
head_dim=head_dim,
cls_cache=cls_cache,
add_second_input=0,
**kwargs,
)["inputs"]
return res
Expand Down
Loading
Loading