ONNX¶
-
class
singa.sonnx.SingaFrontend¶ This class provides mthods to convert model from singa to onnx.
-
classmethod
handle_special_ops(op, X, W)¶ hanlde the special operators, because the inputs of batchnorm and reshape are differnet with onnx we need to add these inputs into onnx model mannully :param op: a given operator
- Parameters
X – onnx input list
X – onnx weight list
Returns: the onnx node
-
classmethod
singa_op_to_onnx_node(op, op_t)¶ get a onnx node from singa operator :param op: a given operator
- Parameters
op_t – the tensor of the operator
- Returns
the onnx node
-
classmethod
singa_to_onnx_graph(inputs, y, model_name='sonnx')¶ get onnx model from singa computational graph :param inputs: a list of input tensors (each is initialized with a name)
- Parameters
y – a list of tensors, usually the outputs of the graph
- Returns
the onnx model
-
classmethod
singa_to_onnx_model(inputs, y, model_name='sonnx')¶ get onnx model from singa computational graph :param inputs: a list of input tensors (each is initialized with a name)
- Parameters
y – a list of tensors, usually the outputs of the graph
- Returns
the onnx model
-
classmethod
-
class
singa.sonnx.OnnxNode(node)¶ Reimplementation of NodeProto from ONNX, but in a form more convenient to work with from Python.
-
getattr(key, default=None)¶
-
-
class
singa.sonnx.OnnxAttributes¶ This is a more convenient way to work with ONNX attributes that is not the protobuf representation.
-
static
from_onnx(args)¶
-
static
-
class
singa.sonnx.SingaBackend¶ -
classmethod
run_node(onnx_node, inputs, opset_version=11)¶ run a single singa operator from a onnx node :param onnx_node: a given onnx node
- Parameters
inputs – the input tensor
device – the used device
opset_version – the opset version
- Returns
list, the output of the
-
classmethod
prepare(model, device, **kwargs)¶ get the batch norm operator from onnx node :param model: a given onnx node
- Parameters
device – the used device
- Returns
a list of output values
-
classmethod
-
class
singa.sonnx.SingaRep(model, weights, singa_ops, keep_initializers_as_inputs=True)¶ -
run(inputs, **kwargs)¶ run the forward of singa model :param inputs: a given operator
- Returns
the onnx node
-
-
singa.sonnx.run_node(onnx_node, inputs, opset_version=11)¶ run a single singa operator from a onnx node :param onnx_node: a given onnx node
- Parameters
inputs – the input tensor
device – the used device
opset_version – the opset version
- Returns
list, the output of the
-
singa.sonnx.prepare(model, device, **kwargs)¶ get the batch norm operator from onnx node :param model: a given onnx node
- Parameters
device – the used device
- Returns
a list of output values
-
singa.sonnx.get_op(onnx_node, inputs, opset_version=11)¶ get a singa operator(handle and autograd) from a onnx node :param onnx_node: a given onnx node
- Parameters
inputs – the input list
opset_version – the opset version
- Returns
a dict of tensors
- Returns
a list of SingaOps(‘name’, ‘op’, ‘handle’, ‘forward’)
-
singa.sonnx.to_onnx(inputs, y, model_name='sonnx')¶ get onnx model from singa computational graph :param inputs: a list of input tensors (each is initialized with a name)
- Parameters
y – a list of tensors, usually the outputs of the graph
- Returns
the onnx model