modeci_mdf.interfaces.pytorch.importer

Functions for converting from PyTorch TorchScript to MDF models.

This code was originally inspired by the following blog post:

Mike He, “From Models to Computation Graphs (Part I)”, https://ad1024.space/articles/22

Functions

convert_to_serializable(value)

Helper function that converts some common unserializable types to JSON seriralizable types

get_graph_constants(graph)

Find all constant nodes in the graph and extract their values as a proper JSON serializable value.

make_func_id(node)

Helper function to get a unique name (used in MDF as id) for a TorchScript node's op/function.

make_model_graph_name(model)

Helper function that generates a clean graph and model name from a TorchScript model

make_node_id(node)

Helper function to get a unique name (used in MDF as id) from a TorchScript Node object

process_onnx_schema(node, consts, port_mapper)

Retrieve the argument names and attributes (parameters in MDF) for this Operation.

process_torch_schema(node, consts, port_mapper)

Parse a TorchScript node schema into argument names and constant attributes (parameters in MDF)

pytorch_to_mdf(model[, args, trace, ...])

Convert a PyTorch model to an MDF model.

torchnode_to_mdfnode(node, graph, consts, ...)

Convert a TorchScript node to an MDF node.

translate_graph(graph, mdf_graph, consts, ...)

Go through a Graph or Block and translate the nodes and edges to MDF nodes and edges.

Classes

PortMapper(graph, args)

A simple class that handles mapping TorchScript inputouput ids to MDF InputPortOutputPort ids.