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_torch_dtype(itype: int) torch.dtype[source]#
- class yobx.xshape._builder_runtime._ExtraPackages[source]#
Lazy availability checks for optional heavy dependencies (torch, tensorflow).
Calling
self._has_torchorself._has_tensorflowperforms a one-time import attempt for the respective package and caches the result so that subsequent calls are cheap. If the environment variableNOTORCH=1(orNOTF=1for TensorFlow) is set the import is skipped unconditionally and the property returnsFalse, 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._tensorflowand exposed through thetorch/tensorflowproperties. For torch,torch._subclassesis also cached and_maybe_disable_fake_tensor_mode()is installed asself.maybe_disable_fake_tensor_mode.- property _has_tensorflow: bool#
Return
Trueif tensorflow is importable.On the first call the property tries to
import tensorflowand caches the outcome inself._has_tensorflow_. All subsequent calls return the cached value without touching the import system. Setting the environment variableNOTF=1before instantiation forces the property to returnFalsewithout attempting any import.
- property _has_torch: bool#
Return
Trueif torch is importable.On the first call the property tries to
import torchand caches the outcome inself._has_torch_. All subsequent calls return the cached value without touching the import system. Setting the environment variableNOTORCH=1before instantiation forces the property to returnFalsewithout attempting any import.