{"record":{"id":"d22910976c2a848b","repo":"jax-ml/jax","slug":"convolution-dimension-numbers-list-tuple-must-be-l","errorCode":null,"errorMessage":"convolution dimension_numbers list/tuple must be length 3, got {}.","messagePattern":"convolution dimension_numbers list/tuple must be length 3, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/convolution.py","lineNumber":974,"sourceCode":"      object.\n\n  Returns:\n    A `ConvDimensionNumbers` object that represents `dimension_numbers` in the\n    canonical form used by lax functions.\n  \"\"\"\n  if isinstance(dimension_numbers, ConvDimensionNumbers):\n    return dimension_numbers\n  if len(lhs_shape) != len(rhs_shape):\n    msg = \"convolution requires lhs and rhs ndim to be equal, got {} and {}.\"\n    raise TypeError(msg.format(len(lhs_shape), len(rhs_shape)))\n\n  if dimension_numbers is None:\n    iota = tuple(range(len(lhs_shape)))\n    return ConvDimensionNumbers(iota, iota, iota)\n  elif isinstance(dimension_numbers, (list, tuple)):\n    if len(dimension_numbers) != 3:\n      msg = \"convolution dimension_numbers list/tuple must be length 3, got {}.\"\n      raise TypeError(msg.format(len(dimension_numbers)))\n    if not all(isinstance(elt, str) for elt in dimension_numbers):\n      msg = \"convolution dimension_numbers elements must be strings, got {}.\"\n      raise TypeError(msg.format(tuple(map(type, dimension_numbers))))\n    msg = (\"convolution dimension_numbers[{}] must have len equal to the ndim \"\n           \"of lhs and rhs, got {} for lhs and rhs shapes {} and {}.\")\n    for i, elt in enumerate(dimension_numbers):\n      if len(elt) != len(lhs_shape):\n        raise TypeError(msg.format(i, len(elt), lhs_shape, rhs_shape))\n\n    lhs_spec, rhs_spec, out_spec = conv_general_permutations(dimension_numbers)\n    return ConvDimensionNumbers(lhs_spec, rhs_spec, out_spec)\n  else:\n    msg = \"convolution dimension_numbers must be tuple/list or None, got {}.\"\n    raise TypeError(msg.format(type(dimension_numbers)))\n\n\ndef conv_general_permutations(dimension_numbers):\n  \"\"\"Utility for convolution dimension permutations relative to Conv HLO.\"\"\"","sourceCodeStart":956,"sourceCodeEnd":992,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/convolution.py#L956-L992","documentation":"When dimension_numbers is given as a list/tuple, it must be a 3-element tuple of strings: (lhs_layout, rhs_layout, out_layout) e.g. ('NCHW','OIHW','NCHW'). Anything with a different length raises this TypeError.","triggerScenarios":"Passing dimension_numbers=('NCHW','OIHW') (missing output spec) or a 4-tuple to lax.conv_general_dilated or lax.conv_dimension_numbers.","commonSituations":"Omitting the output layout assuming it's inferred; copy-paste truncation; passing a ConvDimensionNumbers namedtuple unpacked incorrectly.","solutions":["Provide exactly three layout strings: input, kernel, output","Or pass None to get the default canonical layout","Or pass an already-built ConvDimensionNumbers namedtuple"],"exampleFix":"# before\ndn = lax.conv_dimension_numbers(x.shape, w.shape, ('NCHW', 'OIHW'))\n# after\ndn = lax.conv_dimension_numbers(x.shape, w.shape, ('NCHW', 'OIHW', 'NCHW'))","handlingStrategy":"validation","validationCode":"assert isinstance(dimension_numbers, (tuple, list)) and len(dimension_numbers) == 3, 'need (lhs, rhs, out) layouts'","typeGuard":"def valid_dn_tuple(dn) -> bool:\n    return isinstance(dn, (tuple, list)) and len(dn) == 3 and all(isinstance(s, str) for s in dn)","tryCatchPattern":null,"preventionTips":["Define layout constants once: LAYOUTS = ('NCHW','OIHW','NCHW')","Remember JAX requires the third (output) layout even if it equals the input's"],"tags":["jax","convolution","dimension-numbers","api-misuse"],"backgroundTag":"invalid-argument-format","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}