Value¶

class onnx_ir.Value(producer: Node | None = None, *, index: int | None = None, name: str | None = None, shape: Shape | None = None, type: TypeProtocol | None = None, doc_string: str | None = None, const_value: TensorProtocol | None = None)¶

IR Value.

A value is a named entity that can be used to represent an input or output of a graph, a function, or a node. The information it stores generalizes over ValueInfoProto in the ONNX specification.

A Value is always not owned or owned by exactly one node. When the value is not owned, it must be an input of a graph or a function. producer and index are None.

When the value is owned by a node, it is an output of the node. The node that produces the value can be accessed with producer(). The index of the output of the node that produces the value can be accessed with index().

To find all the nodes that use this value as an input, call uses().

To check if the value is an is an input, output or initializer of a graph, use is_graph_input(), is_graph_output() or is_initializer().

Use graph() to get the graph that owns the value.

doc_string¶
property const_value: TensorProtocol | None¶

A concrete value.

The value can be backed by different raw data types, such as numpy arrays. The only guarantee is that it conforms TensorProtocol.

consumers() Sequence[Node][source]¶

Return the nodes (deduplicated) that consume this value.

display(*, page: bool = False) None¶

Pretty print the object.

Parameters:

page – Whether to page the output.

property dtype: DataType | None¶

The data type of the tensor.

property graph: Graph | None¶

Return the graph that defines this value.

When the value is an input/output/initializer of a graph, the owning graph is that graph. When the value is an output of a node, the owning graph is the graph that the node belongs to. When the value is not owned by any graph, it returns None.

index() int | None[source]¶

The index of the output of the defining node.

is_graph_input() bool[source]¶

Whether the value is an input of a graph.

is_graph_output() bool[source]¶

Whether the value is an output of a graph.

is_initializer() bool[source]¶

Whether the value is an initializer of a graph.

property meta: MetadataStore¶

The metadata store for intermediate analysis.

Write to the metadata_props if you would like the metadata to be serialized to the ONNX proto.

property metadata_props: dict[str, str]¶
property name: str | None¶
producer() Node | None[source]¶

The node that produces this value.

When producer is None, the value does not belong to a node, and is typically a graph input or an initializer. You can use graph`() to find the graph that owns this value. Use is_graph_input(), is_graph_output() or is_initializer() to check if the value is an input, output or initializer of a graph.

property shape: Shape | None¶
property type: TypeProtocol | None¶

The type of the tensor.

Example types can be TensorType, SparseTensorType, SequenceType, OptionalType. To obtain the data type of the tensor, use type.dtype or conveniently dtype.

uses() Collection[Usage][source]¶

Return a set of uses of the value.

The set contains tuples of (Node, index) where the index is the index of the input of the node. For example, if node.inputs[1] == value, then the use is (node, 1).