jax-ml/jax · error · ValueError
Cannot concatenate non-vector values
Error message
Cannot concatenate non-vector values
What it means
vector_concat only concatenates ir.VectorType values. If vectors[0].type is a scalar (or any non-vector type) the helper cannot determine element type/shape semantics and raises ValueError.
Source
Thrown at jax/experimental/mosaic/gpu/utils.py:2129
[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:
case [v]:
return v
case [v, w]:View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Wrap scalars as vector<1xT> with vector.broadcast before concatenating
- Verify each element's .type is ir.VectorType before the call
- Trace where the list was built and fix producers to emit vectors
Example fix
# before v = vector_concat([a_scalar, b_scalar]) # after one = ir.VectorType.get((1,), a_scalar.type) v = vector_concat([vector.broadcast(one, a_scalar), vector.broadcast(one, b_scalar)])
Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(vectors[0].type, ir.VectorType), 'vector_concat needs vectors'
Type guard
def all_vectors(vals) -> bool:
return all(isinstance(v.type, ir.VectorType) for v in vals) Prevention
- Broadcast scalars to vector<1xT> before concatenating
- Type-check fragment lists at construction
When it happens
Trigger: Calling vector_concat where the first element is a scalar i32/f32, a memref value, or a tensor — e.g. accidentally passing extracted scalars instead of vector<1xT> values.
Common situations: Refactoring that replaced broadcast/scalar insert with raw scalars; passing results of extractelement (scalars) where extract_subvector outputs were expected.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- Unsupported mesh type: {type(mesh)}
- Expected an `NDIndexer`, but got {transforms[0]}
- inline_mgpu_p only supports plgpu.ShapeDtypeStruct return ty
- inline_mgpu_p only supports only SomeLayout and RefType arg
- Cannot concatenate an empty list of vectors
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/c12469ce63af634c.
Report an issue: GitHub.