onnx_diagnostic.helpers¶
submodules
- onnx_diagnostic.helpers.args_helper
- onnx_diagnostic.helpers.bench_run
- onnx_diagnostic.helpers.cache_helper
- onnx_diagnostic.helpers.config_helper
- onnx_diagnostic.helpers.helper
- onnx_diagnostic.helpers.memory_peak
- onnx_diagnostic.helpers.mini_onnx_builder
- onnx_diagnostic.helpers.onnx_helper
- onnx_diagnostic.helpers.ort_session
- onnx_diagnostic.helpers.rt_helper
- onnx_diagnostic.helpers.torch_helper
- onnx_diagnostic.helpers.flatten_object(x: Any, drop_keys: bool = False) Any [source][source]¶
Flattens the object. It accepts some common classes used in deep learning.
- Parameters:
x – any object
drop_keys – drop the keys if a dictionary is flattened. Keeps the order defined by the dictionary if False, sort them if True.
- Returns:
flattened object
- onnx_diagnostic.helpers.max_diff(expected: Any, got: Any, verbose: int = 0, level: int = 0, flatten: bool = False, debug_info: List[str] | None = None, begin: int = 0, end: int = -1, _index: int = 0, allow_unique_tensor_with_list_of_one_element: bool = True, hist: bool | List[float] | None = None) Dict[str, float | int | Tuple[int, ...]] [source][source]¶
Returns the maximum discrepancy.
- Parameters:
expected – expected values
got – values
verbose – verbosity level
level – for embedded outputs, used for debug purpposes
flatten – flatten outputs
debug_info – debug information
begin – first output to considered
end – last output to considered (-1 for the last one)
_index – used with begin and end
allow_unique_tensor_with_list_of_one_element – allow a comparison between a single tensor and a list of one tensor
hist – compute an histogram of the discrepancies
- Returns:
dictionary with many values
abs: max absolute error
rel: max relative error
sum: sum of the errors
- n: number of outputs values, if there is one
output, this number will be the number of elements of this output
dnan: difference in the number of nan
You may use
string_diff()
to display the discrepancies in one string.
- onnx_diagnostic.helpers.string_diff(diff: Dict[str, Any]) str [source][source]¶
Renders discrepancies return by
max_diff()
into one string.
- onnx_diagnostic.helpers.string_sig(f: Callable, kwargs: Dict[str, Any] | None = None) str [source][source]¶
Displays the signature of a function if the default if the given value is different from
- onnx_diagnostic.helpers.string_type(obj: Any, with_shape: bool = False, with_min_max: bool = False, with_device: bool = False, ignore: bool = False, limit: int = 20, verbose: int = 0) str [source][source]¶
Displays the types of an object as a string.
- Parameters:
obj – any
with_shape – displays shapes as well
with_min_max – displays information about the values
with_device – display the device
ignore – if True, just prints the type for unknown types
verbose – verbosity (to show the path it followed to get that print)
- Returns:
str
<<<
from onnx_diagnostic.helpers import string_type print(string_type((1, ["r", 6.6])))
>>>
(int,#2[str,float])
With pytorch:
<<<
import torch from onnx_diagnostic.helpers import string_type inputs = ( torch.rand((3, 4), dtype=torch.float16), [ torch.rand((5, 6), dtype=torch.float16), torch.rand((5, 6, 7), dtype=torch.float16), ], ) # with shapes print(string_type(inputs, with_shape=True)) # with min max print(string_type(inputs, with_shape=True, with_min_max=True))
>>>
(T10s3x4,#2[T10s5x6,T10s5x6x7]) (T10s3x4[0.10107421875,0.78662109375:A0.5012613932291666],#2[T10s5x6[0.1494140625,0.95947265625:A0.5461263020833333],T10s5x6x7[0.00146484375,0.99853515625:A0.48550269717261907]])