Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Onnx Onnx Tensor Specification

From Leeroopedia


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

Overview

A specification mechanism that defines the name, data type, and shape of tensors used as inputs and outputs in a computation graph.

Description

Tensor specification is the foundational step in constructing any ONNX computation graph. Every graph requires explicit declarations of its input and output tensors, each described by a name (unique string identifier), an element type (such as float32, int64), and a shape (a sequence of dimensions that may be fixed integers, symbolic strings, or unknown). These specifications are encoded as ValueInfoProto objects in the ONNX protobuf schema and serve as the contract between the graph and its consumers, ensuring that runtimes can validate tensor compatibility before execution.

The concept addresses the need for a strongly-typed intermediate representation where every edge in the computation graph has a well-defined type and shape, enabling static analysis, shape inference, and cross-framework interoperability.

Usage

Use this principle whenever constructing an ONNX model from scratch. Tensor specifications must be created before assembling a graph, since both graph inputs and outputs require ValueInfoProto declarations. This is also relevant when defining intermediate value information for shape inference or when creating test models for validation.

Theoretical Basis

An ONNX tensor specification is a triple:

Failed to parse (syntax error): {\displaystyle \text{TensorSpec} = (\text{name}, \text{elem\_type}, \text{shape}) }

Where:

  • name is a unique string identifier within the graph
  • elem\_type is an integer constant from the TensorProto.DataType enumeration (e.g., FLOAT=1, INT64=7)
  • shape is a sequence of dimension descriptors, each being:
    • A fixed integer (static dimension)
    • A string (symbolic/dynamic dimension, e.g., "batch_size")
    • None (completely unknown dimension)

Pseudo-code:

# Abstract algorithm for tensor specification
spec = ValueInfoProto()
spec.name = tensor_name
spec.type.tensor_type.elem_type = data_type_constant
for dim in shape:
    if dim is int:     add fixed dimension
    if dim is str:     add symbolic dimension
    if dim is None:    add unknown dimension

Related Pages

Implemented By

Page Connections

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