jax-ml/jax · error · ValueError

All elements in the grid must be strictly positive, but got

Error message

All elements in the grid must be strictly positive, but got {grid=}

What it means

Before running, the pipeline checks that every statically-known (Python int) grid dimension is > 0. A zero or negative extent would mean an empty or invalid iteration space, so ValueError is raised listing the grid.

Source

Thrown at jax/_src/pallas/mosaic/pipeline.py:2018

def emit_pipeline(
    body,
    *,
    grid: tuple[int | jax.Array, ...],
    in_specs=(),
    out_specs=(),
    tiling: Tiling | None = None,
    core_axis: tuple[int, ...] | int | None = None,
    core_axis_name: tuple[str, ...] | str | None = None,
    dimension_semantics: tuple[GridDimensionSemantics, ...] | None = None,
    trace_scopes: bool = True,
    no_pipelining: bool = False,
    _explicit_indices: bool = False,
):
  in_specs = _normalize_specs(in_specs)
  out_specs = _normalize_specs(out_specs)

  if any(g <= 0 for g in grid if isinstance(g, int)):
    raise ValueError(
        f"All elements in the grid must be strictly positive, but got {grid=}"
    )

  if core_axis is not None and core_axis_name is not None:
    raise ValueError("Only one of `core_axis` or `core_axis_name` can be set.")
  core_axis_ = core_axis_name if core_axis is None else core_axis
  if dimension_semantics is None:
    dimension_semantics = (ARBITRARY,) * len(grid)

  num_in_specs = len(in_specs)

  def wrapped(*args, allocations=None, **kwargs):
    num_cores, core_id = _resolve_core_info(core_axis_)

    if allocations is not None and not in_specs and not out_specs:
      flat_allocs = [
          b for b in allocations if isinstance(b, BufferedRefBase) or b is None
      ]

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Trace where the zero/negative value comes from and guard upstream: skip the kernel or clamp the dimension
  2. Fix size math, e.g. use max(1, ...) only if a 1-iteration no-op run is acceptable
  3. Add an assert all(g > 0 for g in grid if isinstance(g, int)) before dispatch

Example fix

# before
grid=(math.ceil(numel / block), 128)  # numel == 0 -> grid[0] == 0
# after
assert numel > 0
grid=(math.ceil(numel / block), 128)
Defensive patterns

Strategy: validation

Validate before calling

assert all(g > 0 for g in grid if isinstance(g, int)), f'non-positive grid: {grid}'

Prevention

When it happens

Trigger: A grid dimension computes to 0 or negative: empty batch, ceil(n/block) with n==0, or a negative size from subtraction, e.g. grid=(0, 128).

Common situations: Edge-case inputs (empty tensors), off-by-one size math, dynamic dims that became 0 after masking/clamping, or a default grid entry never set (0).

Related errors


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