jax-ml/jax · error · ValueError
Unsupported range type
Error message
Unsupported range type: {type(r)}. What it means
Guard in is_range_out_of_bounds_for_shape: bounds checks accept ints or slices; any other range object (e.g. an array or arbitrary index expression) has no bounds-check implementation and raises ValueError with the offending type.
Solutions
- Normalize the index: expand ellipsis/None and convert to int/slice tuples before writing
- Use _normalize_range-style helpers on the range before indexing
- Convert numpy scalars to Python ints
Example fix
// before smem[None, 0:16] = v // after smem[0:1, 0:16] = v
Defensive patterns
Strategy: type-guard
Type guard
def is_supported_range(rnge):
return all(isinstance(r, (int, slice)) for r in rnge) Prevention
- Normalize indexes (expand ellipsis, drop None, convert numpy ints) before writing to interpret Buffers
- Only use int/slice tuples for shared-memory writes
When it happens
Trigger: Calling Buffer.__setitem__ (or the util directly) with a range tuple containing None/ellipsis/numpy arrays instead of ints or slices.
Common situations: Passing raw numpy-style indexing (e.g. [None, :] or [...]) into interpret-mode shared memory writes; converting slices lazily so None sneaks through.
Related errors
- Acc ref must be at least 2D, got shape
- Attempting to deallocate allocation with key
- Attempting to get contents of allocation with key
- Attempting to store into allocation with key
- Attempting to swap into allocation with `key
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/7e332d60fa20f49f.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/pallas/mosaic/interpret/utils.py:362
assert 0 <= r
if r >= d:
return True
elif isinstance(r, slice):
assert r.start is not None and 0 <= r.start
assert r.stop is not None and 0 <= r.stop
if r.step is None:
if r.stop > d:
return True
else:
assert 0 <= r.step
num_elements_in_slice = (r.stop - r.start + r.step - 1) // r.step
if num_elements_in_slice > 0:
last_index = r.start + (num_elements_in_slice - 1) * r.step
if last_index >= d:
return True
else:
raise ValueError(f"Unsupported range type: {type(r)}.")
return False
def clip_range_to_shape(
rnge: tuple[slice | int, ...], shape: tuple[int, ...]
) -> tuple[slice | int, ...] | None:
"""Clips `slice`s in `rnge` to the `shape`. Returns None if `rnge` is entirely out of bounds."""
result: list[slice | int] = []
for r, l in zip(rnge, shape, strict=True):
if isinstance(r, int):
if r >= l:
return None
result.append(r)
elif isinstance(r, slice):
if r.start >= l:
return None
result.append(slice(r.start, min(r.stop, l), r.step))
else:View on GitHub (pinned to 1e1c6a8fc0)