modeci_mdf.interfaces.pytorch.importer.pytorch_to_mdf

modeci_mdf.interfaces.pytorch.importer.pytorch_to_mdf(model: Union[Callable, Module, ScriptFunction, ScriptModule], args: Union[None, Tensor, Tuple[Tensor]] = None, trace: bool = False, use_onnx_ops: bool = True) Union[Model, Graph][source]

Convert a PyTorch model to an MDF model. By default, this function will invoke torch.jit.script on the model to compile it down to TorchScript IR and simplify the graph before exporting the MDF. The default is to use ONNX operations when possible and fallback to ATENTorch ops when ONNX support is not available (torch._C._onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK mode). To use allATENTorch ops, set use_onnx_ops to False.

Parameters:
  • model – The model to translate into MDF.

  • args – The input arguments for this model. If a nn.Module is passed then the model will be traced with these inputs. If a ScriptModule is passed, they are still needed to determine input shapes.

  • trace – Force the use of tracing to compile the model. The default is to use torch.jit.script

  • use_onnx_ops – Use ONNX ops when possible, fallback to ATEN ops when not available. Default is True. If False, use only ATEN ops.

Returns:

The translated MDF model