yobx.helpers¶
modules
Other functions¶
- yobx.helpers.string_type(obj: Any, with_shape: bool = False, with_min_max: bool = False, with_device: bool = False, ignore: bool = False, limit: int = 20) 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
- Returns:
str
The function displays something like the following for a tensor.
T7s2x7[0.5:6:A3.56] ^^^+-^^----+------^ || | | || | +-- information about the content of a tensor or array || | [min,max:A<average>] || | || +-- a shape || |+-- integer following the code defined by onnx.TensorProto, | 7 is onnx.TensorProto.INT64 (see onnx_dtype_name) | +-- A,T,F A is an array from numpy T is a Tensor from pytorch F is a FakeTensor from pytorchThe element types for a tensor are displayed as integer to shorten the message. The semantic is defined by
onnx.TensorProtoand can be obtained byyobx.helpers.onnx_helper.onnx_dtype_name().<<<
from yobx.helpers import string_type print(string_type((1, ["r", 6.6])))
>>>
(int,#2[str,float])
With pytorch:
<<<
import torch from yobx.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.044921875,0.7685546875:A0.3328857421875],#2[T10s5x6[0.03564453125,0.99755859375:A0.4521484375],T10s5x6x7[0.0068359375,0.99462890625:A0.48237537202380953]])
- yobx.helpers.max_diff(expected: Any, got: Any, 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, skip_none: bool = False) Dict[str, float | int | Tuple[Any, ...]][source][source]¶
Returns the maximum discrepancy.
- Parameters:
expected – expected values
got – values
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
skip_none – skips none value
- 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
dev: tensor on the same device, if applicable
You may use
string_diff()to display the discrepancies in one string.