concrete.ml.torch.numpy_module.md

module concrete.ml.torch.numpy_module

A torch to numpy module.

Global Variables

  • OPSET_VERSION_FOR_ONNX_EXPORT


class NumpyModule

General interface to transform a torch.nn.Module to numpy module.

Args:

  • torch_model (Union[nn.Module, onnx.ModelProto]): A fully trained, torch model along with its parameters or the onnx graph of the model.

  • dummy_input (Union[torch.Tensor, Tuple[torch.Tensor, ...]]): Sample tensors for all the module inputs, used in the ONNX export to get a simple to manipulate nn representation.

  • debug_onnx_output_file_path: (Optional[Union[Path, str]], optional): An optional path to indicate where to save the ONNX file exported by torch for debug. Defaults to None.

method __init__

__init__(
    model: Union[Module, ModelProto],
    dummy_input: Optional[Tensor, Tuple[Tensor, ]] = None,
    debug_onnx_output_file_path: Optional[str, Path] = None
)

property onnx_model

Get the ONNX model.

.. # noqa: DAR201

Returns:

  • _onnx_model (onnx.ModelProto): the ONNX model


method forward

forward(*args: ndarray) → Union[ndarray, Tuple[ndarray, ]]

Apply a forward pass on args with the equivalent numpy function only.

Args:

  • *args: the inputs of the forward function

Returns:

  • Union[numpy.ndarray, Tuple[numpy.ndarray, ...]]: result of the forward on the given inputs

Last updated