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 onnx side (OpSchema.has_type_and_shape_inference_function);

  • whether a shape-inference function is registered on the onnx_light side (in the onnx_optim C++ library, see ComputeShapeNode());

  • how many backend test cases exercise the operator in each package (a test case is attributed to the operator whose lowercased or snake_case name matches its test_<op>(_<variant>)* data-folder name — the convention used by onnx/backend/test/data/node and mirrored by onnx_light’s test_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 onnx and onnx_light operators.

Parameters:
  • rows – One SchemaComparisonRow per (domain, op_name) known to either side, sorted by (domain, name).

  • onnx_availableTrue when the reference onnx package is importable and was used to populate the onnx-side columns.

property total_onnx: int#

Number of operators with an OpSchema.

property total_onnx_backend_tests: int#

Total number of onnx node backend tests counted.

property total_onnx_light: int#

Number of operators with a LightOpSchema.

property total_onnx_light_backend_tests: int#

Total number of onnx_light node backend tests counted.

property total_onnx_light_shape_inference: int#

Operators with shape inference on the onnx_light (onnx_optim) side.

property total_onnx_shape_inference: int#

Operators with shape inference on the onnx side.

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.onnx for the default ONNX domain).

  • name – Operator name.

  • in_onnxTrue when the operator has an OpSchema in onnx.defs.

  • in_onnx_lightTrue when the operator has a LightOpSchema in the onnx_op C++ extension.

  • onnx_shape_inferenceTrue when onnx registers a type and shape inference function for the operator.

  • onnx_light_shape_inferenceTrue when onnx_optim registers a shape-inference dispatch entry for the operator.

  • onnx_backend_tests – Number of node backend tests in onnx attributed to the operator (one count per onnx/backend/test/data/node/test_<op>(_<variant>)* subfolder whose name starts with the operator’s lowercased or snake_case form).

  • 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 (with test_cc_ also stripped for cases registered by lib_onnx_backend_test).

onnx_light.tools.schema_comparison.compute_schema_comparison() SchemaComparison#

Computes the full SchemaComparison.

The function silently degrades when the upstream onnx package is not importable: the onnx-side columns are then left empty and SchemaComparison.onnx_available is set to False.

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-table directive per domain.

Parameters:
  • comparison – The comparison to render.

  • only_in_either – When True (the default), operators that are absent from both onnx and onnx_light (this can happen for custom-domain test fixtures) are filtered out.

  • css_class – When provided, a :class: option is emitted on the list-table directive. This is used by the documentation to opt the rendered <table> element into the sphinx-datatables extension (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 runpython block.