module onnx_grammar.onnx_translator

Inheritance diagram of mlprodict.onnx_grammar.onnx_translator

Short summary

module mlprodict.onnx_grammar.onnx_translator

One class which visits a syntax tree.

source on GitHub

Classes

class

truncated documentation

CodeTranslator

Class which converts a Python function into something else. It must implements methods visit and depart.

OnnxTranslator

Class which converts a Python function into an ONNX function. It must implements methods visit and depart. …

Methods

method

truncated documentation

__init__

__init__

_fix_default_values

Maps default values with parameter names.

_get_last

_is_stacked

_post_process

Simplifies some operator such as OnnxNeg(2).

depart

Leaves a node.

depart

Visits a node.

export

Exports the parsed python code into something.

export

Returns an ONNX graph or a piece of code which could generate the graph.

make_msg

Make a message with line and column information.

visit

Visits a node.

visit

Visits a node.

Documentation

One class which visits a syntax tree.

source on GitHub

class mlprodict.onnx_grammar.onnx_translator.CodeTranslator(visitor)

Bases: object

Class which converts a Python function into something else. It must implements methods visit and depart.

source on GitHub

Parameters

visitorCodeNodeVisitor

source on GitHub

__init__(visitor)
Parameters

visitorCodeNodeVisitor

source on GitHub

depart(node, info)

Leaves a node.

Parameters
  • node – visited node

  • info – info extracted by the visitor

source on GitHub

export(context=None, **kwargs)

Exports the parsed python code into something.

source on GitHub

visit(node, info)

Visits a node.

Parameters
  • node – visited node

  • info – info extracted by the visitor

source on GitHub

class mlprodict.onnx_grammar.onnx_translator.OnnxTranslator(visitor)

Bases: mlprodict.onnx_grammar.onnx_translator.CodeTranslator

Class which converts a Python function into an ONNX function. It must implements methods visit and depart.

source on GitHub

Parameters

visitorCodeNodeVisitor

source on GitHub

class Parameter(name, value=('#NODEFAULT#'), annotation=None)

Bases: object

Holds parameter information.

source on GitHub

Parameters
  • name – parameter name

  • value – parameter value

source on GitHub

__init__(name, value=('#NODEFAULT#'), annotation=None)
Parameters
  • name – parameter name

  • value – parameter value

source on GitHub

__str__()

Into python syntax.

source on GitHub

static format_value(value)

Returns a formatted value in python code.

source on GitHub

property formatted_value

Returns a formatted value in python code.

source on GitHub

__init__(visitor)
Parameters

visitorCodeNodeVisitor

source on GitHub

_binary_operators = {'Add': 'Add', 'Div': 'Div', 'MatMult': 'MatMul', 'Mult': 'Mul', 'Pow': 'Pow', 'Sub': 'Sub'}
_fix_default_values(code_fct)

Maps default values with parameter names.

source on GitHub

_get_last(name, info=None)
_is_stacked(name)
_numpy2onnx_op = {'absolute': 'Abs', 'cos': 'Cos', 'exp': 'Exp', 'inner': 'inner', 'power': 'Pow', 'sin': 'Sin', 'transpose': 'Transpose'}
_parameter_mapping = {'Transpose': {'axes': 'perm'}}
_post_process(op, node)

Simplifies some operator such as OnnxNeg(2).

source on GitHub

_unary_operators = {'Sub': 'Neg'}
depart(node, info)

Visits a node.

Parameters
  • node – visited node

  • info – info extracted by the visitor

source on GitHub

export(context=None, format='code', output_names=None)

Returns an ONNX graph or a piece of code which could generate the graph.

Parameters
  • context – function used in the function code

  • format'code'

  • output_names – add code in the final function to overwrite the names of the outputs in the ONNX graph

Returns

string or onnx graph

This method is used in function translate_fct2onnx. An example of code can be found there.

source on GitHub

make_msg(info)

Make a message with line and column information.

source on GitHub

visit(node, info)

Visits a node.

Parameters
  • node – visited node

  • info – info extracted by the visitor

source on GitHub