{"record":{"id":"70880d4d08274b1d","repo":"jax-ml/jax","slug":"dot-general-requires-rhs-batch-dimensions-to-be-di","errorCode":null,"errorMessage":"dot_general requires rhs batch dimensions to be distinct, got rhs_batch {rhs_batch}.","messagePattern":"dot_general requires rhs batch dimensions to be distinct, got rhs_batch (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":5716,"sourceCode":"    msg = (\"dot_general requires rhs dimension numbers to be nonnegative and \"\n           \"less than the number of axes of the rhs value, got \"\n           f\"rhs_batch of {rhs_batch} and rhs_contracting of {rhs_contracting} \"\n           f\"for rhs of rank {rhs.ndim}\")\n    raise TypeError(msg)\n  if len(lhs_batch) != len(rhs_batch):\n    msg = (\"dot_general requires equal numbers of lhs_batch and rhs_batch \"\n           \"dimensions, got lhs_batch {} and rhs_batch {}.\")\n    raise TypeError(msg.format(lhs_batch, rhs_batch))\n  lhs_contracting_set, lhs_batch_set = set(lhs_contracting), set(lhs_batch)\n  rhs_contracting_set, rhs_batch_set = set(rhs_contracting), set(rhs_batch)\n  if len(lhs_batch_set) != len(lhs_batch):\n    msg = (\"dot_general requires lhs batch dimensions to be distinct, got \"\n           f\"lhs_batch {lhs_batch}.\")\n    raise TypeError(msg)\n  if len(rhs_batch_set) != len(rhs_batch):\n    msg = (\"dot_general requires rhs batch dimensions to be distinct, got \"\n           f\"rhs_batch {rhs_batch}.\")\n    raise TypeError(msg)\n  if len(lhs_contracting_set) != len(lhs_contracting):\n    msg = (\"dot_general requires lhs contracting dimensions to be distinct, \"\n           f\"got lhs_contracting {lhs_contracting}.\")\n    raise TypeError(msg)\n  if len(rhs_contracting_set) != len(rhs_contracting):\n    msg = (\"dot_general requires rhs contracting dimensions to be distinct, \"\n           f\"got rhs_contracting {rhs_contracting}.\")\n    raise TypeError(msg)\n  if lhs_contracting_set & lhs_batch_set:\n    msg = (\"dot_general requires lhs batch dimensions to be disjoint from \"\n           \"contracting dimensions, got lhs_batch {} and lhs_contracting {}.\")\n    raise TypeError(msg.format(lhs_batch, lhs_contracting))\n  if rhs_contracting_set & rhs_batch_set:\n    msg = (\"dot_general requires rhs batch dimensions to be disjoint from \"\n           \"contracting dimensions, got rhs_batch {} and rhs_contracting {}.\")\n    raise TypeError(msg.format(rhs_batch, rhs_contracting))\n  lhs_batch_shape = tuple(lhs.shape[i] for i in lhs_batch)\n  rhs_batch_shape = tuple(rhs.shape[i] for i in rhs_batch)","sourceCodeStart":5698,"sourceCodeEnd":5734,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L5698-L5734","documentation":"Raised by lax.dot_general validation when the rhs_batch sequence contains duplicate dimension indices. Each rhs batch dimension must be distinct so it pairs one-to-one with a distinct lhs batch dimension.","triggerScenarios":"jax.lax.dot_general with dimension_numbers where dimension_numbers[1][1] (rhs batch dims) has repeats, e.g. (((), ()), ((0, 1), (2, 2))).","commonSituations":"Manually writing batch dimension tuples for custom vmap/jit rules or porting HLO DotDimensionNumbers; mismatched tuple lengths paired with duplicated indices.","solutions":["Deduplicate rhs_batch entries; each rhs batch axis may be listed only once","Cross-check that len(lhs_batch) == len(rhs_batch) and indices align pairwise","Use jnp.einsum or vmap(matmul) instead of hand-written dimension numbers"],"exampleFix":"// before\nres = lax.dot_general(x, y, (((), ()), ((0, 1), (1, 1))))\n// after\nres = lax.dot_general(x, y, (((), ()), ((0, 1), (0, 1))))","handlingStrategy":"validation","validationCode":"rhs_batch = dimension_numbers[1][1]\nassert len(set(rhs_batch)) == len(rhs_batch), 'duplicate rhs batch dims'","typeGuard":"def valid_batch_dims(dn):\n    (lc, rc), (lb, rb) = dn\n    return all(len(set(x)) == len(x) for x in (lb, rb))","tryCatchPattern":null,"preventionTips":["Unit-test helper that generates dimension_numbers","Mirror lhs/rhs tuples structurally when editing"],"tags":["jax","dot-general","dimension-numbers","batch-dims"],"backgroundTag":"invalid-dimension-numbers","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}