tensorflow/models · error · ValueError
Inconsistent shapes in shard_tensors: first is {tensors[0].s
Error message
Inconsistent shapes in shard_tensors: first is {tensors[0].shape} and other is {tensor.shape} What it means
Error "Inconsistent shapes in shard_tensors: first is {tensors[0].shape} and other is {tensor.shape}" thrown in tensorflow/models.
Source
Thrown at official/vision/modeling/layers/edgetpu.py:125
Args:
axis: axis to be used to split tensors
block_size: block size to split tensors.
tensors: list of tensors.
Returns:
List of shards, each shard has exactly one peace of each input tesnor.
Raises:
ValueError: if input tensors has different size of sharded dimension.
"""
if not all(tensor.shape.is_fully_defined() for tensor in tensors):
return [tensors]
for validate_axis in range(axis + 1):
consistent_length: int = tensors[0].shape[validate_axis]
for tensor in tensors:
if tensor.shape[validate_axis] != consistent_length:
raise ValueError('Inconsistent shapes in shard_tensors: first is '
f'{tensors[0].shape} and other is {tensor.shape}')
batch_size: int = tensors[0].shape[axis]
if block_size >= batch_size:
return [tensors]
else:
blocks = batch_size // block_size
remainder = batch_size % block_size
if remainder:
tensor_parts = []
for tensor in tensors:
shape: tf.TensorShape = tensor.shape
body: tf.Tensor = tf.slice(tensor, [0] * len(shape), [
size if i != axis else blocks * block_size
for i, size in enumerate(shape)
])
tail: tf.Tensor = tf.slice(tensor, [
0 if i != axis else (blocks * block_size)
for i, _ in enumerate(shape)View on GitHub (pinned to e006f5f0d5)
Solutions
- Shard only tensors that all have identical shapes.
- Pad or trim the tensors so every shard tensor has the same shape before calling shard_tensors.
When it happens
Trigger: Thrown at official/vision/modeling/layers/edgetpu.py:125 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/b467127590001219.
Report an issue: GitHub.