Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Onnx Onnx Helper Make Tensor Value Info

From Leeroopedia
Revision as of 16:12, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Onnx_Onnx_Helper_Make_Tensor_Value_Info.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Model_Construction, Intermediate_Representation
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete tool for creating tensor type and shape specifications provided by the ONNX helper module.

Description

The make_tensor_value_info function constructs a ValueInfoProto protobuf message that describes a tensor's name, element data type, and shape. It is the primary entry point for declaring graph inputs and outputs when building ONNX models programmatically. Internally, it delegates to make_tensor_type_proto to populate the type field with a TypeProto containing tensor type and shape information.

Usage

Import this function when you need to define input or output tensor specifications for an ONNX graph. It is always the first step in programmatic model construction, called before make_graph to create the input/output declarations that the graph requires.

Code Reference

Source Location

  • Repository: onnx
  • File: onnx/helper.py
  • Lines: 829-844

Signature

def make_tensor_value_info(
    name: str,
    elem_type: int,
    shape: Sequence[str | int | None] | None,
    doc_string: str = "",
    shape_denotation: list[str] | None = None,
) -> ValueInfoProto:
    """Makes a ValueInfoProto based on the data type and shape.

    Args:
        name: Tensor name identifier (unique within the graph).
        elem_type: TensorProto data type constant (e.g., TensorProto.FLOAT).
        shape: Dimension sizes. int for fixed, str for symbolic, None for unknown.
               Pass None for a completely unranked tensor.
        doc_string: Optional documentation string.
        shape_denotation: Optional semantic labels for each dimension.
    """

Import

from onnx import helper, TensorProto

I/O Contract

Inputs

Name Type Required Description
name str Yes Unique tensor name identifier within the graph
elem_type int Yes TensorProto data type constant (e.g., TensorProto.FLOAT = 1)
shape Sequence[str, int, None] or None Yes Dimension sizes; int=fixed, str=symbolic, None=unknown dimension
doc_string str No Optional documentation string (default: "")
shape_denotation list[str] or None No Optional semantic labels per dimension

Outputs

Name Type Description
return ValueInfoProto Protobuf message describing the tensor's name, type, and shape

Usage Examples

Basic Float Tensor

from onnx import helper, TensorProto

# Define a 2D float tensor input with fixed shape
X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [3, 4])

# Define an output with symbolic batch dimension
Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, ["batch", 10])

Dynamic and Unknown Dimensions

from onnx import helper, TensorProto

# Symbolic batch dimension, fixed feature dimension
input_spec = helper.make_tensor_value_info("input", TensorProto.FLOAT, ["N", 784])

# Completely unknown rank (unranked tensor)
unknown_spec = helper.make_tensor_value_info("dynamic", TensorProto.FLOAT, None)

# Mixed: some dimensions unknown
mixed_spec = helper.make_tensor_value_info("mixed", TensorProto.INT64, [None, 256, None])

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment