{"record":{"id":"23ff53bf3222ef1b","repo":"jax-ml/jax","slug":"dot-general-requires-lhs-batch-dimensions-to-be-di-23ff53","errorCode":null,"errorMessage":"dot_general requires lhs batch dimensions to be disjoint from contracting dimensions, got lhs_batch {} and lhs_contracting {}.","messagePattern":"dot_general requires lhs batch dimensions to be disjoint from contracting dimensions, got lhs_batch (.+?) and lhs_contracting (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":5728,"sourceCode":"    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 \"\n           \"shape, got {} and {}.\")\n    raise TypeError(msg.format(lhs_contracting_shape, rhs_contracting_shape))\n\n  return _dot_general_shape_computation(lhs.shape, rhs.shape, dimension_numbers)","sourceCodeStart":5710,"sourceCodeEnd":5746,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L5710-L5746","documentation":"Raised by lax.dot_general validation when the same index appears in both lhs_batch and lhs_contracting for the lhs operand. An axis cannot simultaneously be broadcast (batched) and summed (contracted).","triggerScenarios":"jax.lax.dot_general with dimension_numbers where set(dimension_numbers[0][0]) & set(dimension_numbers[1][0]) is non-empty, e.g. (((1,), ()), ((1,), ())).","commonSituations":"Converting a tensordot/einsum expression to dot_general and reusing an axis index in both roles; ambiguous contraction specs copied from other frameworks.","solutions":["Decide whether the shared lhs axis should batch or contract, and remove it from the other list","Recompute dimension numbers from the intended einsum with jnp.einsum(..., out='opt_einsum') or by inspection of the summation labels"],"exampleFix":"// before\nres = lax.dot_general(x, y, (((1,), (0,)), ((1,), (0,))))  # axis 1 both batched and contracted\n// after: axis 1 is contracting only\nres = lax.dot_general(x, y, (((1,), (0,)), ((), ())))","handlingStrategy":"validation","validationCode":"(lhs_c, _), (lhs_b, _) = dimension_numbers\nassert not (set(lhs_c) & set(lhs_b)), 'axis both batched and contracted on lhs'","typeGuard":"def disjoint_dims(dn):\n    (lc, rc), (lb, rb) = dn\n    return not (set(lc) & set(lb)) and not (set(rc) & set(rb))","tryCatchPattern":null,"preventionTips":["Sketch which axes batch, contract, or stay free before writing tuples"],"tags":["jax","dot-general","dimension-numbers","batch-dims","contraction"],"backgroundTag":"invalid-dimension-numbers","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}