tensorflow/models · error · ValueError
num_shards: %d mod shards_per_group: %d, should be 0
Error message
num_shards: %d mod shards_per_group: %d, should be 0
What it means
Error "num_shards: %d mod shards_per_group: %d, should be 0" thrown in tensorflow/models.
Source
Thrown at official/projects/edgetpu/vision/modeling/common_modules.py:43
STDDEV_RGB = (0.5 * 255, 0.5 * 255, 0.5 * 255)
@tf_keras.utils.register_keras_serializable(package='Vision')
class TpuBatchNormalization(tf_keras.layers.BatchNormalization):
"""Cross replica batch normalization."""
def __init__(self, fused: Optional[bool] = False, **kwargs):
if fused in (True, None):
raise ValueError('TpuBatchNormalization does not support fused=True.')
super(TpuBatchNormalization, self).__init__(fused=fused, **kwargs)
def _cross_replica_average(self, t: tf.Tensor, num_shards_per_group: int):
"""Calculates the average value of input tensor across TPU replicas."""
num_shards = tpu_function.get_tpu_context().number_of_shards
group_assignment = None
if num_shards_per_group > 1:
if num_shards % num_shards_per_group != 0:
raise ValueError(
'num_shards: %d mod shards_per_group: %d, should be 0' %
(num_shards, num_shards_per_group))
num_groups = num_shards // num_shards_per_group
group_assignment = [[
x for x in range(num_shards) if x // num_shards_per_group == y
] for y in range(num_groups)]
return tf1.tpu.cross_replica_sum(t, group_assignment) / tf.cast(
num_shards_per_group, t.dtype)
def _moments(self,
inputs: tf.Tensor,
reduction_axes: int,
keep_dims: int,
mask: Optional[tf.Tensor] = None):
"""Compute the mean and variance: it overrides the original _moments."""
shard_mean, shard_variance = super(TpuBatchNormalization, self)._moments(
inputs, reduction_axes, keep_dims=keep_dims, mask=mask)
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/projects/edgetpu/vision/modeling/common_modules.py:43 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/ca22aef20cd5484f.
Report an issue: GitHub.