onnx-diagnostic 0.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- onnx_diagnostic/__init__.py +7 -0
- onnx_diagnostic/__main__.py +4 -0
- onnx_diagnostic/_command_lines_parser.py +1141 -0
- onnx_diagnostic/api.py +15 -0
- onnx_diagnostic/doc.py +100 -0
- onnx_diagnostic/export/__init__.py +2 -0
- onnx_diagnostic/export/api.py +124 -0
- onnx_diagnostic/export/dynamic_shapes.py +1083 -0
- onnx_diagnostic/export/shape_helper.py +296 -0
- onnx_diagnostic/export/validate.py +173 -0
- onnx_diagnostic/ext_test_case.py +1290 -0
- onnx_diagnostic/helpers/__init__.py +1 -0
- onnx_diagnostic/helpers/_log_helper.py +463 -0
- onnx_diagnostic/helpers/args_helper.py +132 -0
- onnx_diagnostic/helpers/bench_run.py +450 -0
- onnx_diagnostic/helpers/cache_helper.py +687 -0
- onnx_diagnostic/helpers/config_helper.py +170 -0
- onnx_diagnostic/helpers/doc_helper.py +163 -0
- onnx_diagnostic/helpers/fake_tensor_helper.py +273 -0
- onnx_diagnostic/helpers/graph_helper.py +386 -0
- onnx_diagnostic/helpers/helper.py +1707 -0
- onnx_diagnostic/helpers/log_helper.py +2245 -0
- onnx_diagnostic/helpers/memory_peak.py +249 -0
- onnx_diagnostic/helpers/mini_onnx_builder.py +600 -0
- onnx_diagnostic/helpers/model_builder_helper.py +469 -0
- onnx_diagnostic/helpers/onnx_helper.py +1200 -0
- onnx_diagnostic/helpers/ort_session.py +736 -0
- onnx_diagnostic/helpers/rt_helper.py +476 -0
- onnx_diagnostic/helpers/torch_helper.py +987 -0
- onnx_diagnostic/reference/__init__.py +4 -0
- onnx_diagnostic/reference/evaluator.py +254 -0
- onnx_diagnostic/reference/ops/__init__.py +1 -0
- onnx_diagnostic/reference/ops/op_add_add_mul_mul.py +68 -0
- onnx_diagnostic/reference/ops/op_attention.py +60 -0
- onnx_diagnostic/reference/ops/op_average_pool_grad.py +63 -0
- onnx_diagnostic/reference/ops/op_bias_softmax.py +16 -0
- onnx_diagnostic/reference/ops/op_cast_like.py +46 -0
- onnx_diagnostic/reference/ops/op_complex.py +26 -0
- onnx_diagnostic/reference/ops/op_concat.py +15 -0
- onnx_diagnostic/reference/ops/op_constant_of_shape.py +67 -0
- onnx_diagnostic/reference/ops/op_fused_matmul.py +31 -0
- onnx_diagnostic/reference/ops/op_gather.py +29 -0
- onnx_diagnostic/reference/ops/op_gather_elements.py +45 -0
- onnx_diagnostic/reference/ops/op_gather_grad.py +12 -0
- onnx_diagnostic/reference/ops/op_memcpy_host.py +11 -0
- onnx_diagnostic/reference/ops/op_mul_sigmoid.py +23 -0
- onnx_diagnostic/reference/ops/op_negxplus1.py +8 -0
- onnx_diagnostic/reference/ops/op_qlinear_average_pool.py +40 -0
- onnx_diagnostic/reference/ops/op_qlinear_conv.py +102 -0
- onnx_diagnostic/reference/ops/op_quick_gelu.py +23 -0
- onnx_diagnostic/reference/ops/op_replace_zero.py +13 -0
- onnx_diagnostic/reference/ops/op_rotary.py +19 -0
- onnx_diagnostic/reference/ops/op_scan.py +65 -0
- onnx_diagnostic/reference/ops/op_scatter_elements.py +107 -0
- onnx_diagnostic/reference/ops/op_scatternd_of_shape.py +22 -0
- onnx_diagnostic/reference/ops/op_simplified_layer_normalization.py +8 -0
- onnx_diagnostic/reference/ops/op_skip_layer_normalization.py +13 -0
- onnx_diagnostic/reference/ops/op_slice.py +20 -0
- onnx_diagnostic/reference/ops/op_transpose_cast.py +16 -0
- onnx_diagnostic/reference/ops/op_tri_matrix.py +17 -0
- onnx_diagnostic/reference/ort_evaluator.py +652 -0
- onnx_diagnostic/reference/quantized_tensor.py +46 -0
- onnx_diagnostic/reference/report_results_comparison.py +95 -0
- onnx_diagnostic/reference/torch_evaluator.py +669 -0
- onnx_diagnostic/reference/torch_ops/__init__.py +56 -0
- onnx_diagnostic/reference/torch_ops/_op_run.py +335 -0
- onnx_diagnostic/reference/torch_ops/access_ops.py +94 -0
- onnx_diagnostic/reference/torch_ops/binary_ops.py +108 -0
- onnx_diagnostic/reference/torch_ops/controlflow_ops.py +121 -0
- onnx_diagnostic/reference/torch_ops/generator_ops.py +36 -0
- onnx_diagnostic/reference/torch_ops/nn_ops.py +196 -0
- onnx_diagnostic/reference/torch_ops/other_ops.py +106 -0
- onnx_diagnostic/reference/torch_ops/reduce_ops.py +130 -0
- onnx_diagnostic/reference/torch_ops/sequence_ops.py +65 -0
- onnx_diagnostic/reference/torch_ops/shape_ops.py +121 -0
- onnx_diagnostic/reference/torch_ops/unary_ops.py +93 -0
- onnx_diagnostic/tasks/__init__.py +90 -0
- onnx_diagnostic/tasks/automatic_speech_recognition.py +188 -0
- onnx_diagnostic/tasks/data/__init__.py +13 -0
- onnx_diagnostic/tasks/data/dummies_imagetext2text_generation_gemma3.onnx +0 -0
- onnx_diagnostic/tasks/feature_extraction.py +162 -0
- onnx_diagnostic/tasks/fill_mask.py +89 -0
- onnx_diagnostic/tasks/image_classification.py +144 -0
- onnx_diagnostic/tasks/image_text_to_text.py +581 -0
- onnx_diagnostic/tasks/image_to_video.py +127 -0
- onnx_diagnostic/tasks/mask_generation.py +143 -0
- onnx_diagnostic/tasks/mixture_of_expert.py +79 -0
- onnx_diagnostic/tasks/object_detection.py +134 -0
- onnx_diagnostic/tasks/sentence_similarity.py +89 -0
- onnx_diagnostic/tasks/summarization.py +227 -0
- onnx_diagnostic/tasks/text2text_generation.py +230 -0
- onnx_diagnostic/tasks/text_classification.py +89 -0
- onnx_diagnostic/tasks/text_generation.py +352 -0
- onnx_diagnostic/tasks/text_to_image.py +95 -0
- onnx_diagnostic/tasks/zero_shot_image_classification.py +128 -0
- onnx_diagnostic/torch_export_patches/__init__.py +21 -0
- onnx_diagnostic/torch_export_patches/eval/__init__.py +725 -0
- onnx_diagnostic/torch_export_patches/eval/model_cases.py +898 -0
- onnx_diagnostic/torch_export_patches/onnx_export_errors.py +1098 -0
- onnx_diagnostic/torch_export_patches/onnx_export_serialization.py +311 -0
- onnx_diagnostic/torch_export_patches/patch_details.py +340 -0
- onnx_diagnostic/torch_export_patches/patch_expressions.py +108 -0
- onnx_diagnostic/torch_export_patches/patch_inputs.py +211 -0
- onnx_diagnostic/torch_export_patches/patch_module.py +1047 -0
- onnx_diagnostic/torch_export_patches/patch_module_helper.py +184 -0
- onnx_diagnostic/torch_export_patches/patches/__init__.py +0 -0
- onnx_diagnostic/torch_export_patches/patches/patch_torch.py +1090 -0
- onnx_diagnostic/torch_export_patches/patches/patch_transformers.py +2139 -0
- onnx_diagnostic/torch_export_patches/serialization/__init__.py +46 -0
- onnx_diagnostic/torch_export_patches/serialization/diffusers_impl.py +34 -0
- onnx_diagnostic/torch_export_patches/serialization/transformers_impl.py +313 -0
- onnx_diagnostic/torch_models/__init__.py +0 -0
- onnx_diagnostic/torch_models/code_sample.py +343 -0
- onnx_diagnostic/torch_models/hghub/__init__.py +1 -0
- onnx_diagnostic/torch_models/hghub/hub_api.py +422 -0
- onnx_diagnostic/torch_models/hghub/hub_data.py +234 -0
- onnx_diagnostic/torch_models/hghub/hub_data_cached_configs.py +4905 -0
- onnx_diagnostic/torch_models/hghub/model_inputs.py +388 -0
- onnx_diagnostic/torch_models/hghub/model_specific.py +76 -0
- onnx_diagnostic/torch_models/llms.py +2 -0
- onnx_diagnostic/torch_models/untrained/__init__.py +0 -0
- onnx_diagnostic/torch_models/untrained/llm_phi2.py +113 -0
- onnx_diagnostic/torch_models/untrained/llm_tiny_llm.py +76 -0
- onnx_diagnostic/torch_models/validate.py +2124 -0
- onnx_diagnostic/torch_onnx/__init__.py +0 -0
- onnx_diagnostic/torch_onnx/runtime_info.py +289 -0
- onnx_diagnostic/torch_onnx/sbs.py +440 -0
- onnx_diagnostic-0.8.0.dist-info/METADATA +213 -0
- onnx_diagnostic-0.8.0.dist-info/RECORD +132 -0
- onnx_diagnostic-0.8.0.dist-info/WHEEL +5 -0
- onnx_diagnostic-0.8.0.dist-info/licenses/LICENSE.txt +19 -0
- onnx_diagnostic-0.8.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Tuple, Union
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
ReportKeyNameType = Union[str, Tuple[str, int, str]]
|
|
5
|
+
ReportKeyValueType = Tuple[int, Tuple[int, ...]]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ReportResultComparison:
|
|
9
|
+
"""
|
|
10
|
+
Holds tensors a runtime can use as a reference to compare
|
|
11
|
+
intermediate results.
|
|
12
|
+
See :meth:`onnx_diagnostic.reference.TorchOnnxEvaluator.run`.
|
|
13
|
+
|
|
14
|
+
:param tensors: tensor
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, tensors: Dict[ReportKeyNameType, "torch.Tensor"]): # noqa: F821
|
|
18
|
+
from ..helpers.onnx_helper import dtype_to_tensor_dtype
|
|
19
|
+
from ..helpers import max_diff, string_type
|
|
20
|
+
|
|
21
|
+
assert all(
|
|
22
|
+
hasattr(v, "shape") and hasattr(v, "dtype") for v in tensors.values()
|
|
23
|
+
), f"One of the tensors is not: {string_type(tensors, with_shape=True)}"
|
|
24
|
+
self.dtype_to_tensor_dtype = dtype_to_tensor_dtype
|
|
25
|
+
self.max_diff = max_diff
|
|
26
|
+
self.tensors = tensors
|
|
27
|
+
self._build_mapping()
|
|
28
|
+
|
|
29
|
+
def key(self, tensor: "torch.Tensor") -> ReportKeyValueType: # noqa: F821
|
|
30
|
+
"Returns a key for a tensor, (onnx dtype, shape)."
|
|
31
|
+
return self.dtype_to_tensor_dtype(tensor.dtype), tuple(map(int, tensor.shape))
|
|
32
|
+
|
|
33
|
+
def _build_mapping(self):
|
|
34
|
+
mapping = {}
|
|
35
|
+
for k, v in self.tensors.items():
|
|
36
|
+
key = self.key(v)
|
|
37
|
+
if key not in mapping:
|
|
38
|
+
mapping[key] = []
|
|
39
|
+
mapping[key].append(k)
|
|
40
|
+
self.mapping = mapping
|
|
41
|
+
self.clear()
|
|
42
|
+
|
|
43
|
+
def clear(self):
|
|
44
|
+
"""Clears the last report."""
|
|
45
|
+
self.report_cmp = {}
|
|
46
|
+
self.unique_run_names = set()
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def value(
|
|
50
|
+
self,
|
|
51
|
+
) -> Dict[Tuple[Tuple[int, str], ReportKeyNameType], Dict[str, Union[float, str]]]:
|
|
52
|
+
"Returns the report."
|
|
53
|
+
return self.report_cmp
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def data(self) -> List[Dict[str, Any]]:
|
|
57
|
+
"Returns data which can be consumed by a dataframe."
|
|
58
|
+
rows = []
|
|
59
|
+
for k, v in self.value.items():
|
|
60
|
+
(i_run, run_name), ref_name = k
|
|
61
|
+
d = dict(run_index=i_run, run_name=run_name, ref_name=ref_name)
|
|
62
|
+
d.update(v)
|
|
63
|
+
rows.append(d)
|
|
64
|
+
return rows
|
|
65
|
+
|
|
66
|
+
def report(
|
|
67
|
+
self, outputs: Dict[str, "torch.Tensor"] # noqa: F821
|
|
68
|
+
) -> List[Tuple[Tuple[int, str], ReportKeyNameType, Dict[str, Union[float, str]]]]:
|
|
69
|
+
"""
|
|
70
|
+
For every tensor in outputs, compares it to every tensor held by
|
|
71
|
+
this class if it shares the same type and shape. The function returns
|
|
72
|
+
the results of the comparison. The function also collects the results
|
|
73
|
+
into a dictionary the user can retrieve later.
|
|
74
|
+
"""
|
|
75
|
+
res: List[Tuple[Tuple[int, str], ReportKeyNameType, Dict[str, Union[float, str]]]] = []
|
|
76
|
+
for name, tensor in outputs.items():
|
|
77
|
+
i_run = len(self.unique_run_names)
|
|
78
|
+
self.unique_run_names.add(name)
|
|
79
|
+
key = self.key(tensor)
|
|
80
|
+
if key not in self.mapping:
|
|
81
|
+
continue
|
|
82
|
+
cache: Dict["torch.device", "torch.Tensor"] = {} # noqa: F821, UP037
|
|
83
|
+
for held_key in self.mapping[key]:
|
|
84
|
+
t2 = self.tensors[held_key]
|
|
85
|
+
if hasattr(t2, "device") and hasattr(tensor, "device"):
|
|
86
|
+
if t2.device in cache:
|
|
87
|
+
t = cache[t2.device]
|
|
88
|
+
else:
|
|
89
|
+
cache[t2.device] = t = tensor.to(t2.device)
|
|
90
|
+
diff = self.max_diff(t, t2)
|
|
91
|
+
else:
|
|
92
|
+
diff = self.max_diff(tensor, t2)
|
|
93
|
+
res.append((i_run, name, held_key, diff)) # type: ignore[arg-type]
|
|
94
|
+
self.report_cmp[(i_run, name), held_key] = diff
|
|
95
|
+
return res
|