expect.h#

namespace onnx_light

Alias that makes onnx-light headers compatible with code that references ONNX_LIGHT_NAMESPACE (the macro used in the standard onnx package).

Set to ONNX_LIGHT_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when lib_onnx_proto uses hidden visibility by default.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_light (via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs from onnx.

namespace core#
namespace backend_test#

Functions

void Expect(const NodeProto &node, const Tensors &inputs, const Tensors &outputs, const std::string &name, const std::vector<OpsetId> &opset_imports, const std::string &producer_name, std::vector<TestCase> &registry, TestCaseTag tag = TestCaseTag::NONE, const std::vector<TypeSpec> &output_types = {}, double rtol = 1e-3, double atol = 1e-7)#

Appends a lazy single-node :ref:TestCase built from node and the provided typed inputs/outputs to registry.

Mirrors onnx_light.backend.test.case.base.expect(). Only the inputs and outputs whose name is non-empty in the node are wired into the graph. The ModelProto and data set are not built at registration time; the given node/inputs/outputs are captured and :func:BuildSingleNodeCase is invoked only when the case is materialized (via TestCase::model / :func:TestCase::data_sets / :func:TestCase::Materialize). The declared element counts are recorded eagerly from the input/output tensors so the sizing stays inspectable without materializing.

Parameters:
  • node – Single-node template; its op_type, domain and attributes are kept.

  • inputs – Concrete input tensors corresponding to the non-empty entries of node.input.

  • outputs – Concrete expected output tensors corresponding to the non-empty entries of node.output.

  • name – Unique test name (used both for TestCase.name and the graph name).

  • opset_imports – Opset imports for the generated model. If empty the caller is responsible for ensuring a default has been applied — typically pass at least DefaultOpset(since_version).

  • producer_name – Producer name written into the model.

  • registry – Output registry (appended to).

  • tag – Optional grouping tag (defaults to the node domain for non-default operator domains).

  • output_types – Optional per-output declared type specs. When non-empty it must contain one entry per output tensor; each output value-info is then declared from its TypeSpec instead of the materialized tensor type. Used to declare Sequence / Map valued outputs whose runtime representation is a plain Tensor.

  • rtol – Relative tolerance for numeric outputs (default 1e-3).

  • atol – Absolute tolerance for numeric outputs (default 1e-7).

Throws:

std::invalid_argument – if inputs.size() does not equal the number of non-empty entries in node.input or if outputs.size() does not equal the number of non-empty entries in node.output, or if output_types is non-empty and its size does not equal outputs.size().

BuiltCase BuildSingleNodeCase(const NodeProto &node, Tensors inputs, Tensors outputs, const std::string &name, const std::vector<OpsetId> &opset_imports, const std::string &producer_name, const std::vector<TypeSpec> &output_types = {}, std::vector<Map> maps = {})#

Builds a single-node ModelProto and its one data set from node and the provided typed inputs/outputs. This is the shared core of both :func:Expect overloads, invoked on demand when a lazy case is materialized. Only the inputs and outputs whose name is non-empty in the node are wired into the graph.

Map-typed graph inputs are supplied via maps: each Map::name must match a non-empty entry in node.input, is declared with a map(key_type, value_type) TypeProto in the graph, and is stored in DataSet::maps so the runtime can retrieve it by name. The remaining (tensor-typed) inputs come from inputs in positional order. The sum inputs.size() + maps.size() must equal the number of non-empty entries in node.input.

Throws:

std::invalid_argument – under the same conditions as :func:Expect.

void Expect(std::vector<TestCase> &registry, NodeProto node, std::string name, std::vector<OpsetId> opset_imports, std::vector<int64_t> in_counts, std::vector<int64_t> out_counts, std::function<IoData()> make_io, std::string producer_name = "backend-test", TestCaseTag tag = TestCaseTag::NONE, std::vector<TypeSpec> output_types = {}, double rtol = 1e-3, double atol = 1e-7)#

Appends a lazy single-node :ref:TestCase whose inputs/outputs are generated on demand by make_io. Overload of :func:Expect for cases — chiefly the BENCHMARK cases — whose (potentially very large) inputs and expected outputs are too expensive to materialize at registration time. make_io (which performs the input generation and kernel evaluation) is invoked only when the case is materialized via TestCase::model / :func:TestCase::data_sets / :func:TestCase::Materialize. in_counts / out_counts record the declared element count of each input/output so the sizing can be validated without running make_io.

Parameters:
  • registry – Output registry (appended to).

  • node – Single-node template; its op_type, domain and attributes are kept. Consumed (moved).

  • name – Unique test name.

  • opset_imports – Opset imports for the generated model.

  • in_counts – Declared element count of each (non-empty) input.

  • out_counts – Declared element count of each (non-empty) output.

  • make_io – Callable producing the concrete inputs/outputs on demand.

  • producer_name – Producer name written into the model.

  • tag – Optional grouping tag (defaults to the node domain for non-default operator domains).

  • output_types – Optional per-output declared type specs (see :func:Expect).

  • rtol – Relative tolerance for numeric outputs (default 1e-3).

  • atol – Absolute tolerance for numeric outputs (default 1e-7).

void Expect(std::vector<TestCase> &registry, NodeProto node, std::string name, std::vector<OpsetId> opset_imports, std::vector<int64_t> in_counts, std::vector<int64_t> out_counts, std::function<IoData(bool)> make_io, std::string producer_name = "backend-test", TestCaseTag tag = TestCaseTag::NONE, std::vector<TypeSpec> output_types = {}, double rtol = 1e-3, double atol = 1e-7)#

Variant of the lazy :func:Expect callback which receives whether expected outputs were requested. It lets benchmark collectors generate inputs without invoking their output-producing oracle.

inline void Expect(std::vector<TestCase> &registry, NodeProto node, std::string name, std::vector<OpsetId> opset_imports, std::function<IoData()> make_io, std::string producer_name = "backend-test", TestCaseTag tag = TestCaseTag::NONE, std::vector<TypeSpec> output_types = {}, double rtol = 1e-3, double atol = 1e-7)#

Convenience overload of the lazy :func:Expect that omits the element-count vectors. Equivalent to calling the six-parameter lazy overload with empty in_counts / out_counts. Use for small test cases where pre-declaring element counts adds no value over deriving them from the materialised tensors.

template<typename Kernel>
void ExpectBenchmarkUnaryFloat(const std::string &op_type, const std::string &name, const OpsetId &opset, std::vector<TestCase> &registry, bool with_float16 = true, bool with_bfloat16 = true, int64_t size = kBenchmarkElementwiseSize, uint64_t seed = 987654321ULL, const std::string &input_name = "x", const std::string &output_name = "y")#

Appends benchmark :ref:TestCases for a unary element-wise float operator. Kernel is the operator’s kernel type. A fresh instance is constructed only while materializing each case and computes its expected output. The generated node carries no attributes, so operators whose behaviour depends on attributes should build their own benchmark case instead.

When with_float16 is true (the default) a second FLOAT16 benchmark case named name + "_float16" is registered alongside the FLOAT one. Operators whose kernel does not support FLOAT16 must pass with_float16 = false.

A third BFLOAT16 benchmark case named name + "_bfloat16" is registered by default alongside the FLOAT and FLOAT16 cases. Operators whose kernel does not support BFLOAT16 must pass with_bfloat16 = false.

template<typename Kernel>
void ExpectBenchmarkBinaryFloat(const std::string &op_type, const std::string &name, const OpsetId &opset, std::vector<TestCase> &registry, bool with_float16 = true, bool with_bfloat16 = true, int64_t size = kBenchmarkElementwiseSize, uint64_t seed = 987654321ULL)#

Appends benchmark :ref:TestCases for a binary element-wise float operator with two equally-shaped 1-D inputs. Kernel is constructed only while a case is materialized and computes the expected output. The generated node carries no attributes. The inputs and expected output are produced lazily (see the make_io overload of :func:Expect).

When with_float16 is true (the default) a second FLOAT16 benchmark case named name + "_float16" is registered alongside the FLOAT one. Operators whose kernel does not support FLOAT16 must pass with_float16 = false.

A third BFLOAT16 benchmark case named name + "_bfloat16" is registered by default alongside the FLOAT and FLOAT16 cases. Operators whose kernel does not support BFLOAT16 must pass with_bfloat16 = false.

Variables

constexpr int64_t kBenchmarkElementwiseSize = 1 << 22#

Default element count for a 1-D float benchmark input of a cheap element-wise operator. Sized (4M floats = 16 MiB) so a single kernel evaluation processes enough data to be timed reliably (~0.1 s). Operators with heavier per-element cost (transcendental, matmul, …) pass a smaller explicit size to the benchmark helpers below.