yobx.builder.onnxlight.bridge_graph_builder#
Adapts the published onnx-light native builder to the converter protocol.
- class yobx.builder.onnxlight.bridge_graph_builder.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_contextowns 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 inExportArtifactand 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 inSymTensor.- 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_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.
- property initializers_dict#
Returns a snapshot of native initializer protos.
- property inner_builder#
Returns the underlying native GraphBuilder.
- property input_names#
Returns declared input names.
- property inputs#
Returns native input value infos.
- 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.
- property output_names#
Returns declared output names.
- property outputs#
Returns native output value infos.
- 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.
- set_device(name, device)[source]#
Records device metadata without changing native inference or execution.
- 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_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.
- class yobx.builder.onnxlight.bridge_graph_builder.OnnxLightGraphBuilderOpset(builder)[source]#
Normalizes operator convenience calls and historical axes signatures.
- class yobx.builder.onnxlight.bridge_graph_builder.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_foldingcontrols native folding. GraphGraph owns cleanup and recursive rewriting, and unused-node removal can be controlled independently.