{"record":{"id":"b467127590001219","repo":"tensorflow/models","slug":"inconsistent-shapes-in-shard-tensors-first-is-te","errorCode":null,"errorMessage":"Inconsistent shapes in shard_tensors: first is {tensors[0].shape} and other is {tensor.shape}","messagePattern":"Inconsistent shapes in shard_tensors: first is (.+?) and other is (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/vision/modeling/layers/edgetpu.py","lineNumber":125,"sourceCode":"\n  Args:\n    axis: axis to be used to split tensors\n    block_size: block size to split tensors.\n    tensors: list of tensors.\n\n  Returns:\n    List of shards, each shard has exactly one peace of each input tesnor.\n\n  Raises:\n    ValueError: if input tensors has different size of sharded dimension.\n  \"\"\"\n  if not all(tensor.shape.is_fully_defined() for tensor in tensors):\n    return [tensors]\n  for validate_axis in range(axis + 1):\n    consistent_length: int = tensors[0].shape[validate_axis]\n    for tensor in tensors:\n      if tensor.shape[validate_axis] != consistent_length:\n        raise ValueError('Inconsistent shapes in shard_tensors: first is '\n                         f'{tensors[0].shape} and other is {tensor.shape}')\n  batch_size: int = tensors[0].shape[axis]\n  if block_size >= batch_size:\n    return [tensors]\n  else:\n    blocks = batch_size // block_size\n    remainder = batch_size % block_size\n    if remainder:\n      tensor_parts = []\n      for tensor in tensors:\n        shape: tf.TensorShape = tensor.shape\n        body: tf.Tensor = tf.slice(tensor, [0] * len(shape), [\n            size if i != axis else blocks * block_size\n            for i, size in enumerate(shape)\n        ])\n        tail: tf.Tensor = tf.slice(tensor, [\n            0 if i != axis else (blocks * block_size)\n            for i, _ in enumerate(shape)","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/vision/modeling/layers/edgetpu.py#L107-L143","documentation":"Error \"Inconsistent shapes in shard_tensors: first is {tensors[0].shape} and other is {tensor.shape}\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/vision/modeling/layers/edgetpu.py:125 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}