yet-another-onnx-builder documentation#
yet-another-onnx-builder on GitHub
yet-another-onnx-builder (yobx) proposes a unique API and a unique function
yobx.to_onnx() to convert machine learning models
to ONNX format and manipulating ONNX graphs programmatically.
It can export from many libraries. Each converters relies on a common GraphBuilder API
(GraphBuilderExtendedProtocol)
to build the final ONNX model. One default implementation is provided but
it can also be replaced by any implementation of your own.
Any user can implement its own. You can see
OnnxScriptGraphBuilder
or SpoxGraphBuilder for a reference.
These API are close to onnx API, using NodeProto for nodes
and strings for names. This is on purpose: what this API produces is
what you see in the final ONNX model. You can add your own metadata,
choose your own names.
yobx.to_onnx() is the single entry point for all supported frameworks.
It inspects the type of model at runtime and automatically delegates to
the appropriate backend-specific converter:
a
torch.nn.Moduleortorch.fx.GraphModule→yobx.torch.to_onnx()a
tf.Module(including Keras models) →yobx.tensorflow.to_onnx()raw
.tflitebytes or a path ending in".tflite"→yobx.litert.to_onnx()a SQL string, a Python callable, or a
polars.LazyFrame→yobx.sql.to_onnx()
All extra keyword arguments are forwarded verbatim to the selected converter,
so the backend-specific parameters (export_options, function_options,
extra_converters, …) remain fully accessible through the top-level function.
standard machine learning
data manipulations
This is work in progress.
Many packages produce SQL queries. It starts by converting a SQL
query into ONNX. A lightweight DataFrame function tracer
(dataframe_to_onnx()) records pandas-inspired
operations on a DataFrame and compiles them to ONNX directly.
sql |
||
|
||
deep learning
The package is built upon a single graph builder API for constructing and optimizing ONNX graphs with built-in shape inference with can also linked to spox or onnxscript/ir-py. Its unique API:
# the model is called
expected = model(*args, **kwargs)
onnx_model = to_onnx(model, args, kwargs, dynamic_shapes, **options)
This package was initially started using vibe coding. AI is able to translate an existing code into another one such as ONNX but it tends sometime to favor ugly functions definition not friendly to the users.