{"record":{"id":"ba9f2137180b2be5","repo":"jax-ml/jax","slug":"string-padding-is-not-implemented-for-transposed-c","errorCode":null,"errorMessage":"String padding is not implemented for transposed convolution using this op. Please either exactly specify the required padding or use conv_transpose.","messagePattern":"String padding is not implemented for transposed convolution using this op\\. Please either exactly specify the required padding or use conv_transpose\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/convolution.py","lineNumber":151,"sourceCode":"  For example, to indicate dimension numbers consistent with the ``conv``\n  function with two spatial dimensions, one could use ``('NCHW', 'OIHW',\n  'NCHW')``. As another example, to indicate dimension numbers consistent with\n  the TensorFlow Conv2D operation, one could use ``('NHWC', 'HWIO', 'NHWC')``.\n  When using the latter form of convolution dimension specification, window\n  strides are associated with spatial dimension character labels according to\n  the order in which the labels appear in the ``rhs_spec`` string, so that\n  ``window_strides[0]`` is matched with the dimension corresponding to the first\n  character appearing in rhs_spec that is not ``'I'`` or ``'O'``.\n\n  If ``dimension_numbers`` is ``None``, the default is ``('NCHW', 'OIHW',\n  'NCHW')`` (for a 2D convolution).\n  \"\"\"\n  dnums = conv_dimension_numbers(lhs.shape, rhs.shape, dimension_numbers)\n  out_sharding = canonicalize_sharding(out_sharding, 'dot_general')\n  if lhs_dilation is None:\n    lhs_dilation = (1,) * (lhs.ndim - 2)\n  elif isinstance(padding, str) and not len(lhs_dilation) == lhs_dilation.count(1):\n    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(","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/convolution.py#L133-L169","documentation":"conv_general_dilated cannot compute automatic padding ('SAME'/'VALID') for a transposed convolution, which is what lhs_dilation != all-ones implies. If string padding is combined with non-unit lhs_dilation the op raises ValueError and directs you to conv_transpose, which handles padding computation for transposed convolutions.","triggerScenarios":"Calling lax.conv_general_dilated(lhs, rhs, strides, 'SAME', lhs_dilation=(2,2)) directly; indirectly by calling lax.conv_transpose with a non-default padding is fine, but hand-rolled transposed convs through conv_general_dilated with string padding hit this.","commonSituations":"Manually implementing transposed conv / upsampling via dilation instead of using lax.conv_transpose; porting PyTorch ConvTranspose2d semantics to JAX by hand.","solutions":["Use lax.conv_transpose, which computes correct transposed-conv padding for 'SAME'/'VALID'","Specify explicit padding as a list of (low, high) pairs instead of a string"],"exampleFix":"// before\nout = lax.conv_general_dilated(x, k, strides=(2,2), padding='SAME', lhs_dilation=(2,2))\n// after\nout = lax.conv_transpose(x, k, strides=(2,2), padding='SAME')","handlingStrategy":"fallback","validationCode":"if isinstance(padding, str) and any(d != 1 for d in (lhs_dilation or (1,)*(lhs.ndim-2))):\n    use_conv_transpose = True  # switch API","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use lax.conv_transpose for transposed convolutions","Pass explicit (low, high) pairs with dilation"],"tags":["jax","lax","convolution","transposed-conv","padding"],"backgroundTag":"invalid-padding-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}