onnx_light.onnx.backend#

class onnx_light.onnx.backend.TestCase(*args, **kwargs)#

A single C++-generated backend test case (mirrors onnx_light.backend.test.case.base.TestCase).

property atol#

(self) -> float

property data_sets#

Returns the input/output data sets of this test case, materializing them first for lazily-built cases.

property kind#

(self) -> str

property model#

Returns the ModelProto of this test case, resolved against the binding registered by _onnxpyprotoop. Built on demand for lazily-built (benchmark) cases.

property model_name#

(self) -> str

property name#

(self) -> str

property rtol#

(self) -> float

property tag#

(self) -> str

class onnx_light.onnx.backend.TestMode(*values)#

Selects how backend test cases are generated. TEST (the default) yields the standard correctness cases. BENCHMARK yields large-input cases sized so a single kernel evaluation runs long enough to be timed (~0.1 s), for categories that support it.

onnx_light.onnx.backend.collect_test_case(include_big: bool = False, mode: TestMode | None = None) dict[str, TestCase]#

Collects all backend test cases.

The canonical node test cases are produced by the C++ lib_onnx_backend_test library and exposed through the onnx_light.onnx_py._onnxpy.backend_test Python bindings. In addition, any user-defined Base subclass with export* class methods is executed so that downstream code can still register extra Python-defined cases through the expect() helper. Python-defined cases take precedence over C++ cases of the same name.

Parameters:
  • include_big – When True, includes backend test cases whose name contains "_big_". Defaults to False, which keeps these big cases excluded.

  • mode – The generation mode (a TestMode value). When None (default), defaults to TestMode.TEST which yields the standard correctness cases. TestMode.BENCHMARK yields large benchmark-sized cases where supported.

Returns:

A dictionary mapping test case names to TestCase instances.

onnx_light.onnx.backend.collect_test_cases_by_name(pattern: str | Pattern[str], include_big: bool = False, mode: TestMode | None = None) list[TestCase]#

Returns the C++-implemented backend test cases whose name matches pattern.

The actual filtering happens in C++ (onnx_kernels::CollectTestCasesByName) using std::regex_search with ECMAScript syntax. A compiled re.Pattern is accepted for convenience and is forwarded as its source string.

Parameters:
  • pattern – A regular expression (as a string or a pre-compiled re.Pattern) matched against TestCase.name. Use "^...$" to require a full match.

  • include_big – When True, includes backend test cases whose name contains "_big_". Defaults to False, which keeps these big cases excluded.

  • mode – Selects the generation mode. TestMode.TEST (the default when None) yields the standard correctness cases; TestMode.BENCHMARK yields large benchmark-sized cases where supported.

Returns:

The list of TestCase instances (in their natural registration order) whose name matches pattern.

Raises:
  • TypeError – If pattern is neither a string nor a compiled regular expression.

  • ValueError – If pattern is not a valid regular expression.

onnx_light.onnx.backend.get_test_case(name: str, mode: TestMode | None = None) TestCase | None#

Returns a single backend test case by exact name, or None.

Unlike collect_test_case(), which collects all C++ test cases and converts every one to Python, this function uses the C++ exact-name lookup (get_test_case_by_name()) to retrieve only the requested case without regex overhead. This is significantly faster when only one case is needed.

Parameters:
  • name – The exact test case name (e.g. "test_cc_loop_zero_trip_count").

  • mode – The generation mode (a TestMode value). When None (default), defaults to TestMode.TEST.

Returns:

The TestCase instance, or None if no case with that name exists.

onnx_light.onnx.backend.make_test_class(rt: Callable, include_regex: Sequence[str] | None = None, exclude_regex: Sequence[str] | None = None, atols: dict[str, float] | None = None, rtols: dict[str, float] | None = None, include_big: bool = False)#

Collects all test cases with collect_test_case. Keeps or removes tests based on include_regex and exclude_regex. Creates a test class which has a test method per test, like test_{name}. Compares outputs.

If rt declares a single positional parameter (i.e. rt(model)), it is treated as a model-level validator: it is invoked once per test case as rt(tc.model) and no output comparison is performed. This is the path used by onnx_light.onnx.checker (check_model).