Skip to content

Commit 6ddb987

Browse files
committed
Merge branch 'main' of https://github.com/sdpython/onnx-diagnostic into titaipr
2 parents 9568e18 + 4866853 commit 6ddb987

File tree

11 files changed

+229
-97
lines changed

11 files changed

+229
-97
lines changed

CHANGELOGS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Change Logs
44
0.7.12
55
++++++
66

7+
* :pr:`232`: fixes ``--patch`` argument so that ``--patch=0`` works
8+
* :pr:`231`: better statistics about fusions
79
* :pr:`227`: better support for ``model_id//pretrained``, adds speed up when running command validate
810
* :pr:`226`: fix input order for models created with modelbuilder
911

_unittests/ut_helpers/test_log_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def test_cube_logs_performance_cube_time(self):
268268
cube = CubeLogsPerformance(dfs, keep_last_date=True)
269269
cube.load()
270270
ct = cube.clone()
271-
self.assertEqual((52, 106), ct.shape)
271+
self.assertEqual((52, 111), ct.shape)
272272

273273
def test_duplicate(self):
274274
df = pandas.DataFrame(

_unittests/ut_torch_models/test_hghub_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def test_enumerate_model_list(self):
3939
verbose=1,
4040
dump="test_enumerate_model_list.csv",
4141
filter="image-classification",
42-
library="transformers",
4342
)
4443
)
4544
self.assertEqual(len(models), 2)

_unittests/ut_xrun_doc/test_check_ort_float16.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ExtTestCase,
1111
ignore_warnings,
1212
requires_cuda,
13+
requires_onnxruntime,
1314
)
1415

1516

@@ -130,6 +131,7 @@ def common_scatter(self, opset, providers, dtype, reduction, expected_names):
130131

131132
@requires_cuda()
132133
@ignore_warnings(DeprecationWarning)
134+
@requires_onnxruntime("1.23")
133135
def test_scatterels_cuda(self):
134136
default_value = [
135137
"Cast",
@@ -143,6 +145,10 @@ def test_scatterels_cuda(self):
143145
(np.float16, "none"): default_value,
144146
(np.float32, "add"): default_value,
145147
(np.float16, "add"): default_value,
148+
(np.float32, "min"): default_value,
149+
(np.float16, "min"): default_value,
150+
(np.float32, "max"): default_value,
151+
(np.float16, "max"): default_value,
146152
}
147153
for opset, dtype, reduction in itertools.product(
148154
[16, 18], [np.float32, np.float16], ["none", "add", "min", "max"]
@@ -185,14 +191,14 @@ def test_scatternd_cuda(self):
185191
)
186192

187193
@ignore_warnings(DeprecationWarning)
194+
@requires_onnxruntime("1.23")
188195
def test_scatterels_cpu(self):
189196
default_value = [
190197
"Cast",
191198
"ScatterElements",
192199
"Sub",
193200
]
194201
default_value_16 = [
195-
"Cast",
196202
"Cast",
197203
"ScatterElements",
198204
"Cast",
@@ -218,14 +224,14 @@ def test_scatterels_cpu(self):
218224
)
219225

220226
@ignore_warnings(DeprecationWarning)
227+
@requires_onnxruntime("1.23")
221228
def test_scatternd_cpu(self):
222229
default_value = [
223230
"Cast",
224231
"ScatterND",
225232
"Sub",
226233
]
227234
default_value_16 = [
228-
"Cast",
229235
"Cast",
230236
"ScatterND",
231237
"Cast",

onnx_diagnostic/_command_lines_parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ def _cmd_validate(argv: List[Any]):
581581
):
582582
print(f"validate - unsupported args: export={args.export!r}, opt={args.opt!r}")
583583
return
584+
patch_dict = args.patch if isinstance(args.patch, dict) else {"patch": args.patch}
584585
summary, _data = validate_model(
585586
model_id=args.mid,
586587
task=args.task,
@@ -591,8 +592,8 @@ def _cmd_validate(argv: List[Any]):
591592
use_pretrained=args.trained,
592593
dtype=args.dtype,
593594
device=args.device,
594-
patch=args.patch,
595-
rewrite=args.rewrite,
595+
patch=patch_dict,
596+
rewrite=args.rewrite and patch_dict.get("patch", True),
596597
stop_if_static=args.stop_if_static,
597598
optimization=args.opt,
598599
exporter=args.export,
@@ -827,6 +828,8 @@ def get_parser_agg() -> ArgumentParser:
827828
"n_model_running,n_model_acc01,n_model_acc001,n_model_dynamic,"
828829
"n_model_pass,n_model_faster,"
829830
"n_model_faster2x,n_model_faster3x,n_model_faster4x,n_node_attention,"
831+
"n_node_attention23,n_node_rotary_embedding,n_node_rotary_embedding23,"
832+
"n_node_layer_normalization,n_node_layer_normalization23,"
830833
"peak_gpu_torch,peak_gpu_nvidia,n_node_control_flow,"
831834
"n_node_constant,n_node_shape,n_node_expand,"
832835
"n_node_function,n_node_initializer,n_node_scatter,"

onnx_diagnostic/helpers/log_helper.py

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ def _to_images_bar(
285285
nn = df.shape[1] // n_cols
286286
nn += int(df.shape[1] % n_cols != 0)
287287
ratio = float(os.environ.get("FIGSIZEH", "1"))
288-
fig, axs = plt.subplots(nn, n_cols, figsize=(6 * n_cols, nn * df.shape[0] / 3 * ratio))
288+
figsize = (6 * n_cols, nn * (2.5 + df.shape[0] / 15) * ratio)
289+
fig, axs = plt.subplots(nn, n_cols, figsize=figsize)
289290
pos = 0
290291
imgs = []
291292
for c in self._make_loop(df.columns, verbose):
@@ -332,10 +333,12 @@ def rotate_align(ax, angle=15, align="right"):
332333
n_cols = len(groups)
333334

334335
title_suffix = f"\n{title_suffix}" if title_suffix else ""
336+
ratio = float(os.environ.get("FIGSIZEH", "1"))
337+
figsize = (5 * n_cols, max(len(g) for g in groups) * (2 + df.shape[1] / 2) * ratio)
335338
fig, axs = plt.subplots(
336339
df.shape[1],
337340
n_cols,
338-
figsize=(5 * n_cols, max(len(g) for g in groups) * df.shape[1] / 2),
341+
figsize=figsize,
339342
sharex=True,
340343
sharey="row" if n_cols > 1 else False,
341344
)
@@ -877,7 +880,11 @@ def view(
877880
print(f"[CubeLogs.view] key_columns={key_columns}")
878881
g = data[[*key_index, *key_columns]].copy()
879882
g["count"] = 1
880-
r = g.groupby([*key_index, *key_columns], dropna=False).sum()
883+
r = (
884+
g.copy()
885+
if not key_index and not key_columns
886+
else g.groupby([*key_index, *key_columns], dropna=False).sum()
887+
)
881888
not_unique = r[r["count"] > 1]
882889
assert not_unique.shape[0] == 0, (
883890
f"view_def.name={view_def.name!r}, "
@@ -1505,6 +1512,11 @@ def __init__(
15051512
"n_model_faster3x",
15061513
"n_model_faster4x",
15071514
"n_node_attention",
1515+
"n_node_attention23",
1516+
"n_node_rotary_embedding",
1517+
"n_node_rotary_embedding23",
1518+
"n_node_layer_normalization",
1519+
"n_node_layer_normalization23",
15081520
"n_node_control_flow",
15091521
"n_node_scatter",
15101522
"n_node_function",
@@ -1568,7 +1580,9 @@ def _process_formula(
15681580

15691581
def gdf(df, cname, default_value=np.nan):
15701582
if cname in df.columns:
1571-
return df[cname]
1583+
if np.isnan(default_value):
1584+
return df[cname]
1585+
return df[cname].fillna(default_value)
15721586
return pandas.Series(default_value, index=df.index)
15731587

15741588
def ghas_value(df, cname):
@@ -1676,15 +1690,54 @@ def first_err(df: pandas.DataFrame) -> pandas.Series:
16761690
"time_latency",
16771691
gdf(df, "time_latency_eager") > gdf(df, "time_latency", np.inf) * 3.98,
16781692
),
1693+
n_node_attention23=lambda df: gpreserve(
1694+
df, "time_latency_eager", gdf(df, "op_onnx__Attention")
1695+
),
1696+
n_node_rotary_embedding23=lambda df: gpreserve(
1697+
df, "time_latency_eager", gdf(df, "op_onnx__RotaryEmbedding")
1698+
),
1699+
n_node_layer_normalization23=lambda df: gpreserve(
1700+
df,
1701+
"time_latency_eager",
1702+
gdf(df, "op_onnx__LayerNormalization", 0)
1703+
+ gdf(df, "op_onnx__RMSNormalization", 0)
1704+
+ gdf(df, "op_onnx__BatchNormlization", 0)
1705+
+ gdf(df, "op_onnx__InstanceNormlization", 0)
1706+
+ gdf(df, "op_onnx__GroupNormalization", 0),
1707+
),
16791708
n_node_attention=lambda df: gpreserve(
16801709
df,
1681-
"op_onnx_com.microsoft_Attention",
1682-
gdf(df, "op_onnx_com.microsoft_Attention")
1683-
+ gdf(df, "op_onnx_com.microsoft_MultiHeadAttention"),
1710+
"time_latency_eager",
1711+
gdf(df, "op_onnx_com.microsoft_Attention", 0)
1712+
+ gdf(df, "op_onnx_com.microsoft_MultiHeadAttention", 0)
1713+
+ gdf(df, "op_onnx_com.microsoft_PackedAttention", 0)
1714+
+ gdf(df, "op_onnx_com.microsoft_PackedMultiHeadAttention", 0)
1715+
+ gdf(df, "op_onnx_com.microsoft_GroupQueryAttention", 0)
1716+
+ gdf(df, "op_onnx_com.microsoft_PagedAttention", 0)
1717+
+ gdf(df, "op_onnx_com.microsoft_DecoderAttention", 0)
1718+
+ gdf(df, "op_onnx_com.microsoft_LongformerAttention", 0)
1719+
+ gdf(df, "op_onnx_com.microsoft_DecoderMaskedSelfAttention", 0)
1720+
+ gdf(df, "op_onnx_com.microsoft_DecoderMaskedMultiHeadAttention", 0)
1721+
+ gdf(df, "op_onnx_com.microsoft_SparseAttention", 0),
1722+
),
1723+
n_node_layer_normalization=lambda df: gpreserve(
1724+
df,
1725+
"time_latency_eager",
1726+
gdf(df, "op_onnx_com.microsoft_EmbedLayerNormalization", 0)
1727+
+ gdf(df, "op_onnx_com.microsoft_SkipLayerNormalization", 0)
1728+
+ gdf(df, "op_onnx_com.microsoft_LayerNormalization", 0)
1729+
+ gdf(df, "op_onnx_com.microsoft_SkipSimplifiedLayerNormalization", 0)
1730+
+ gdf(df, "op_onnx_com.microsoft_SimplifiedLayerNormalization", 0),
1731+
),
1732+
n_node_rotary_embedding=lambda df: gpreserve(
1733+
df,
1734+
"time_latency_eager",
1735+
gdf(df, "op_onnx_com.microsoft_GemmaRotaryEmbedding", 0)
1736+
+ gdf(df, "op_onnx_com.microsoft_RotaryEmbedding", 0),
16841737
),
16851738
n_node_control_flow=lambda df: gpreserve(
16861739
df,
1687-
"op_onnx__If",
1740+
"time_latency_eager",
16881741
(
16891742
gdf(df, "op_onnx__If", 0)
16901743
+ gdf(df, "op_onnx__Scan", 0)
@@ -1693,7 +1746,7 @@ def first_err(df: pandas.DataFrame) -> pandas.Series:
16931746
),
16941747
n_node_scatter=lambda df: gpreserve(
16951748
df,
1696-
"op_onnx__ScatterND",
1749+
"time_latency_eager",
16971750
gdf(df, "op_onnx__ScatterND", 0) + gdf(df, "op_onnx__ScatterElements", 0),
16981751
),
16991752
n_node_function=lambda df: gpreserve(
@@ -1706,13 +1759,13 @@ def first_err(df: pandas.DataFrame) -> pandas.Series:
17061759
df, "onnx_n_initializer", gdf(df, "onnx_n_initializer")
17071760
),
17081761
n_node_constant=lambda df: gpreserve(
1709-
df, "op_onnx__Constant", gdf(df, "op_onnx__Constant")
1762+
df, "time_latency_eager", gdf(df, "op_onnx__Constant")
17101763
),
17111764
n_node_shape=lambda df: gpreserve(
1712-
df, "op_onnx__Shape", gdf(df, "op_onnx__Shape")
1765+
df, "time_latency_eager", gdf(df, "op_onnx__Shape")
17131766
),
17141767
n_node_expand=lambda df: gpreserve(
1715-
df, "op_onnx__Expand", gdf(df, "op_onnx__Expand")
1768+
df, "time_latency_eager", gdf(df, "op_onnx__Expand")
17161769
),
17171770
)
17181771
assert (

onnx_diagnostic/torch_export_patches/onnx_export_errors.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ def torch_export_patches(
254254
may appear ``AssertionError: Mutating module attribute _seen_tokens during export.``.
255255
It can be avoided by setting ``strict=False`` when call :func:`torch.export.export`.
256256
"""
257+
if verbose:
258+
print(f"[torch_export_patches] patch_sympy={patch_sympy!r}")
259+
print(f" . patch_torch={patch_torch!r}")
260+
print(f" . patch_transformers={patch_transformers!r}")
261+
print(f" . patch_diffusers={patch_diffusers!r}")
262+
print(f" . catch_constraints={catch_constraints!r}")
263+
print(f" . stop_if_static={stop_if_static!r}")
264+
print(f" . patch={patch!r}")
265+
print(f" . custom_patches={custom_patches!r}")
266+
print(f"[torch_export_patches] dump_rewriting={dump_rewriting!r}")
267+
257268
if rewrite:
258269
from .patch_module import torch_export_rewrite
259270

onnx_diagnostic/torch_models/hghub/hub_api.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,31 +289,25 @@ def task_from_tags(tags: Union[str, List[str]]) -> str:
289289

290290
def enumerate_model_list(
291291
n: int = 50,
292-
task: Optional[str] = None,
293-
library: Optional[str] = None,
294-
tags: Optional[Union[str, List[str]]] = None,
292+
pipeline_tag: Optional[str] = None,
295293
search: Optional[str] = None,
296294
dump: Optional[str] = None,
297-
filter: Optional[str] = None,
295+
filter: Optional[Union[str, List[str]]] = None,
298296
verbose: int = 0,
299297
):
300298
"""
301299
Enumerates models coming from :epkg:`huggingface_hub`.
302300
303301
:param n: number of models to retrieve (-1 for all)
304-
:param task: see :meth:`huggingface_hub.HfApi.list_models`
305-
:param tags: see :meth:`huggingface_hub.HfApi.list_models`
306-
:param library: see :meth:`huggingface_hub.HfApi.list_models`
302+
:param pipeline_tag: see :meth:`huggingface_hub.HfApi.list_models`
307303
:param search: see :meth:`huggingface_hub.HfApi.list_models`
308304
:param filter: see :meth:`huggingface_hub.HfApi.list_models`
309305
:param dump: dumps the result in this csv file
310306
:param verbose: show progress
311307
"""
312308
api = HfApi()
313309
models = api.list_models(
314-
task=task,
315-
library=library,
316-
tags=tags,
310+
pipeline_tag=pipeline_tag,
317311
search=search,
318312
full=True,
319313
filter=filter,

0 commit comments

Comments
 (0)