yobx.xshape.native_shape_inference#

Exposes native symbolic inference without a Python shape-engine fallback.

class yobx.xshape.native_shape_inference.NativeShapeInference(verbose=0, opset=None)[source]#

Infers ONNX tensor descriptors with a persistent native ShapesContext.

TYPE uses the same native engine but exposes only element types. Unknown operators and incompatible constraints raise the native exception, including when the legacy exc=False argument is supplied. Custom inference can be registered directly on context.

add_to_constraints(dim_name: str, value: int | str | set[int | str]) → None[source]#

Registers one or several native dimension equalities.

estimate_node_flops(node)[source]#

Estimates arithmetic cost using only native descriptors and values.

evaluate_cost_with_true_inputs(feeds, cost, exc=False)[source]#

Evaluates symbolic costs against actual input dimensions.

evaluate_shape(name: str, context: dict[str, int]) → tuple[int | None, ...][source]#

Evaluates native expressions and preserves anonymous unknown dimensions.

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

Returns a registered literal without evaluating Python operators.

get_debug_msg(limit=1000)[source]#

Returns a compact native inference diagnostic.

get_device(name)[source]#

Returns caller-supplied device metadata.

get_opset(name)[source]#

Returns the native domain opset.

get_rank(name)[source]#

Returns the inferred rank.

get_registered_constraints() → dict[str, set[int | str]][source]#

Returns equality constraints recorded by the native engine.

get_shape(name: str) → Tuple[int | str | None, ...][source]#

Returns native dimensions, preserving anonymous dimensions as None.

get_shape_renamed(name)[source]#

Returns dimensions as resolved by the native engine.

get_type(name)[source]#

Returns the native element type, or zero when unavailable.

has_device(name)[source]#

Returns whether optional device metadata was supplied.

has_opset(name)[source]#

Returns whether the domain has an opset.

has_rank(name)[source]#

Returns whether a native shape is available.

has_shape(name, full=False)[source]#

Returns whether a native shape is available.

has_type(name)[source]#

Returns whether a native element type is available.

property input_names#

Returns the model input names.

is_constant(name)[source]#

Returns whether a literal tensor is registered.

property main_opset#

Returns the default-domain opset.

property output_names#

Returns the model output names.

register_constraint_dimension(dim_name: str, value: int | str | set[int | str]) → None[source]#

Registers one or several native dimension equalities.

reset_types_and_shapes()[source]#

Clears inferred descriptors and native callbacks.

run_model(model, functions=None, exc=False, inference=InferenceMode.SHAPE)[source]#

Runs native inference and optionally returns per-node cost statistics.

run_node(node, exc=False, cost=True)[source]#

Infers a node natively and optionally estimates its arithmetic cost.

set_constant(name, value)[source]#

Registers a literal through native Constant inference.

set_device(name: str, device: int, **kwargs) → None[source]#

Stores optional device metadata without performing inference.

set_opset(name: str, version: int) → None[source]#

Registers a domain opset with the native engine.

set_rank(name, rank)[source]#

Seeds a rank with anonymous native dimensions.

set_shape(name, shape, exc=False, **kwargs)[source]#

Seeds a native descriptor with dimensions.

set_type(name: str, itype: int, exc: bool = True) → bool[source]#

Seeds a native descriptor with an element type.

set_value_shape(name, value, equal_to=None)[source]#

Seeds native shape-tensor values.

to_onnx()[source]#

Returns an inferred copy of the most recently processed model.

update_shapes(model)[source]#

Writes native inferred descriptors to a model or graph in place.

value_as_shape(name: str) → Tuple[int | str | None, ...] | None[source]#

Returns native shape-tensor values, or None when unavailable.