{"record":{"id":"a95c3d9481e56cb6","repo":"jax-ml/jax","slug":"accumulator-ref-must-be-collective-if-collective-a","errorCode":null,"errorMessage":"Accumulator Ref must be collective if collective_axis is set.","messagePattern":"Accumulator Ref must be collective if collective_axis is set\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic_gpu/primitives.py","lineNumber":2579,"sourceCode":"                               collective_axis,\n                               arrive,\n                               scaled,\n                               sparse):\n  del accumulate, acc_transforms_tree, a_transforms_tree, b_transforms_tree, barrier_transforms_tree\n\n  if acc.memory_space != gpu_core.TMEM:\n    raise ValueError(\"Accumulator must be a TMEM Ref.\")\n  if a.memory_space not in (gpu_core.SMEM, gpu_core.TMEM):\n    raise ValueError(\"LHS must be a TMEM/SMEM Ref.\")\n  if b.memory_space != gpu_core.SMEM:\n    raise ValueError(\"RHS must be an SMEM Ref.\")\n\n  if collective_axis is not None:\n    # TODO(justinfu): If under a core_map, the avals for acc/a\n    # become normal MemRefs so we cannot check if they are collective.\n    # Figure out a way to fix this.\n    if isinstance(acc, gpu_core.AbstractTMEMRef) and not acc.collective:\n      raise ValueError(\n          \"Accumulator Ref must be collective if collective_axis is set.\")\n    if isinstance(a, gpu_core.AbstractTMEMRef) and not a.collective:\n      raise ValueError(\n          \"LHS Ref must be collective if collective_axis is set.\")\n\n  scales_and_transforms_leaves = barrier_scales_and_transforms_leaves\n  if arrive:\n    barrier, *scales_and_transforms_leaves = barrier_scales_and_transforms_leaves\n    orders_tensor_core = getattr(\n        barrier.inner_aval.dtype, \"orders_tensor_core\", False)\n    if not orders_tensor_core:\n      raise ValueError(\"MMA barrier must have orders_tensor_core set to True.\")\n  if scaled:\n    a_scale, b_scale = scales_and_transforms_leaves[:2]\n    if a_scale.memory_space != gpu_core.TMEM:\n      raise ValueError(\"a_scale must be a TMEM Ref\")\n    if b_scale.memory_space != gpu_core.TMEM:\n      raise ValueError(\"b_scale must be a TMEM Ref\")","sourceCodeStart":2561,"sourceCodeEnd":2597,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic_gpu/primitives.py#L2561-L2597","documentation":"When collective_axis is passed to tcgen05.mma, the accumulator TMEM ref must itself be marked collective. The check is skipped if the aval has degraded to a plain MemRef (e.g. under core_map).","triggerScenarios":"Calling tcgen05.mma(..., collective_axis=0) with an accumulator that was allocated without the collective TMEM flag.","commonSituations":"Adding collective_axis to an existing kernel but keeping the old TMEM allocation; using a non-collective accumulator allocation helper when switching to 2CTA mode.","solutions":["Allocate the accumulator TMEM ref with the collective flag enabled (see the collective MMA helper/allocate API used by Mosaic GPU examples)","Make the collective setting of the accumulator consistent with collective_axis","If you did not intend 2CTA mode, remove collective_axis"],"exampleFix":"# before\nacc = allocate(TMEM, (m, 2*n), jnp.float32)  # not collective\ntcgen05.mma(a, b, acc, k_dim=k, collective_axis=0)\n# after\nacc = allocate(TMEM, (m, 2*n), jnp.float32, collective=True)\ntcgen05.mma(a, b, acc, k_dim=k, collective_axis=0)","handlingStrategy":"validation","validationCode":"if collective_axis is not None:\n    assert getattr(acc, 'collective', True), 'acc must be collective'","typeGuard":"def acc_collective_ok(acc, collective_axis):\n    return collective_axis is None or getattr(acc, 'collective', False)","tryCatchPattern":null,"preventionTips":["Set the collective flag wherever collective_axis is passed","Encapsulate collective MMA setup in one function"],"tags":["jax","pallas","tcgen05","collective-mma","tmem"],"backgroundTag":"gpu-memory-space-validation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}