boundlab.interp.onnx_export#

boundlab.interp.onnx_export(f, args, kwargs={}, input_names=None, output_names=None, optimize=None)[source]#

Export a PyTorch function or module to an ONNX IR model.

Shape arguments are given as lists/tuples of ints — zero-value tensors are constructed internally and only used for tracing.

Parameters:
Returns:

An onnx_ir.Model ready for abstract interpretation.

Return type:

onnx_ir.Model

Examples

>>> import torch
>>> from boundlab.interp.onnx import onnx_export
>>> def f(x):
...     return x @ x.T
...
>>> model = onnx_export(f, ([3, 4],))
>>> list(model.graph)[0].op_type
'MatMul'