Skip to main content

OnnxModel

An ONNX model file as an editable graph: open or create one, inspect and edit it, save it, or compile() it into a runnable ModelGraph.

ir_version (property)​

The ONNX IR version.

num_initializers (property)​

The initializer (graph constant) count.

num_nodes (property)​

The node count.

opset (property)​

The ai.onnx opset version.

__init__​

__init__(self, /, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

add_initializer​

add_initializeradd_initializer(self, value: clika_runtime._core.Tensor) -> str

add_initializer(self, value: clika_runtime._core.Tensor) -> str

add_initializer(value) -> str

Create a graph constant from a tensor's bytes; returns the generated initializer name.

add_input​

add_inputadd_input(self, name: str, dtype: clika_runtime._core.DataType, shape: collections.abc.Sequence[int]) -> str

add_input(self, name: str, dtype: clika_runtime._core.DataType, shape: collections.abc.Sequence[int]) -> str

add_input(name, dtype, shape) -> str

Register a graph input; any dim <= 0 declares a dynamic dimension. Returns the tensor name.

add_node​

add_nodeadd_node(self, op_type: str, inputs: collections.abc.Sequence[str], num_outputs: int = 1, attrs: dict = {}, domain: str = '', output_names: collections.abc.Sequence[str] = []) -> list[str]

add_node(self, op_type: str, inputs: collections.abc.Sequence[str], num_outputs: int = 1, attrs: dict = {}, domain: str = '', output_names: collections.abc.Sequence[str] = []) -> list[str]

add_node(op_type, inputs, num_outputs=1, attrs={}, domain='', output_names=()) -> list[str]

Append a node: positional input tensor names in, generated (or caller-named) output names back. Attributes ride a dict of int / float / str / list values.

add_output​

add_outputadd_output(self, name: str, dtype: clika_runtime._core.DataType, shape: collections.abc.Sequence[int]) -> str

add_output(self, name: str, dtype: clika_runtime._core.DataType, shape: collections.abc.Sequence[int]) -> str

add_output(name, dtype, shape) -> str

Register a graph output. Returns the tensor name.

compile​

compilecompile(self, options: object | None = None) -> clika_runtime._core.io.ModelGraph

compile(self, options: object | None = None) -> clika_runtime._core.io.ModelGraph

compile(options=None) -> ModelGraph

Build the executable form: every node parses into its runtime operator (an unsupported op fails here, naming it), weights bind, shapes resolve. options (a CompileOptions) pins input shapes, picks optimization and specialization, and places the weights. Returns the runnable ModelGraph; the OnnxModel is unchanged and reusable.

create​

create(*args, **kwargs)

create(graph_name: str, opset_version: int = 0) -> clika_runtime._core.io.OnnxModel

create(graph_name, opset_version=0) -> OnnxModel

Create an empty model at the given ai.onnx opset (0 = the library default); build it up with add_input / add_initializer / add_node / add_output.

inputs​

inputsinputs(self) -> list

inputs(self) -> list

inputs() -> list[tuple[str, DataType, tuple[int, ...]]]

Graph inputs as (name, dtype, dims) tuples; a dynamic dim reads as -1.

nodes​

nodesnodes(self) -> list[clika_runtime._core.io.OnnxNodeInfo]

nodes(self) -> list[clika_runtime._core.io.OnnxNodeInfo]

nodes() -> list[OnnxNodeInfo]

The graph's nodes in graph order, each with its name, op type, domain and the input and output tensor names; a node's name is what remove_node(name) takes.

open​

open(*args, **kwargs)

open(path: str) -> clika_runtime._core.io.OnnxModel

open(path) -> OnnxModel

Open a .onnx file (initializer payloads referenced as external data stay on disk beside it).

optimize​

optimizeoptimize(self) -> int

optimize(self) -> int

optimize() -> int

Run the graph-rewrite pipeline to a fixed point; returns the pass count.

outputs​

outputsoutputs(self) -> list

outputs(self) -> list

outputs() -> list[tuple[str, DataType, tuple[int, ...]]]

Graph outputs as (name, dtype, dims) tuples.

remove_node​

remove_noderemove_node(self, name: str) -> None

remove_node(self, name: str) -> None

remove_node(name) -> None

Remove the node named name (an error if absent).

save​

savesave(self, path: str) -> None

save(self, path: str) -> None

save(path) -> None

Assemble the model and write it to path.