{"record":{"id":"6c4e57f85bd2c28d","repo":"jax-ml/jax","slug":"padding-argument-to-conv-general-dilated-should-be","errorCode":null,"errorMessage":"padding argument to conv_general_dilated should be a string or a sequence of (low, high) pairs, got {padding}","messagePattern":"padding argument to conv_general_dilated should be a string or a sequence of \\(low, high\\) pairs, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/convolution.py","lineNumber":169,"sourceCode":"    raise ValueError(\n        \"String padding is not implemented for transposed convolution \"\n        \"using this op. Please either exactly specify the required padding or \"\n        \"use conv_transpose.\")\n  if rhs_dilation is None:\n    rhs_dilation = (1,) * (rhs.ndim - 2)\n  if isinstance(padding, str):\n    lhs_perm, rhs_perm, _ = dnums\n    rhs_shape = np.take(rhs.shape, rhs_perm)[2:]\n    effective_rhs_shape = [core.dilate_dim(k, r) for k, r in zip(rhs_shape, rhs_dilation)]\n    padding = lax.padtype_to_pads(\n        np.take(lhs.shape, lhs_perm)[2:], effective_rhs_shape,\n        window_strides, padding)\n  else:\n    try:\n      padding = tuple((operator.index(lo), operator.index(hi))\n                      for lo, hi in padding)\n    except (ValueError, TypeError) as e:\n      raise ValueError(\n        \"padding argument to conv_general_dilated should be a string or a \"\n        f\"sequence of (low, high) pairs, got {padding}\") from e\n\n  preferred_element_type = (\n      None if preferred_element_type is None\n      else dtypes.check_and_canonicalize_user_dtype(\n          preferred_element_type, \"conv_general_dilated\"\n      )\n  )\n  lhs, rhs = core.auto_insert_reshard(lhs, rhs)\n  return conv_general_dilated_p.bind(\n      lhs, rhs, window_strides=tuple(window_strides), padding=tuple(padding),\n      lhs_dilation=tuple(lhs_dilation), rhs_dilation=tuple(rhs_dilation),\n      dimension_numbers=dnums,\n      feature_group_count=feature_group_count,\n      batch_group_count=batch_group_count,\n      precision=lax.canonicalize_precision(precision),\n      preferred_element_type=preferred_element_type,","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/convolution.py#L151-L187","documentation":"conv_general_dilated's padding parameter must be either a string ('SAME'/'VALID') or a sequence of integer (low, high) pairs, one per spatial dimension. The code coerces each entry with operator.index over a two-element unpack; anything else (nested strings, floats, three-element tuples, non-iterables) re-raises as ValueError.","triggerScenarios":"Passing padding=[(1,1),(1,1.5)], [(0,0,0)], padding=1, or a malformed nested list to lax.conv_general_dilated; also generators that don't yield exactly two ints.","commonSituations":"Building padding programmatically and producing floats or single ints; converting from frameworks that express padding as a single number (torch nn.Conv2d padding=1) without expanding it to per-dim pairs.","solutions":["Pass explicit pairs of Python ints: [(1, 1), (1, 1)]","Convert torch-style padding: [(p, p) for p in (padding,)*num_spatial_dims]","Use 'SAME' or 'VALID' if you don't need custom padding"],"exampleFix":"// before\nlax.conv_general_dilated(x, k, (1,1), padding=1)\n// after\nlax.conv_general_dilated(x, k, (1,1), padding=[(1,1), (1,1)])","handlingStrategy":"validation","validationCode":"if not isinstance(padding, str):\n    padding = [(int(lo), int(hi)) for lo, hi in padding]\n    assert all(isinstance(p, tuple) and len(p) == 2 for p in padding)","typeGuard":"def is_valid_padding(p) -> bool:\n    if isinstance(p, str): return p in ('SAME', 'VALID')\n    try:\n        return all(isinstance(lo, int) and isinstance(hi, int) for lo, hi in p)\n    except Exception:\n        return False","tryCatchPattern":null,"preventionTips":["Normalize padding to int pairs at config boundaries","Expand single-number padding to per-dim pairs when porting from torch"],"tags":["jax","lax","convolution","padding"],"backgroundTag":"invalid-padding-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}