yobx.xshape._builder_runtime#

class yobx.xshape._builder_runtime._BuilderRuntime[source]#

Computes the output of a couple of nodes knowing their inputs. It supports numpy and torch tensors. Most of the function are used while exporting a model, by _InferenceRuntime.compute_constant.

_apply_expand_to_shape(input_shape: Tuple[int | torch.SymInt | torch.SymFloat | TracingInt | float | str, ...], new_shape: Tuple[int, ...]) Tuple[int | torch.SymInt | torch.SymFloat | TracingInt | float | str, ...][source]#

Returns the shape of the output of a node Reshape.

_apply_reshape_to_shape(input_shape: Tuple[int | torch.SymInt | torch.SymFloat | TracingInt | float | str, ...], new_shape: Tuple[int, ...]) Tuple[int | torch.SymInt | torch.SymFloat | TracingInt | float | str, ...][source]#

Returns the shape of the output of a node Reshape.

make_torch_tensor_from_np_array(arr: ndarray) torch.Tensor[source]#

Converts a numpy array to a torch tensor.

onnx_dtype_to_np_dtype(itype: int) dtype[source]#

See yobx.helpers.onnx_helper.tensor_dtype_to_np_dtype().

onnx_dtype_to_torch_dtype(itype: int) torch.dtype[source]#

See yobx.torch.torch_helper.onnx_dtype_to_torch_dtype().

class yobx.xshape._builder_runtime._ExtraPackages[source]#

Lazy availability checks for optional heavy dependencies (torch, tensorflow).

Calling self._has_torch or self._has_tensorflow performs a one-time import attempt for the respective package and caches the result so that subsequent calls are cheap. If the environment variable NOTORCH=1 (or NOTF=1 for TensorFlow) is set the import is skipped unconditionally and the property returns False, which is useful in test environments that must not load those frameworks.

Once a package is confirmed available the corresponding module object is cached in self._torch / self._tensorflow and exposed through the torch / tensorflow properties. For torch, torch._subclasses is also cached and _maybe_disable_fake_tensor_mode() is installed as self.maybe_disable_fake_tensor_mode.

property _has_tensorflow: bool#

Return True if tensorflow is importable.

On the first call the property tries to import tensorflow and caches the outcome in self._has_tensorflow_. All subsequent calls return the cached value without touching the import system. Setting the environment variable NOTF=1 before instantiation forces the property to return False without attempting any import.

property _has_torch: bool#

Return True if torch is importable.

On the first call the property tries to import torch and caches the outcome in self._has_torch_. All subsequent calls return the cached value without touching the import system. Setting the environment variable NOTORCH=1 before instantiation forces the property to return False without attempting any import.