In this article
The meaning of a zero in a reshape shape tensor depends on allowzero; it cannot be interpreted independently of the operator attributes.
A target shape is not just a list of extents
A graph editor sees a zero in a Reshape target tensor and concludes that the result must be empty. Under the ordinary marker convention, that entry instead copies the corresponding input dimension. Confusing a marker with a literal extent can break batching or sequence handling without changing the number of visible shape entries. Inspect the node attributes and imported schema before interpreting a shape tensor as a fully concrete allocation request.
allowzero selects the interpretation
The Reshape specification describes the default copy behavior and literal-zero behavior selected by allowzero. It also restricts combining literal zeros with an inferred dimension marker. A shape containing 0 and -1 therefore needs interpretation under the actual attribute setting, not a generic arithmetic shortcut. Copying a dimension is a statement about the corresponding input axis; inferring a dimension uses the element-count relationship under the operator’s rules.
Unknown metadata is another separate case
The shape inference guide distinguishes symbolic or unknown extents from known integer values. An unknown annotation does not imply that the runtime shape tensor contains a zero. Keep type metadata and actual shape data separate in diagnostics. The tensor descriptor guide explains related distinctions among dimensions, offsets and strides. A change in logical shape should not be casually interpreted as a guarantee about storage aliasing or allocation.
Validate the graph with representative shape values
The ONNX checker helps establish structural validity after a rewrite. Behavioral validation must additionally exercise the target shape values that the application actually supplies. Compare a copied nonempty dimension, a supported empty case and an inferred-dimension case where appropriate. If the application forbids empty tensors, document that restriction at its input boundary instead of relying on a graph annotation accidentally excluding an untested value.
Keep marker semantics visible in adapters
An adapter that serializes shapes should preserve the attribute-controlled distinction rather than replacing all markers with guessed sizes. Explain the source of each target-shape entry and retain the original graph for comparison. The explicit schema guide offers the same practical principle for input interpretation: a sentinel’s meaning belongs to its contract. Here that contract is the selected Reshape definition and its attributes, not the visual appearance of the integer list alone.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.