pytorch_pfn_extras.onnx.pfto_exporter.export.GraphContext#

class pytorch_pfn_extras.onnx.pfto_exporter.export.GraphContext(graph, block, opset, original_node, params_dict, env)#

Bases: object

Extra context for symbolic functions with all methods from torch.Graph.

NOTE: This class is not meant for external consumption. Please do not depend on it outside of torch.onnx as the interface may evolve.

Parameters:
  • graph (Graph) –

  • block (Block) –

  • opset (int) –

  • original_node (Node) –

  • params_dict (Dict[str, _C.IValue]) –

  • env (Dict[Value, Value]) –

graph#

The _C.Graph being constructed.

Type:

torch.Graph

block#

The current _C.Block being constructed.

Type:

torch.Block

opset#

The opset version.

Type:

int

original_node#

Current node that is being converted from.

Type:

torch.Node

params_dict#

Mapping from graph initializer name to IValue.

Type:

Dict[str, _C.IValue]

env#

Mapping from Torch domain graph Value to ONNX domain graph Value.

Type:

Dict[torch.Value, torch.Value]

Methods

__init__(graph, block, opset, original_node, ...)

at(operator, *args[, overload_name])

Generates an ONNX ATen op node.

aten_op(operator, *args[, overload_name])

Generates an ONNX ATen op node.

onnxscript_op(onnx_fn, *raw_args[, outputs])

Creates an ONNX operator from onnx-script function, taking "raw_args" as inputs and "kwargs" as attributes.

op(opname, *raw_args[, outputs])

Creates an ONNX operator "opname", taking "raw_args" as inputs and "kwargs" as attributes.

Attributes

graph

block

opset

original_node

params_dict

env

__init__(graph, block, opset, original_node, params_dict, env)#
Parameters:
  • graph (Graph) –

  • block (Block) –

  • opset (int) –

  • original_node (Node) –

  • params_dict (Dict[str, _C.IValue]) –

  • env (Dict[Value, Value]) –

Return type:

None

at(operator, *args, overload_name='', **kwargs)#

Generates an ONNX ATen op node.

This function is for backward compatibility with the old symbolic functions.

Parameters:
  • operator (str) –

  • overload_name (str) –

aten_op(operator, *args, overload_name='', **kwargs)#

Generates an ONNX ATen op node.

This function is for backward compatibility with the old symbolic functions.

Parameters:
  • operator (str) –

  • overload_name (str) –

block: Block#
env: Dict[Value, Value]#
graph: Graph#
onnxscript_op(onnx_fn, *raw_args, outputs=1, **kwargs)#

Creates an ONNX operator from onnx-script function, taking “raw_args” as inputs and “kwargs” as attributes.

onnx-script repository: microsoft/onnx-script

Parameters:
  • onnx_fn – ONNXFunction from onnx-script; An example can be found at microsoft/onnx-script

  • raw_args (Union[Tensor, Value]) – The inputs to the operator; usually provided as arguments to the symbolic definition.

  • outputs (int) – The number of outputs this operator returns. By default an operator is assumed to return a single output. If outputs is greater than one, this functions returns a tuple of output Value, representing each output of the ONNX operator in order.

  • kwargs – The attributes of the ONNX operator, whose keys are named according to the following convention: alpha_f indicates the alpha attribute with type f. The valid type specifiers are f (float), i (int), s (string) or t (Tensor). An attribute specified with type float accepts either a single float, or a list of floats (e.g., you would say dims_i for a dims attribute that takes a list of integers).

Returns:

The value representing the single output of this operator (see the outputs keyword argument for multi-return nodes).

op(opname, *raw_args, outputs=1, **kwargs)#

Creates an ONNX operator “opname”, taking “raw_args” as inputs and “kwargs” as attributes.

The set of operators and the inputs/attributes they take is documented at onnx/onnx

Parameters:
  • opname (str) – The ONNX operator name, e.g., Abs or Add, or an operator qualified with a namespace, e.g., aten::add.

  • raw_args (Union[Tensor, Value]) – The inputs to the operator; usually provided as arguments to the symbolic definition.

  • outputs (int) – The number of outputs this operator returns. By default an operator is assumed to return a single output. If outputs is greater than one, this functions returns a tuple of output Value, representing each output of the ONNX operator in order.

  • kwargs – The attributes of the ONNX operator, whose keys are named according to the following convention: alpha_f indicates the alpha attribute with type f. The valid type specifiers are f (float), i (int), s (string) or t (Tensor). An attribute specified with type float accepts either a single float, or a list of floats (e.g., you would say dims_i for a dims attribute that takes a list of integers).

Returns:

The value representing the single output of this operator (see the outputs keyword argument for multi-return nodes).

opset: int#
original_node: Node#
params_dict: Dict[str, _C.IValue]#