{"record":{"id":"0ad31a93d7733461","repo":"jax-ml/jax","slug":"shape-shape-and-strides-strides-must-have-the","errorCode":null,"errorMessage":"Shape {shape} and strides {strides} must have the same length","messagePattern":"Shape (.+?) and strides (.+?) must have the same length","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/fragmented_array.py","lineNumber":208,"sourceCode":"      tiles.append(t)\n    return Tiling(tuple(tiles))\n\n  def tile_nested_shape_strides(\n      self,\n      shape: tuple[tuple[int, ...], ...],\n      strides: tuple[tuple[int, ...], ...],\n  ) -> tuple[tuple[tuple[int, ...], ...], tuple[tuple[int, ...], ...]]:\n    \"\"\"A fused version of `tile_shape` and `tile_strides` for nested shapes.\n\n    By nested shape we mean that each logical dimension (i.e. each element of\n    shape/strides) is actually composed out of multiple physical dimensions.\n    For example, a row-major array of logical shape (128, 128) that is tiled\n    into (64, 64) tiles would have a nested shape ((2, 64), (2, 64)) (i.e. each\n    dim is split into two sub-dims) and nested strides of\n    ((2 * 64 * 64, 64), (64 * 64, 1)).\n    \"\"\"\n    if len(shape) != len(strides):\n      raise ValueError(\n          f\"Shape {shape} and strides {strides} must have the same length\"\n      )\n    def fail_if(cond, shape=shape):  # Capture shape now.\n      if cond:\n        raise ValueError(f\"Tiling {self.tiles} does not apply to shape {shape}\")\n    for tile in self.tiles:\n      fail_if(len(tile) > len(shape))\n      untiled_shape, tiled_shape = shape[:-len(tile)], shape[-len(tile):]\n      untiled_strides, tiled_strides = strides[:-len(tile)], strides[-len(tile):]\n      major_dim_shapes, major_dim_strides = [], []\n      minor_dim_shapes, minor_dim_strides = [], []\n      for t, dim_shape, dim_strides in zip(tile, tiled_shape, tiled_strides):\n        major_dim_shape_rev, major_dim_stride_rev = [], []\n        minor_dim_shape_rev, minor_dim_stride_rev = [], []\n        for d, s in zip(reversed(dim_shape), reversed(dim_strides), strict=True):\n          if d < t:  # We will need to tile more dims\n            fail_if(t % d != 0)\n            t //= d","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/fragmented_array.py#L190-L226","documentation":"Tiling.tile_nested_shape_strides requires parallel shape and strides sequences of the same length; a length mismatch means the caller paired a shape with strides from a different rank/layout.","triggerScenarios":"Calling tile_nested_shape_strides(shape, strides) where len(shape) != len(strides) — e.g. passing strides computed from a different (pre- or post-reshape) layout, or forgetting the stride for one dim.","commonSituations":"Hand-assembling tiled transfer descriptors (transfer_tiled / plan_tiled_transfer) with mismatched metadata; shape changes after strides were computed.","solutions":["Recompute strides from the same shape/rank you pass in (keep them derived together)","Assert len equality before calling","Use the library helpers that produce shape+strides jointly"],"exampleFix":"// before\nshape, strides = (2, 64), compute_strides((2, 64, 64))\ntiling.tile_nested_shape_strides(shape, strides)\n// after\nassert len(shape) == len(strides)\ntiling.tile_nested_shape_strides(shape, strides)","handlingStrategy":"type-guard","validationCode":"assert len(shape) == len(strides), 'shape/strides rank mismatch'","typeGuard":"def matching_rank(shape, strides) -> bool:\n    return len(shape) == len(strides)","tryCatchPattern":null,"preventionTips":["Derive strides from the same shape object passed in","Compute shape+strides jointly with library helpers for tiled transfers"],"tags":["mosaic","fragmented-array","tiling","shape-strides","validation"],"backgroundTag":"shape-strides-rank-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}