{"record":{"id":"c0e84707daafbb41","repo":"jax-ml/jax","slug":"all-elements-in-the-grid-must-be-strictly-positive","errorCode":null,"errorMessage":"All elements in the grid must be strictly positive, but got {grid=}","messagePattern":"All elements in the grid must be strictly positive, but got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/pipeline.py","lineNumber":2018,"sourceCode":"def emit_pipeline(\n    body,\n    *,\n    grid: tuple[int | jax.Array, ...],\n    in_specs=(),\n    out_specs=(),\n    tiling: Tiling | None = None,\n    core_axis: tuple[int, ...] | int | None = None,\n    core_axis_name: tuple[str, ...] | str | None = None,\n    dimension_semantics: tuple[GridDimensionSemantics, ...] | None = None,\n    trace_scopes: bool = True,\n    no_pipelining: bool = False,\n    _explicit_indices: bool = False,\n):\n  in_specs = _normalize_specs(in_specs)\n  out_specs = _normalize_specs(out_specs)\n\n  if any(g <= 0 for g in grid if isinstance(g, int)):\n    raise ValueError(\n        f\"All elements in the grid must be strictly positive, but got {grid=}\"\n    )\n\n  if core_axis is not None and core_axis_name is not None:\n    raise ValueError(\"Only one of `core_axis` or `core_axis_name` can be set.\")\n  core_axis_ = core_axis_name if core_axis is None else core_axis\n  if dimension_semantics is None:\n    dimension_semantics = (ARBITRARY,) * len(grid)\n\n  num_in_specs = len(in_specs)\n\n  def wrapped(*args, allocations=None, **kwargs):\n    num_cores, core_id = _resolve_core_info(core_axis_)\n\n    if allocations is not None and not in_specs and not out_specs:\n      flat_allocs = [\n          b for b in allocations if isinstance(b, BufferedRefBase) or b is None\n      ]","sourceCodeStart":2000,"sourceCodeEnd":2036,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/pipeline.py#L2000-L2036","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Trace where the zero/negative value comes from and guard upstream: skip the kernel or clamp the dimension","Fix size math, e.g. use max(1, ...) only if a 1-iteration no-op run is acceptable","Add an assert all(g > 0 for g in grid if isinstance(g, int)) before dispatch"],"exampleFix":"# before\ngrid=(math.ceil(numel / block), 128)  # numel == 0 -> grid[0] == 0\n# after\nassert numel > 0\ngrid=(math.ceil(numel / block), 128)","handlingStrategy":"validation","validationCode":"assert all(g > 0 for g in grid if isinstance(g, int)), f'non-positive grid: {grid}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard empty inputs before launching the kernel","Add asserts on computed grid sizes at the call site"],"tags":["jax","pallas","grid","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}