{"record":{"id":"0f9ddbc0f045ada4","repo":"jax-ml/jax","slug":"inconsistent-size-for-name-dim-sizes-name-vs","errorCode":null,"errorMessage":"Inconsistent size for {name}: {dim_sizes[name]} vs {shape_val}","messagePattern":"Inconsistent size for (.+?): (.+?) vs (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/einshape.py","lineNumber":179,"sourceCode":"  lhs_str, rhs_str = equation.split(\"->\")\n  return _parse_side(lhs_str), _parse_side(rhs_str)\n\n\ndef _get_einshape_dims(\n    parsed_side: list[list[str]],\n    shape: tuple[int, ...],\n    sizes: dict[str, int],\n) -> dict[str, int]:\n  \"\"\"Parses an einshape equation into a dictionary of dimension sizes.\"\"\"\n  dim_sizes: dict[str, int] = {}\n\n  # Populate known sizes from input\n  for i, group in enumerate(parsed_side):\n    shape_val = shape[i]\n    if len(group) == 1:\n      name = group[0]\n      if name in dim_sizes and dim_sizes[name] != shape_val:\n        raise ValueError(\n            f\"Inconsistent size for {name}: {dim_sizes[name]} vs {shape_val}\"\n        )\n      dim_sizes[name] = shape_val\n    else:\n      # We have a merged dimension on LHS, need to split\n      known_product = 1\n      unknown_dims = []\n      for name in group:\n        if name in sizes:\n          dim_sizes[name] = sizes[name]\n          known_product *= sizes[name]\n        elif name in dim_sizes:\n          known_product *= dim_sizes[name]\n        else:\n          unknown_dims.append(name)\n\n      if not unknown_dims:\n        if known_product != shape_val:","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/einshape.py#L161-L197","documentation":"einshape binds each named dimension (letter) to a size from the input shape. If the same name appears in multiple positions whose sizes differ (e.g. 'aa' with shape (4, 8)), the binding is contradictory and _get_einshape_dims raises ValueError showing the conflicting sizes. Repeated letters act like einsum labels: they must all have the same extent.","triggerScenarios":"Passing an equation whose LHS repeats a dimension letter with inconsistent extents, e.g. get_einshape_transforms('aa -> a', shape=(4, 8)); or a merged group like '(ab)a' where 'a' also appears standalone with a different size.","commonSituations":"Using repeated letters merely as placeholders instead of einsum-style equality constraints; input arrays whose axis sizes changed after refactoring while the equation stayed fixed; transposing code from reshape where letters carried no meaning.","solutions":["Fix the equation so each repeated letter corresponds to axes of equal size, or use distinct letters for unrelated axes","Verify the input shape matches the equation's LHS structure before calling einshape","If merging/splitting dims, use parenthesized groups with correct products instead of repeated letters"],"exampleFix":"# before\nt = get_einshape_transforms('aa -> a', x.shape)  # x.shape == (4, 8)\n\n# after\nt = get_einshape_transforms('ab -> ab', x.shape)  # distinct names for distinct sizes","handlingStrategy":"validation","validationCode":"def dims_consistent(parsed_side, shape):\n    sizes = {}\n    for group, size in zip(parsed_side, shape):\n        if len(group) == 1 and group[0] in sizes:\n            if sizes[group[0]] != size:\n                return False\n        elif len(group) == 1:\n            sizes[group[0]] = size\n    return True","typeGuard":"def letter_sizes_consistent(lhs_groups: list[list[str]], shape: tuple) -> bool:\n    seen = {}\n    for g, s in zip(lhs_groups, shape):\n        if len(g) == 1:\n            if g[0] in seen and seen[g[0]] != s:\n                return False\n            seen[g[0]] = s\n    return True","tryCatchPattern":"try:\n    t = get_einshape_transforms(eq, shape)\nexcept ValueError as e:\n    if 'Inconsistent size' in str(e):\n        raise ValueError(f'equation {eq!r} reuses a letter for axes of different size in shape {shape}') from None\n    raise","preventionTips":["Treat repeated letters as equality constraints; use unique letters for independent axes","Assert input shape matches the equation's implied structure before calling","Regenerate equations when tensor layouts change instead of reusing constants"],"tags":["jax","einshape","einsum-notation","dimension-mismatch","shape-validation"],"backgroundTag":"einsum-dimension-size-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}