{"record":{"id":"47ee0460a6c9141c","repo":"jax-ml/jax","slug":"dot-general-requires-rhs-contracting-dimensions-to","errorCode":null,"errorMessage":"dot_general requires rhs contracting dimensions to be distinct, got rhs_contracting {rhs_contracting}.","messagePattern":"dot_general requires rhs contracting dimensions to be distinct, got rhs_contracting (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":5724,"sourceCode":"    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)\n  if not core.definitely_equal_shape(lhs_batch_shape, rhs_batch_shape):\n    msg = (\"dot_general requires lhs batch dimensions and rhs batch dimensions \"\n           \"to have the same shape, got {} and {}.\")\n    raise TypeError(msg.format(lhs_batch_shape, rhs_batch_shape))\n  lhs_contracting_shape = tuple(lhs.shape[i] for i in lhs_contracting)\n  rhs_contracting_shape = tuple(rhs.shape[i] for i in rhs_contracting)\n  if not core.definitely_equal_shape(lhs_contracting_shape, rhs_contracting_shape):\n    msg = (\"dot_general requires contracting dimensions to have the same \"","sourceCodeStart":5706,"sourceCodeEnd":5742,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L5706-L5742","documentation":"Raised by lax.dot_general validation when rhs_contracting contains duplicate indices. Each rhs contracting dimension must be distinct since each pairs with exactly one lhs contracting dimension for the sum.","triggerScenarios":"jax.lax.dot_general with dimension_numbers[0][1] containing repeats, e.g. (((0, 0), (1, 1)), ((), ())).","commonSituations":"Hand-written transposition rules, custom_jvp/vjp rules, or ported XLA configs where the rhs contracting tuple was copy-pasted and edited incorrectly.","solutions":["Deduplicate rhs_contracting so each rhs axis appears once","Ensure the pairing (lhs_contracting[i], rhs_contracting[i]) is what you intend","Use jnp.einsum/jnp.tensordot for complex contractions"],"exampleFix":"// before\nres = lax.dot_general(x, y, (((0, 0), (1, 1)), ((), ())))\n// after\nres = lax.dot_general(x, y, (((0, 0), (1, 2)), ((), ())))","handlingStrategy":"validation","validationCode":"rhs_c = dimension_numbers[0][1]\nassert len(set(rhs_c)) == len(rhs_c), 'duplicate rhs contracting dims'","typeGuard":"def valid_contracting(dn):\n    (lc, rc), _ = dn\n    return all(len(set(x)) == len(x) for x in (lc, rc))","tryCatchPattern":null,"preventionTips":["Keep lhs/rhs tuples symmetric when editing; test with tiny arrays"],"tags":["jax","dot-general","dimension-numbers","contraction"],"backgroundTag":"invalid-dimension-numbers","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}