{"record":{"id":"4632133bf57b2067","repo":"jax-ml/jax","slug":"cannot-concatenate-vectors-of-different-element-ty","errorCode":null,"errorMessage":"Cannot concatenate vectors of different element types","messagePattern":"Cannot concatenate vectors of different element types","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/utils.py","lineNumber":2135,"sourceCode":"      [slice_length],\n      [1],\n  )\n\n\ndef vector_concat(\n    vectors: Sequence[ir.Value[ir.VectorType]],\n) -> ir.Value[ir.VectorType]:\n  if not vectors:\n    raise ValueError(\"Cannot concatenate an empty list of vectors\")\n  vty = vectors[0].type\n  if not isinstance(vty, ir.VectorType):\n    raise ValueError(\"Cannot concatenate non-vector values\")\n  vty = ir.VectorType(vty)\n  if vty.rank != 1:\n    raise NotImplementedError(\"Only 1D vectors are supported\")\n  for v in vectors:\n    if v.type.element_type != vty.element_type:\n      raise ValueError(\"Cannot concatenate vectors of different element types\")\n    if v.type.rank != 1:\n      raise ValueError(\"Can only concatenate 1D vectors\")\n  return _vector_concat_rec(vectors)\n\n\ndef _vector_concat_rec(\n    vectors: Sequence[ir.Value[ir.VectorType]],\n) -> ir.Value[ir.VectorType]:\n  match vectors:\n    case [v]:\n      return v\n    case [v, w]:\n      [v_len] = ir.VectorType(v.type).shape\n      [w_len] = ir.VectorType(w.type).shape\n      mask = ir.DenseI64ArrayAttr.get(list(range(v_len + w_len)))\n      return vector.shuffle(*vectors, mask=mask)\n    case _:\n      assert vectors","sourceCodeStart":2117,"sourceCodeEnd":2153,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/utils.py#L2117-L2153","documentation":"vector_concat requires a uniform element type across all operands because the result type is derived from vectors[0]. Any operand whose element type differs raises this ValueError before concatenation.","triggerScenarios":"Calling vector_concat with e.g. [vector<4xf32>, vector<4xbf16>] — mixed f32/bf16 or i32/f32 operands.","commonSituations":"Mixing values from an accumulator (f32) and reloaded weights (bf16) in an epilogue; one pipeline stage inserting an implicit upcast while another does not.","solutions":["Normalize element types first: bitcast if same bitwidth, else arith.extf/truncf/uitofp conversions","Broadcast/convert all operands to the result element type before the concat","Add per-operand asserts on .type.element_type during development"],"exampleFix":"# before\nv = vector_concat([acc_f32, w_bf16])\n# after\nw_f32 = arith.extf(f32, w_bf16)\nv = vector_concat([acc_f32, w_f32])","handlingStrategy":"validation","validationCode":"et = ir.VectorType(vectors[0].type).element_type\nassert all(ir.VectorType(v.type).element_type == et for v in vectors), 'mixed element types'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert all fragments to one element type before concat","Insert explicit casts at dtype boundaries in pipelines"],"tags":["mosaic-gpu","vector-concat","dtype-mismatch"],"backgroundTag":"operand-type-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}