onnx_chainer.replace_func.fake_as_funcnode(alt_func, name, rename_attributes=None, experimental_warning=True)

The target function fakes FunctionNode

The target function is replaced to the alternative function to connect variable node by acting function node. alt_func must satisfy the following restrictions.

  1. Inputs includes one or more chainer.Variable to trace variables.

  2. Output consists nothing but ndarray or chainer.Variable

Even if alt_func returns ndarray, the value forced to be converted to chainer.Variable. A caller of the target function have to care both cases, returning ndarray and chainer.Variable.

When alt_func returns list of variable, the wrapped function will also returns multiple variables as tuple. However dict cannot be return, the wrapped function breaks down the returned values as tuple of values, keys will be ignored.

Arguments of alt_func except for chainer.Variable are set as function attributes. Attribute names are set argN (N is index number) or keyword on default.


>>> def func(x, a, b, c=1, d=2): pass
>>> # x is variable
>>> func = onnx_chainer.replace_func.fake_as_funcnode(
...     func, 'CustomNode',
...     rename_attributes=[(1, 'value'), ('c', 'y')])

Then func will be operated as a function node named “CustomNode”, and 'value', 'b', 'y', 'd' are set as function’s attributes. See tests/test_replace_func.py more details.

  • alt_func (func) – actual called function. There are some constrains, see the above documentation.

  • name (str) – function name. This name is used for what ONNX operator to be assigned.

  • rename_attributes (list or tuple) – rename attribute name, set list of tuple(index_of_args, new_name) or tuple(kwargs_name, new_name)

  • experimental_warning – this function is experimental utility, if set False, run without experimental warning.


wrapped function, called on exporting.

Return type