jax-ml/jax · error · ValueError

Tiles must not be empty

Error message

Tiles must not be empty

What it means

Each tile tuple inside a Tiling must be non-empty; an empty tuple () cannot split any dimensions. Validated in Tiling.__post_init__.

Source

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

  size. Then, all newly unfolded minor dimensions are transposed to appear at
  the end.

  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()

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Filter out empty tuples before constructing: Tiling([t for t in tiles if t])
  2. Fix the generator so it never emits empty tile tuples

Example fix

// before
Tiling(tiles_list)  # tiles_list contains ()
// after
Tiling([t for t in tiles_list if t])
Defensive patterns

Strategy: validation

Validate before calling

assert all(len(t) > 0 for t in tiles), 'no empty tiles'

Type guard

def has_no_empty_tiles(tiles) -> bool:
    return all(len(t) > 0 for t in tiles)

Prevention

When it happens

Trigger: Passing a tiles list containing an empty tuple, e.g. Tiling([(), (4, 4)]), often from a programmatically generated list with a leftover ().

Common situations: Generated layout specs where a rank-0 fragment was appended; refactoring code that used to filter empty dims.

Related errors


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