boundlab.interp.Interpreter#
- class boundlab.interp.Interpreter[source]#
Bases:
Generic[E]Methods
Initialize an interpreter with a dispatcher.
Return a new interpreter that applies another function to the output of this one.
Return a new interpreter that produces tuples of results from this and other interpreters.
Register a handler for an operator.
- __init__(dispatcher)[source]#
Initialize an interpreter with a dispatcher.
The dispatcher maps ONNX operator names to handler functions.
Keys are the ONNX
op_typestrings (e.g."Gemm","Relu","Reshape"). Custom-domain ops (e.g."diff_pair"from theboundlabdomain) are also keyed by bareop_type.
- product(*other)[source]#
Return a new interpreter that produces tuples of results from this and other interpreters.
- and_then(other)[source]#
Return a new interpreter that applies another function to the output of this one.
- __call__(model)[source]#
Build an expression-level interpreter for an ONNX model.
- Parameters:
model (ir.Model | str | Path) –
An
onnx_ir.Modelor astr/pathlib.Pathpointing to an.onnxfile.The ONNX graph is walked in topological order (ONNX guarantees this). For each node:
Initializer inputs are wrapped as
Tensorand passed as positional arguments.Optional/missing inputs (empty-string name) are passed as
None.Node attributes are converted to Python scalars / lists and passed as keyword arguments.
The dispatcher is keyed on the bare
op_type(domain is ignored); e.g. a customboundlab::diff_pairnode is dispatched as"diff_pair".
- Returns:
A callable
interpret(*exprs)that maps inputExprobjects to output expression(s).
- Return type:
Callable[…, E]
Examples
>>> import torch, tempfile, os >>> from boundlab.interp import Interpreter, ONNX_BASE_INTERPRETER >>> from boundlab.zono import interpret >>> import boundlab.expr as expr