yobx.builder.onnxlight#

Native graph-builder bridge built on the published onnx-light wheel.

Provides the native onnx-light graph builder bridge.

class yobx.builder.onnxlight.OnnxLightGraphBuilder(target_opset_or_existing_proto=18, ir_version=None, *, optimization_options=None, convert_options=None, verbose=0, as_function=False)[source]#

Implements converter graph construction using native onnx-light engines.

The persistent shapes_context owns symbolic inference and explicit annotations. The wheel does not expose mutable builder shape information, so changed annotations are synchronized through native model serialization before subsequent construction or optimization. No Python GraphBuilder, pattern optimizer, reference shape inference or reference runtime is used.

Import, graph construction, optimization, inference and both export methods use only native protos. to_onnx() wraps a native model in ExportArtifact and optionally stores large tensors in a native container. Sequence metadata, Torch exporter state and Python optimization/inference options are deliberately unsupported. Tensor ranks must be declared before inference because the wheel cannot distinguish an unknown rank from a scalar in SymTensor.

add_domain(domain, version=1)[source]#

Registers an opset with both native engines.

constant_is_equal_to(name, value)[source]#

Compares a native computed constant without size-dependent shortcuts.

empty_copy(as_function=False)[source]#

Creates an independent native builder with the same converter options.

property functions#

Returns exported native local function definitions.

get_constant(name, exc=True, computed_value=False, as_shape=False, multiple_outputs=False)[source]#

Returns a constant using only the native constant runtime.

get_debug_msg()[source]#

Returns native builder diagnostics.

get_device(name)[source]#

Returns explicit converter device metadata.

get_dimension_as_result(dimension)[source]#

Materializes a named dimension from native input shape descriptors.

get_dynamic_dimension(dimension, keep_const=False)[source]#

Builds a rank-one dimension tensor with native ONNX operators.

get_opset(domain, exc=True)[source]#

Returns the registered domain version.

get_rank(name)[source]#

Returns the tensor rank.

get_sequence(name)[source]#

Rejects unsupported sequence metadata conversion.

get_shape(name: str) → ONNX_SHAPE[source]#

Returns native symbolic dimensions as a tuple.

get_type(name)[source]#

Returns a tensor dtype from the native context.

has_device(name)[source]#

Returns whether explicit converter device metadata is available.

has_name(name)[source]#

Returns whether the native builder knows a value.

has_opset(domain)[source]#

Returns the domain version or zero.

has_rank(name)[source]#

Returns whether the tensor rank is known.

has_shape(name)[source]#

Returns whether the tensor shape, including its rank, is known.

has_type(name)[source]#

Returns whether the native shape context knows a tensor dtype.

property initializers_dict#

Returns a snapshot of native initializer protos.

inline_functions(verbose=0)[source]#

Inlines local functions using the native graph operation.

property inner_builder#

Returns the underlying native GraphBuilder.

property input_names#

Returns declared input names.

property inputs#

Returns native input value infos.

is_constant(name)[source]#

Queries constant ownership through native GraphGraph.

is_sequence(name)[source]#

Returns whether the native context identifies a sequence.

property last_added_node#

Returns the most recently added native node.

property main_opset#

Returns the standard ONNX opset.

make_initializer(name, value, give_unique_name=True, source=None, *, allow_empty=False, msg=None, parameter_name=None)[source]#

Adds an initializer, borrowing supported NumPy and PyTorch storage.

make_local_function(builder, function_options, optimize=False)[source]#

Registers converter functions through native model import.

make_node(op_type, inputs, outputs=1, domain='', attributes=None, name=None, _infer_shapes=True, _synchronize_annotations=True, **kwargs)[source]#

Creates a native node and computes its shape with ShapesContext.

make_subset_builder(input_names, name='', domain='', add_local_functions=False)[source]#

Creates an independent native function builder from selected input descriptors.

make_tensor_input(name, elem_type=None, shape=None, device=None)[source]#

Declares a tensor input with a native value-info proto.

make_tensor_output(name: str | list[str] | tuple[str, ...], elem_type=None, shape=None, indexed=False, allow_untyped_output=False) → str | list[str][source]#

Declares one or more native tensor outputs.

make_tensor_value_info_from_name(name)[source]#

Returns a native value-info using the context’s explicit metadata.

move_initializers_to_constant(full_parameter_name=False)[source]#

Lowers graph initializers to native Constant nodes for function export.

property nodes#

Returns a snapshot of native nodes, not a mutable builder registry.

onnx_dtype_to_np_dtype(itype)[source]#

Returns the NumPy dtype through the native ONNX helper.

property output_names#

Returns declared output names.

property outputs#

Returns native output value infos.

prefix_name_context(prefix)[source]#

Scopes generated names to a nested converter prefix.

pretty_text()[source]#

Returns the native builder’s graph diagnostics.

register_constraint_dimension(dimension, value)[source]#

Registers a symbolic dimension equality in the native context.

remove_identity_nodes()[source]#

Removes internal identities while preserving native graph output names.

remove_unused()[source]#

Removes unused nodes with the native cleanup pass.

set_device(name, device)[source]#

Records device metadata without changing native inference or execution.

set_opset(domain, version=1)[source]#

Registers an opset with both native engines.

set_rank(name, value)[source]#

Records a rank using unknown native symbolic dimensions.

set_sequence(name, dtype, shapes=None, ranks=None, unknown=False)[source]#

Rejects unsupported sequence metadata conversion.

set_shape(name, shape, allow_zero=False, set_if_more_precise=False)[source]#

Sets an explicit shape in the native context.

set_type(name, itype)[source]#

Sets an explicit dtype in the native context.

set_type_shape_or_rank(name, like)[source]#

Copies native tensor descriptors and explicit device metadata.

set_type_shape_unary_op(name, input_name, itype=None)[source]#

Copies a tensor annotation entirely within the native context.

set_value_shape(name, value)[source]#

Records a symbolic shape value in the native inference engine.

to_native(optimize=True, inline=True)[source]#

Returns a native model without importing reference ONNX or its runtime.

Construction, shape inference, optional optimization and serialization remain in onnx-light. The exported model preserves imported metadata and the explicitly requested or imported IR version. Otherwise it uses the native wheel’s default IR version, unlike to_onnx(), which selects a compatible IR version for the declared opsets.

Inlining expands converter functions but preserves functions introduced by native optimization.

Returns:

An onnx_light.onnx.ModelProto.

to_onnx(optimize=True, large_model=False, external_threshold=1024, return_optimize_report=False, inline=True, function_options=None, mask_outputs=None, as_graph_proto=False)[source]#

Exports an artifact after optional native GraphGraph optimization.

unique_dimension_name(prefix='dim')[source]#

Returns a symbolic dimension name absent from native descriptors.

unique_name(prefix='value')[source]#

Returns a collision-free name in the current prefix scope.

value_as_shape(name)[source]#

Returns a shape value recorded by the native inference engine.

class yobx.builder.onnxlight.OnnxLightOptimizationOptions(patterns: str | Sequence[str] | None = None, max_iter: int = -1, verbose: int = 0, remove_unused: bool = True, constant_folding: bool = True, processor: Any | None = None)[source]#

Configures native GraphGraph rewriting without Python optimizer semantics.

patterns=None, "default", or "default+onnxruntime" selects the wheel’s standard patterns. An empty sequence disables pattern rewrites. Other strings must be exact native pattern names. constant_folding controls native folding. GraphGraph owns cleanup and recursive rewriting, and unused-node removal can be controlled independently.

pattern_names()[source]#

Returns validated native pattern names.