Skip to content

Use a typed sentinel for dynamic/batch dimensions instead of raw null in TensorType.dims #545

@khatchad

Description

@khatchad

Summary

After #544 closed the ragged half with a typed RaggedDim sentinel, per-element null in TensorType.dims still encodes "dynamic/batch/placeholder" dimensions at the following sites. The Iterable<Dimension<?>> contract is still violated per-element.

Current State

Raw null is emitted into final shape lists at:

  • Input.java:137 (batchSizes.add(null) for unknown batch size)
  • Input.java:154 (newShape.add(null) for dynamic batch dim)
  • FlowFromDirectoryGenerator.java:75 (labelShape.add(null))
  • TensorGenerator.java:2683 (ret.add(null))

These dims are semantically distinct from ragged: uniform within a tensor instance but unknown statically (e.g., tf.keras.Input(shape=(None, 4))).

Test fixtures TENSOR_*_NONE_* (e.g., TENSOR_NONE_4_FLOAT32, TENSOR_2_NONE_INT32, TENSOR_NONE_NONE_STRING) encode this representation directly and will need migration alongside the source change.

Proposed Fix

Two options:

  1. Mirror Use a typed RaggedDim sentinel for ragged dimensions instead of raw null in TensorType.dims #544 with a DynamicDim extends Dimension<Void> (cheap, follows the just-landed precedent).
  2. Unify with RaggedDim under a single UnknownDim(kind) carrying a tag (RAGGED|DYNAMIC|PLACEHOLDER)—the latter fully discharges the per-element-non-null contract claim originally made in Use a typed RaggedDim sentinel for ragged dimensions instead of raw null in TensorType.dims #544 in one move, at the cost of revisiting that fix.

Hidden coupling to update

TensorShapeUtil.areBroadcastable and TensorShapeUtil.getBroadcastedShapes already special-case null. Whichever encoding is chosen, broadcast must remain "compatible+propagate" for dynamic/batch dims.

Background

Spinoff from #544. The Iterable<Dimension<?>> non-null-element contract claim in that issue is only partially resolved by introducing RaggedDim; this issue tracks the remainder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions