jax-ml/jax · error · ValueError

Tile shape must only have positive sizes, got: {self.tiles}

Error message

Tile shape must only have positive sizes, got: {self.tiles}

What it means

Every dimension size in every tile of a Tiling must be a positive integer; a 0 or negative size makes the tiling meaningless and is rejected.

Source

Thrown at jax/experimental/mosaic/gpu/fragmented_array.py:83

  This expression describes multi-level tiling, by applying each element of
  `tiles` in sequence to the array.

  See https://openxla.org/xla/tiled_layout for a more detailed explanation.
  """
  tiles: tuple[tuple[int, ...], ...]

  def __post_init__(self):
    if not self.tiles:
      return
    last_tile_rank = len(self.tiles[0])
    for tile in self.tiles:
      if len(tile) > last_tile_rank:
        raise ValueError("Tiles must have a decreasing rank")
      if not tile:
        raise ValueError("Tiles must not be empty")
      if any(d <= 0 for d in tile):
        raise ValueError(f"Tile shape must only have positive sizes, got: {self.tiles}")
      last_tile_rank = len(tile)

  def __str__(self):
    return f"Tiling({''.join(map(str, self.tiles))})"

  def tile_shape(self, shape: tuple[int, ...]) -> tuple[int, ...]:
    """Computes the shape of an array after tiling."""
    orig_shape = shape
    def fail():
      raise ValueError(f"Tiling {self.tiles} does not apply to shape {orig_shape}")
    for tile in self.tiles:
      if len(tile) > len(shape):
        fail()
      untiled_dims, tiled_dims = shape[:-len(tile)], shape[-len(tile):]
      if any(s % t != 0 for s, t in zip(tiled_dims, tile)):
        fail()
      shape = (*untiled_dims, *(d // t for d, t in zip(tiled_dims, tile)), *tile)
    return shape

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Check the computed tile dims for <=0 before building the Tiling
  2. Ensure the tile divides the array dims and the base shape is large enough
  3. Use validated constructors from fa.TiledLayout which clamp/validate

Example fix

// before
Tiling([(shape[0] // k, shape[1])])  # shape[0]//k == 0
// after
assert shape[0] // k > 0, 'tile dim must be positive'
Tiling([(shape[0] // k, shape[1])])
Defensive patterns

Strategy: validation

Validate before calling

assert all(d > 0 for t in tiles for d in t), 'tile dims must be positive'

Type guard

def all_tile_dims_positive(tiles) -> bool:
    return all(d > 0 for t in tiles for d in t)

Prevention

When it happens

Trigger: Tiling with a tile like (0, 8) or (-1, 64) — usually from arithmetic that computed a zero/negative tile dim (e.g. shape // something == 0).

Common situations: Deriving tile sizes from runtime parameters where a dimension is smaller than expected, producing 0; bad defaults in layout helpers.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/49beda68a94bb87c. Report an issue: GitHub.