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
ModelProtoof 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.BENCHMARKyields 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_testlibrary and exposed through theonnx_light.onnx_py._onnxpy.backend_testPython bindings. In addition, any user-definedBasesubclass withexport*class methods is executed so that downstream code can still register extra Python-defined cases through theexpect()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 toFalse, which keeps these big cases excluded.mode – The generation mode (a
TestModevalue). WhenNone(default), defaults toTestMode.TESTwhich yields the standard correctness cases.TestMode.BENCHMARKyields 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) usingstd::regex_searchwith ECMAScript syntax. A compiledre.Patternis 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 againstTestCase.name. Use"^...$"to require a full match.include_big – When
True, includes backend test cases whose name contains"_big_". Defaults toFalse, which keeps these big cases excluded.mode – Selects the generation mode.
TestMode.TEST(the default whenNone) yields the standard correctness cases;TestMode.BENCHMARKyields large benchmark-sized cases where supported.
- Returns:
The list of
TestCaseinstances (in their natural registration order) whosenamematches 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
TestModevalue). WhenNone(default), defaults toTestMode.TEST.
- Returns:
The
TestCaseinstance, orNoneif 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
rtdeclares a single positional parameter (i.e.rt(model)), it is treated as a model-level validator: it is invoked once per test case asrt(tc.model)and no output comparison is performed. This is the path used byonnx_light.onnx.checker(check_model).