onnx_light.tools.schema_comparison#
Comparison of ONNX OpSchema and onnx_light LightOpSchema.
This module produces a structured comparison between the operator schemas
exposed by the reference onnx package (onnx.defs.OpSchema) and the
lightweight schemas exposed by onnx_light (LightOpSchema from the C++
onnx_op extension).
For every operator known to either side it reports:
whether the operator is described by an
OpSchema(onnx);whether the operator is described by a
LightOpSchema(onnx_light);whether a shape-inference function is registered on the
onnxside (OpSchema.has_type_and_shape_inference_function);whether a shape-inference function is registered on the
onnx_lightside (in theonnx_optimC++ library, seeComputeShapeNode());how many backend test cases exercise the operator in each package (a test case is attributed to the operator whose lowercased or
snake_casename matches itstest_<op>(_<variant>)*data-folder name — the convention used byonnx/backend/test/data/nodeand mirrored byonnx_light’stest_cc_<op>registry).
The compute_schema_comparison() function returns a
SchemaComparison describing the rows. The render_rst_table()
helper turns the comparison into a Sphinx list-table ready to be embedded
in a documentation page (see docs/api/python/tools/schema_comparison.rst).
- class onnx_light.tools.schema_comparison.SchemaComparison(rows: list[SchemaComparisonRow] = <factory>, onnx_available: bool = True)#
Aggregated comparison between
onnxandonnx_lightoperators.- Parameters:
rows – One
SchemaComparisonRowper(domain, op_name)known to either side, sorted by(domain, name).onnx_available –
Truewhen the referenceonnxpackage is importable and was used to populate theonnx-side columns.
- property total_onnx_light_backend_tests: int#
Total number of
onnx_lightnode backend tests counted.
- class onnx_light.tools.schema_comparison.SchemaComparisonRow(domain: str, name: str, in_onnx: bool = False, in_onnx_light: bool = False, onnx_shape_inference: bool = False, onnx_light_shape_inference: bool = False, onnx_backend_tests: int = 0, onnx_light_backend_tests: int = 0)#
One row of
SchemaComparison, describing a single operator.- Parameters:
domain – Operator domain (
ai.onnxfor the default ONNX domain).name – Operator name.
in_onnx –
Truewhen the operator has anOpSchemainonnx.defs.in_onnx_light –
Truewhen the operator has aLightOpSchemain theonnx_opC++ extension.onnx_shape_inference –
Truewhenonnxregisters a type and shape inference function for the operator.onnx_light_shape_inference –
Truewhenonnx_optimregisters a shape-inference dispatch entry for the operator.onnx_backend_tests – Number of node backend tests in
onnxattributed to the operator (one count peronnx/backend/test/data/node/test_<op>(_<variant>)*subfolder whose name starts with the operator’s lowercased orsnake_caseform).onnx_light_backend_tests – Number of node backend tests collected by
onnx_light.backend.test.case.base.collect_test_case()attributed to the operator by the same name-prefix convention (withtest_cc_also stripped for cases registered bylib_onnx_backend_test).
- onnx_light.tools.schema_comparison.compute_schema_comparison() SchemaComparison#
Computes the full
SchemaComparison.The function silently degrades when the upstream
onnxpackage is not importable: theonnx-side columns are then left empty andSchemaComparison.onnx_availableis set toFalse.
- onnx_light.tools.schema_comparison.iter_rows(comparison: SchemaComparison) Iterable[SchemaComparisonRow]#
Iterates over
comparison.rows(convenience helper).
- onnx_light.tools.schema_comparison.render_rst_summary(comparison: SchemaComparison) str#
Renders a short reST summary (totals) for comparison.
- onnx_light.tools.schema_comparison.render_rst_table(comparison: SchemaComparison, only_in_either: bool = True, css_class: str | None = None) str#
Renders comparison as one reST
list-tabledirective per domain.- Parameters:
comparison – The comparison to render.
only_in_either – When
True(the default), operators that are absent from bothonnxandonnx_light(this can happen for custom-domain test fixtures) are filtered out.css_class – When provided, a
:class:option is emitted on thelist-tabledirective. This is used by the documentation to opt the rendered<table>element into thesphinx-datatablesextension (css_class="sphinx-datatable"), which turns the table into an interactive DataTables widget (search box, column sorting, pagination).
- Returns:
A multi-line string containing domain rubrics and table directives, ready to be emitted in a
runpythonblock.