{"record":{"id":"5b8fe4f71d82f80d","repo":"jax-ml/jax","slug":"convolution-dimension-numbers-must-be-tuple-list-o","errorCode":null,"errorMessage":"convolution dimension_numbers must be tuple/list or None, got {}.","messagePattern":"convolution dimension_numbers must be tuple/list or None, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/convolution.py","lineNumber":988,"sourceCode":"    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.\"\"\"\n  lhs_spec, rhs_spec, out_spec = dimension_numbers\n  lhs_char, rhs_char, out_char = charpairs = (\"N\", \"C\"), (\"O\", \"I\"), (\"N\", \"C\")\n  for i, (a, b) in enumerate(charpairs):\n    if not dimension_numbers[i].count(a) == dimension_numbers[i].count(b) == 1:\n      msg = (\"convolution dimension_numbers[{}] must contain the characters \"\n             \"'{}' and '{}' exactly once, got {}.\")\n      raise TypeError(msg.format(i, a, b, dimension_numbers[i]))\n    if len(dimension_numbers[i]) != len(set(dimension_numbers[i])):\n      msg = (\"convolution dimension_numbers[{}] cannot have duplicate \"\n             \"characters, got {}.\")\n      raise TypeError(msg.format(i, dimension_numbers[i]))\n  if not (set(lhs_spec) - set(lhs_char) == set(rhs_spec) - set(rhs_char) ==\n          set(out_spec) - set(out_char)):\n    msg = (\"convolution dimension_numbers elements must each have the same \"","sourceCodeStart":970,"sourceCodeEnd":1006,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/convolution.py#L970-L1006","documentation":"conv_dimension_numbers accepts only None, a list/tuple of three strings, or a ConvDimensionNumbers instance. Any other type (dict, int, keyword string) hits the else branch and raises this TypeError with the actual type.","triggerScenarios":"Passing dimension_numbers='NCHW' (a single string), a dict like {'lhs':'NCHW',...}, or an integer enum to lax.conv_general_dilated.","commonSituations":"Guessing the API shape from other libraries; passing an object that used to work with an older custom wrapper.","solutions":["Pass None for the canonical layout, a 3-tuple of strings, or a ConvDimensionNumbers namedtuple","Build the namedtuple via lax.conv_dimension_numbers(None...) or lax.conv_general_permutations once and reuse it"],"exampleFix":"# before\nout = lax.conv_general_dilated(x, w, (1,1), 'SAME', dimension_numbers='NCHW')\n# after\nout = lax.conv_general_dilated(x, w, (1,1), 'SAME', dimension_numbers=('NCHW', 'OIHW', 'NCHW'))","handlingStrategy":"type-guard","validationCode":"assert dimension_numbers is None or isinstance(dimension_numbers, (tuple, list, jax.lax.ConvDimensionNumbers)), type(dimension_numbers)","typeGuard":"from jax._src.lax.convolution import ConvDimensionNumbers\ndef valid_dn(dn) -> bool:\n    return dn is None or isinstance(dn, (tuple, list, ConvDimensionNumbers))","tryCatchPattern":null,"preventionTips":["Pass None when the canonical NCHW/OIHW layout suffices","Keep one helper that builds dimension_numbers and reuse it everywhere"],"tags":["jax","convolution","dimension-numbers","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}