{"record":{"id":"dd770c5daa69f8af","repo":"jax-ml/jax","slug":"convolution-dimension-numbers-elements-must-be-str","errorCode":null,"errorMessage":"convolution dimension_numbers elements must be strings, got {}.","messagePattern":"convolution dimension_numbers elements must be strings, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/convolution.py","lineNumber":977,"sourceCode":"    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.\"\"\"\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):","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/convolution.py#L959-L995","documentation":"Each of the three dimension_numbers elements must be a string (like 'NCHW'). If any element is another type (int, list, None), conv_dimension_numbers raises this TypeError showing the actual types of the tuple elements.","triggerScenarios":"Passing dimension_numbers=(('N','C','H','W'), ('O','I','H','W'), ('N','C','H','W')) (tuples instead of strings), or integer axis permutations.","commonSituations":"Assuming dimension_numbers takes index tuples like other JAX APIs; converting code from string layouts to permutation lists incorrectly.","solutions":["Use layout strings such as ('NCHW', 'OIHW', 'NCHW')","If you have axis permutations, convert them to layout characters first or use the ConvDimensionNumbers namedtuple form via lax.conv_general_permutations output"],"exampleFix":"# before\ndn = lax.conv_dimension_numbers(x.shape, w.shape, ((0,1,2,3), (0,1,2,3), (0,1,2,3)))\n# after\ndn = lax.conv_dimension_numbers(x.shape, w.shape, ('NCHW', 'OIHW', 'NCHW'))","handlingStrategy":"type-guard","validationCode":"assert all(isinstance(elt, str) for elt in dimension_numbers), 'layouts must be strings'","typeGuard":"def are_layout_strings(dn) -> bool:\n    return isinstance(dn, (tuple, list)) and len(dn) == 3 and all(isinstance(e, str) for e in dn)","tryCatchPattern":null,"preventionTips":["Pass layout strings, not index tuples; use ConvDimensionNumbers for permutations"],"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"}