jax-ml/jax · error · ValueError
Cannot concatenate an empty list of vectors
Error message
Cannot concatenate an empty list of vectors
What it means
vector_concat builds a result by recursively concatenating, starting from vectors[0]; an empty sequence has no element type or length to anchor on, so it raises rather than returning an undefined value.
Source
Thrown at jax/experimental/mosaic/gpu/utils.py:2126
v_ty = ir.VectorType(v.type)
if len(v_ty.shape) != 1:
raise NotImplementedError(f"Only 1D vectors are supported {v_ty}")
[v_len] = v_ty.shape
slice_length = len(range(v_len)[s])
return vector.extract_strided_slice(
ir.VectorType.get((slice_length,), v_ty.element_type),
v,
[s.start or 0],
[slice_length],
[1],
)
def vector_concat(
vectors: Sequence[ir.Value[ir.VectorType]],
) -> ir.Value[ir.VectorType]:
if not vectors:
raise ValueError("Cannot concatenate an empty list of vectors")
vty = vectors[0].type
if not isinstance(vty, ir.VectorType):
raise ValueError("Cannot concatenate non-vector values")
vty = ir.VectorType(vty)
if vty.rank != 1:
raise NotImplementedError("Only 1D vectors are supported")
for v in vectors:
if v.type.element_type != vty.element_type:
raise ValueError("Cannot concatenate vectors of different element types")
if v.type.rank != 1:
raise ValueError("Can only concatenate 1D vectors")
return _vector_concat_rec(vectors)
def _vector_concat_rec(
vectors: Sequence[ir.Value[ir.VectorType]],
) -> ir.Value[ir.VectorType]:
match vectors:View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Guard the call site: skip concatenation or return an undef/zero vector when the list is empty
- Fix the loop/range producing the list so it yields at least one fragment
- Pad the sequence dimension so fragment lists are never empty
Example fix
# before out = vector_concat(parts) # parts == [] # after out = vector_concat(parts) if parts else llvm.mlir_undef(ir.VectorType.get((0,), f32))
Defensive patterns
Strategy: validation
Validate before calling
assert vectors, 'vector_concat received empty list' result = vector_concat(vectors)
Prevention
- Guard loops producing fragment lists with `if parts:`
- Debug empty trip counts before building vectors
When it happens
Trigger: Calling vector_concat([]) — usually because a list comprehension over blocks/fragments produced zero elements (empty range, empty tile list, filtered-out everything).
Common situations: Concatenating per-iteration partial vectors inside a loop whose trip count is 0 (e.g. zero-length sequence dimension); dynamic shapes producing empty fragments at runtime; off-by-one slice producing an empty list.
Related errors
- Need at least one array to concatenate
- Cannot concatenate non-vector values
- Cannot concatenate vectors of different element types
- Can only concatenate 1D vectors
- concatenate expects at least one operand, got 0.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/4c4b728412c100eb.
Report an issue: GitHub.