yobx.xbuilder#

API for the graph builder used to construct and optimize ONNX graphs.

GraphBuilder and OptimizationOptions expose the native onnx-light adapter. The historical yobx.xbuilder.graph_builder and yobx.xbuilder.optimization_options imports resolve to the same classes. Graph construction, shape inference and pattern optimization do not fall back to the former Python engines.

Native optimization options select registered pattern names through patterns and limit iterations through max_iter. "default+onnxruntime" remains a compatibility alias for the native default patterns. Python pattern objects, other legacy pattern groups, and unsupported legacy options raise explicit errors.

The historical graph_builder_opset.Opset import resolves to the native adapter too. The Python OrderOptimization engine and OrderAlgorithm selection have been retired; shape-node ordering uses the native builder’s move_shape_and_size_nodes operation.

GraphBuilder#

yobx.xbuilder.GraphBuilder[source]#

alias of OnnxLightGraphBuilder

FunctionOptions#

class yobx.xbuilder.FunctionOptions(export_as_function: bool = False, name: str = '', domain: str = '', external_threshold: int = 33554432, move_initializer_to_constant: bool = False, return_initializer: bool = False, inline: bool = False, merge_allowed: bool = False, rename_allowed: bool = False)[source]#

Defines how local functions must behave.

Parameters:
  • name – function name

  • domain – function domain

  • export_as_function – export the onnx as functions or keep local function

  • external_threshold – whether or not keep initializer as input for the function or move them as constant of the function

  • move_initializer_to_constant – move initializers as constant first before creating the function proto, that depends on the size defined by external_threshold

  • return_initializer – return the remaining initializer and add them as input to the function

  • inline – inline functions

  • rename_allowed – allow to rename the function if a duplicate is detected

  • merge_allowed – allow to merge a function in case the same code is detected

InferShapesOptions#

class yobx.xbuilder.InferShapesOptions(*values)[source]#

Defines options when running shape inference on an existing model. Options NEW means shapes information is removed by running it again.

OptimizationOptions#

yobx.xbuilder.OptimizationOptions[source]#

alias of OnnxLightOptimizationOptions

Intermediate Classes#

InitializerInfo#

class yobx.xbuilder._initializer_info.InitializerInfo(name: str, source: str, same_as: str | None = None)[source]#

Tracks the location where the initializer was created.

Parameters:
  • name – initializer name

  • source – information

  • same_as – same as an existing initializers

add_source(source: str)[source]#

Adds other sources.

VirtualTensor#

class yobx.xbuilder._virtual_tensor.VirtualTensor(name: str, dtype: Any, shape: Tuple[int | str, ...], device: int | None = None)[source]#

Defines the type and shape of a tensor without its content.

get_device() → int | None[source]#

Returns device.

WrapDim#

class yobx.xbuilder._wrap_dim.WrapDim(name: str)[source]#

Wraps a string considered as a torch.export.Dim.

property name_as_string#

Returns the name as a string.

WrapSym#

class yobx.xbuilder._wrap_sym.WrapSym(sym: torch.SymInt | torch.SymFloat | WrapSym)[source]#

Wraps a symbolic int (a dimension for example).

property name#

Returns the name as a string.