Skip to content

Commit 39977bd

Browse files
authored
fix documentation (#370)
* fix documentation * dump * fix * fix validate * fix aggregation * documentation * output statistics * fix mypy * add timeout
1 parent 62d6ee2 commit 39977bd

5 files changed

Lines changed: 82 additions & 8 deletions

File tree

.github/workflows/models448.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
run:
1313
name: to-${{ matrix.torch }}-tr-${{ matrix.transformers }}-ci ${{ matrix.os }}-${{ matrix.python }}
1414
runs-on: ${{ matrix.os }}
15+
timeout-minutes: 15
16+
1517
strategy:
1618
fail-fast: false
1719
matrix:
@@ -64,5 +66,6 @@ jobs:
6466
run: python -m pip freeze
6567

6668
- name: Phi-4-multimodal-instruct - vision
69+
continue-on-error: true
6770
run: |
6871
PYTHONPATH=. python -m onnx_diagnostic.ci_models.export_phi4_mm -m microsoft/Phi-4-multimodal-instruct --device cpu --dtype float16 --exporter custom --no-pretrained --no-second-input --atol 100000164640 --mismatch01 1 --part vision

_doc/status/patches_diff.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ helps fixing some issues for many models.
3333
3434
Class :class:`PatchDetails <onnx_diagnostic.torch_export_patches.patch_details.PatchDetails>`
3535
gives an example on how to retrieve the list of involded patches for a specific model.
36-
Those patches belongs to the following list which depends on transformers and
37-
pytorch versions.
36+
Those patches belong to the following list which depends on :epkg:`transformers` and
37+
:epkg:`pytorch` versions.
3838

3939
.. runpython::
4040
:showcode:
@@ -62,7 +62,7 @@ Those two versions leads to the following list of patches.
6262
):
6363
pass
6464
for patch in details.patched:
65-
print(f"* {patch.family} - {patch.function_to_patch}")
65+
print(f"* {patch.family} - {getattr(patch.function_to_patch, '__name__', patch.function_to_patch)}")
6666
print()
6767
print()
6868
for patch in details.patched:

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
ignore:
2-
- onnx_diagnostic/big_models/*
3-
- onnx_diagnostic/ci_models/export*
2+
- "onnx_diagnostic/big_models/*"
3+
- "onnx_diagnostic/ci_models/export*"

onnx_diagnostic/export/api.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
23
import torch
34
from .onnx_plug import EagerDirectReplacementWithOnnx
@@ -138,7 +139,7 @@ def to_onnx(
138139
else None
139140
)
140141

141-
return _to_onnx(
142+
proto, opt_stats = _to_onnx(
142143
mod,
143144
args=args,
144145
kwargs=kwargs,
@@ -155,11 +156,47 @@ def to_onnx(
155156
inline=inline,
156157
dispatcher=main_dispatcher,
157158
optimize=optimize,
159+
return_optimize_report=True,
158160
**(exporter_kwargs or {}),
159161
)
162+
if opt_stats and filename and os.path.exists(filename):
163+
import pandas
164+
165+
stat_filename = f"{os.path.splitext(filename)[0]}.opt.xlsx"
166+
pattern_stats = []
167+
for k, v in opt_stats.items():
168+
if "time" in k:
169+
pattern_stats.append(dict(level="main", pattern=k, time_in=v))
170+
pattern_stats.extend(
171+
[{**obs, "level": "detailed"} for obs in opt_stats["optimization"]]
172+
)
173+
df = pandas.DataFrame(pattern_stats)
174+
df.to_excel(stat_filename, index=False)
175+
cols = [
176+
c
177+
for c in [
178+
"level",
179+
"pattern",
180+
"time_in",
181+
"iteration",
182+
"inlined",
183+
"removed",
184+
"added",
185+
"instances",
186+
"changed",
187+
"scale",
188+
]
189+
if c in df.columns
190+
]
191+
agg = {k: "sum" for k in cols if k not in ("level", "pattern")}
192+
agg.update(dict(iteration="max", instances="mean"))
193+
agg = {k: v for k, v in agg.items() if k in df.columns}
194+
stat_filename = f"{os.path.splitext(filename)[0]}.opt.agg.xlsx"
195+
df[cols].groupby(["level", "pattern"]).agg(agg).to_excel(stat_filename)
196+
197+
return proto
160198

161199
if exporter in ("dynamo", "onnx-dynamo"):
162-
import os
163200
from ..helpers import flatten_object
164201
import onnxscript.rewriter.ort_fusions as ort_fusions
165202

@@ -226,7 +263,6 @@ def to_onnx(
226263
return epo
227264

228265
if exporter == "modelbuilder":
229-
import os
230266
from ..helpers import flatten_object, string_type
231267
from ..helpers.model_builder_helper import create_model_builder, save_model_builder
232268

onnx_diagnostic/torch_models/validate.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,41 @@ def call_torch_export_custom(
24492449
)
24502450
),
24512451
)
2452+
if "optimization" in opt_stats and dump_folder:
2453+
import pandas
2454+
2455+
pattern_stats = []
2456+
for k, v in opt_stats.items():
2457+
if "time" in k:
2458+
pattern_stats.append(dict(level="main", pattern=k, time_in=v))
2459+
pattern_stats.extend(
2460+
[{**obs, "level": "detailed"} for obs in opt_stats["optimization"]]
2461+
)
2462+
stat_filename = os.path.join(dump_folder, "optimization_stats.xlsx")
2463+
df = pandas.DataFrame(pattern_stats)
2464+
df.to_excel(stat_filename, index=False)
2465+
cols = [
2466+
c
2467+
for c in [
2468+
"level",
2469+
"pattern",
2470+
"time_in",
2471+
"iteration",
2472+
"inlined",
2473+
"removed",
2474+
"added",
2475+
"instances",
2476+
"changed",
2477+
"scale",
2478+
]
2479+
if c in df.columns
2480+
]
2481+
agg = {k: "sum" for k in cols if k not in ("level", "pattern")}
2482+
agg.update(dict(iteration="max", instances="mean"))
2483+
agg = {k: v for k, v in agg.items() if k in df.columns}
2484+
stat_filename = os.path.join(dump_folder, "optimization_stats.agg.xlsx")
2485+
df[cols].groupby(["level", "pattern"]).agg(agg).to_excel(stat_filename)
2486+
24522487
if "ERR_export_onnx_c" in summary:
24532488
return summary, data
24542489

0 commit comments

Comments
 (0)