{"record":{"id":"64061e63543f6879","repo":"jax-ml/jax","slug":"ragged-dot-general-requires-rhs-group-dimension-nu","errorCode":null,"errorMessage":"ragged_dot_general requires rhs group dimension numbers to be distinct from contracting and batch dimensions.","messagePattern":"ragged_dot_general requires rhs group dimension numbers to be distinct from contracting and batch dimensions\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":6432,"sourceCode":"  # Validate properties of the rhs group dimension(s).\n  rhs_group_dims = ragged_dot_dimension_numbers.rhs_group_dimensions\n  match mode:\n    case RaggedDotMode.RAGGED_CONTRACTING | RaggedDotMode.RAGGED_BATCH:\n      if len(rhs_group_dims) != 0:\n        raise TypeError(\n            'ragged_dot_general requires zero group dimensions in the rhs '\n            'when lhs ragged dimension is contracting or batch.'\n        )\n    case RaggedDotMode.RAGGED_NONCONTRACTING:\n      if len(rhs_group_dims) != 1:\n        raise TypeError(\n            'ragged_dot_general requires exactly one rhs group dimension '\n            'when lhs ragged dimension is noncontracting.'\n        )\n      rhs_group_dim = rhs_group_dims[0]\n      _check_in_range(rhs_group_dim, rhs.ndim, 'rhs group dimension', 'rhs')\n      if rhs_group_dim in rhs_batch or rhs_group_dim in rhs_contracting:\n        raise TypeError(\n            'ragged_dot_general requires rhs group dimension numbers to be '\n            'distinct from contracting and batch dimensions.'\n        )\n      if rhs.shape[rhs_group_dim] != num_groups:\n        raise TypeError(\n            'expected rhs group dimension size to be '\n            f'{num_groups}, got {rhs.shape[rhs_group_dim]}.'\n        )\n\n  out_shape = _dot_general_shape_rule(\n      lhs,\n      rhs,\n      dimension_numbers=ragged_dot_dimension_numbers,\n      precision=precision,\n      preferred_element_type=preferred_element_type,\n      out_sharding=None,\n  )\n  if mode == RaggedDotMode.RAGGED_CONTRACTING:","sourceCodeStart":6414,"sourceCodeEnd":6450,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L6414-L6450","documentation":"The rhs group dimension must be a distinct dimension not also used as a contracting or batch dimension. Reusing the same index in multiple roles makes the dot semantics ambiguous, so JAX rejects it.","triggerScenarios":"Passing RaggedDotDimensionNumbers in RAGGED_NONCONTRACTING mode where rhs_group_dimensions[0] also appears in rhs contracting dimensions or rhs batch dimensions.","commonSituations":"Hand-building dimension-number tuples and accidentally duplicating an index (e.g. contract=(1,), group=(1,)) when adapting a plain dot_general dimension_numbers to the ragged variant.","solutions":["Pick a different index for the rhs group dim that is not in rhs_contracting or rhs_batch","Print/assert your dimension numbers before the call: assert len({*rhs_group, *rhs_contract, *rhs_batch}) == len(rhs_group)+len(rhs_contract)+len(rhs_batch)"],"exampleFix":"// before\ndn = RaggedDotDimensionNumbers((2,),(1,),(0,),(0,),(1,))  // group=1 == contract=1\n// after\ndn = RaggedDotDimensionNumbers((2,),(1,),(0,),(0,),(0,))  // group=0, distinct","handlingStrategy":"validation","validationCode":"used = set(dn.rhs_contracting) | set(dn.rhs_batch)\nassert all(g not in used for g in dn.rhs_group_dimensions)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Uniqueness-check all rhs index lists before the call","Log dimension numbers once at model-build time"],"tags":["jax","ragged-dot","dimension-numbers","shape-validation"],"backgroundTag":"invalid-dimension-configuration","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}