{"record":{"id":"976b2aeb1b92d498","repo":"jax-ml/jax","slug":"conv-general-dilated-feature-group-count-must-divi","errorCode":null,"errorMessage":"conv_general_dilated feature_group_count must divide lhs feature dimension size, but {} does not divide {}.","messagePattern":"conv_general_dilated feature_group_count must divide lhs feature dimension size, but (.+?) does not divide (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/convolution.py","lineNumber":409,"sourceCode":"def _conv_general_dilated_shape_rule(\n    lhs: core.ShapedArray, rhs: core.ShapedArray, *, window_strides, padding,\n    lhs_dilation, rhs_dilation, dimension_numbers, feature_group_count,\n    batch_group_count, **unused_kwargs) -> tuple[int, ...]:\n  assert type(dimension_numbers) is ConvDimensionNumbers\n  if len(lhs.shape) != len(rhs.shape):\n    msg = (\"conv_general_dilated lhs and rhs must have the same number of \"\n           \"dimensions, but got {} and {}.\")\n    raise ValueError(msg.format(lhs.shape, rhs.shape))\n  if not feature_group_count > 0:\n    msg = (\"conv_general_dilated feature_group_count \"\n           \"must be a positive integer, got {}.\")\n    raise ValueError(msg.format(feature_group_count))\n  lhs_feature_count = lhs.shape[dimension_numbers.lhs_spec[1]]\n  quot, rem = divmod(lhs_feature_count, feature_group_count)\n  if rem:\n    msg = (\"conv_general_dilated feature_group_count must divide lhs feature \"\n           \"dimension size, but {} does not divide {}.\")\n    raise ValueError(msg.format(feature_group_count, lhs_feature_count))\n  if not core.definitely_equal(quot, rhs.shape[dimension_numbers.rhs_spec[1]]):\n    msg = (\"conv_general_dilated lhs feature dimension size divided by \"\n           \"feature_group_count must equal the rhs input feature dimension \"\n           \"size, but {} // {} != {}.\")\n    raise ValueError(msg.format(lhs_feature_count, feature_group_count,\n                                rhs.shape[dimension_numbers.rhs_spec[1]]))\n  if rhs.shape[dimension_numbers.rhs_spec[0]] % feature_group_count:\n    msg = (\"conv_general_dilated rhs output feature dimension size must be a \"\n           \"multiple of feature_group_count, but {} is not a multiple of {}.\")\n    raise ValueError(msg.format(rhs.shape[dimension_numbers.rhs_spec[0]],\n                                feature_group_count))\n\n  if not batch_group_count > 0:\n    msg = (\"conv_general_dilated batch_group_count \"\n           \"must be a positive integer, got {}.\")\n    raise ValueError(msg.format(batch_group_count))\n  lhs_batch_count = lhs.shape[dimension_numbers.lhs_spec[0]]\n  if batch_group_count > 1 and lhs_batch_count % batch_group_count != 0:","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/convolution.py#L391-L427","documentation":"For grouped convolutions, the lhs (input) feature dimension must be divisible by feature_group_count so each group gets an equal slice of input channels. The shape rule divmods lhs feature count by the group count and raises ValueError when a remainder exists.","triggerScenarios":"lax.conv_general_dilated with feature_group_count=4 on an input with 6 input channels (6 % 4 != 0); groups not dividing the number of input channels.","commonSituations":"Porting PyTorch grouped convs with a wrong groups value; changing the channel width of a network (e.g. width multiplier) without updating groups; depthwise conv with feature_group_count != number of input channels.","solutions":["Choose feature_group_count that divides the input channel count (common divisors: 1, 2, in_channels//k)","Adjust the input channels to a multiple of the group count","For depthwise: feature_group_count = in_channels and rhs input-feature dim = 1"],"exampleFix":"// before\nlax.conv_general_dilated(x_c6, k, (1,1), 'SAME', feature_group_count=4)\n// after\nlax.conv_general_dilated(x_c6, k, (1,1), 'SAME', feature_group_count=3)  # 6 % 3 == 0","handlingStrategy":"validation","validationCode":"in_ch = lhs.shape[lhs_spec_feature]\nassert in_ch % feature_group_count == 0, (in_ch, feature_group_count)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose groups among divisors of the input channel count","Re-validate groups whenever changing network width"],"tags":["jax","lax","convolution","feature-group-count"],"backgroundTag":"group-count-not-divisible","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}