{"record":{"id":"6efe2d91080d2a75","repo":"jax-ml/jax","slug":"dimension-semantics-must-be-the-same-length-as-gri","errorCode":null,"errorMessage":"dimension_semantics must be the same length as grid.","messagePattern":"dimension_semantics must be the same length as grid\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/pipeline.py","lineNumber":1564,"sourceCode":"  assert not ((num_cores is None) ^ (core_id is None)), (\n      \"Either both num_cores and core_id should be provided, or neither.\")\n  if num_cores is None or core_id is None:\n    # We aren't partitioning the grid\n    return grid, (0,) * len(grid)\n  # Check that num_cores is statically known\n  if not isinstance(num_cores, int):\n    raise NotImplementedError(\n        \"Cannot partition grid over dynamic number of cores.\"\n    )\n  if num_cores == 1:\n    # We aren't partitioning the grid\n    return grid, (0,) * len(grid)\n\n  # If dimension_semantics aren't provided, we assume it is all arbitrary.\n  if dimension_semantics is None:\n    dimension_semantics = (ARBITRARY,) * len(grid)\n  if len(dimension_semantics) != len(grid):\n    raise ValueError(\"dimension_semantics must be the same length as grid.\")\n\n  parallel_dimensions = {\n      i for i, d in enumerate(dimension_semantics) if d == PARALLEL\n  }\n  # If there are no parallel dimensions, we can't partition the grid\n  if not parallel_dimensions:\n    # TODO(sharadmv): enable running kernel on just one core\n    raise NotImplementedError(\n        \"Cannot partition over cores without parallel grid dimensions:\"\n        f\" {dimension_semantics=}\"\n    )\n\n  # Try to find a divisible dimension to partition the grid on\n  divisible_dimensions = {\n      i\n      for i in parallel_dimensions\n      if isinstance(grid[i], int) and grid[i] % num_cores == 0\n  }","sourceCodeStart":1546,"sourceCodeEnd":1582,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/pipeline.py#L1546-L1582","documentation":"dimension_semantics labels each grid axis as PARALLEL or ARBITRARY and must have exactly one entry per grid dimension. If the tuple length differs from len(grid), partitioning cannot align semantics with axes and this ValueError is raised.","triggerScenarios":"Calling the pipeline API with dimension_semantics shorter/longer than grid, e.g. grid=(4, 8, 2) with dimension_semantics=('parallel', 'arbitrary').","commonSituations":"Adding a grid dimension (e.g. batching) without updating dimension_semantics; defaulting semantics for a different grid shape than the one passed.","solutions":["Make dimension_semantics length match len(grid), one label per axis","Omit dimension_semantics to get the all-ARBITRARY default (note: partitioning then requires no parallel dims, see error 2228)","Build it programmatically: ('parallel',) * len(grid) when all axes are parallel"],"exampleFix":"# before\ngrid=(4, 8, 2), dimension_semantics=('parallel', 'arbitrary')\n# after\ngrid=(4, 8, 2), dimension_semantics=('parallel', 'arbitrary', 'parallel')","handlingStrategy":"validation","validationCode":"assert dimension_semantics is None or len(dimension_semantics) == len(grid), \\\n    f'{len(dimension_semantics)} semantics vs grid of rank {len(grid)}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate dimension_semantics programmatically from len(grid)","Update semantics whenever a grid axis is added or removed"],"tags":["jax","pallas","dimension-semantics","validation"],"backgroundTag":"length-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}