Skip to main content

Module shape_data

Module shape_data 

Source
Expand description

Shape-DATA propagation: ShapeData.

The single most important idea carried over from the reference implementation (justinchuby/onnx-shape-inference). Standard shape inference propagates the shape of each tensor; it cannot resolve a Reshape whose target vector is computed at runtime from a Shape op. Shape-data propagation additionally tracks the known element values of the small integer tensors that make up those shape-computation subgraphs — Shape → Slice → Concat → Gather → Unsqueeze → Reshape — so the reshape target resolves symbolically without executing the graph. This is exactly what lets transformer graphs (BERT and friends) infer statically.

A ShapeData models a rank-0 (scalar) or rank-1 (vector) integer tensor whose elements are DimExprs (so they may be concrete or symbolic — e.g. the batch/seq_len dims read out of a Shape op). Only small integer tensors are tracked; everything else has no shape-data.

Structs§

ShapeData
The known element values of a rank-0 or rank-1 integer tensor flowing through a shape-computation subgraph.

Constants§

MAX_SHAPE_DATA_ELEMS
Upper bound on the element count a ShapeData will hold. Shape-vectors are tiny (a handful of dims); this keeps propagation bounded and prevents an accidental attempt to track a large weight tensor’s contents.