jax-ml/jax · error · ValueError

conv_general_dilated feature_group_count must be a positive

Error message

conv_general_dilated feature_group_count must be a positive integer, got {}.

What it means

feature_group_count in conv_general_dilated controls grouped convolutions (like PyTorch's groups) and must be a positive integer. The shape rule checks `feature_group_count > 0` and raises ValueError otherwise, e.g. when 0 or a negative value slips in.

Source

Thrown at jax/_src/lax/convolution.py:403

    rhs = rhs.swapaxes(dn.rhs_spec[0], dn.rhs_spec[1])
  return conv_general_dilated(lhs, rhs, one, pads, strides, rhs_dilation, dn,
                              precision=precision,
                              preferred_element_type=preferred_element_type)


def _conv_general_dilated_shape_rule(
    lhs: core.ShapedArray, rhs: core.ShapedArray, *, window_strides, padding,
    lhs_dilation, rhs_dilation, dimension_numbers, feature_group_count,
    batch_group_count, **unused_kwargs) -> tuple[int, ...]:
  assert type(dimension_numbers) is ConvDimensionNumbers
  if len(lhs.shape) != len(rhs.shape):
    msg = ("conv_general_dilated lhs and rhs must have the same number of "
           "dimensions, but got {} and {}.")
    raise ValueError(msg.format(lhs.shape, rhs.shape))
  if not feature_group_count > 0:
    msg = ("conv_general_dilated feature_group_count "
           "must be a positive integer, got {}.")
    raise ValueError(msg.format(feature_group_count))
  lhs_feature_count = lhs.shape[dimension_numbers.lhs_spec[1]]
  quot, rem = divmod(lhs_feature_count, feature_group_count)
  if rem:
    msg = ("conv_general_dilated feature_group_count must divide lhs feature "
           "dimension size, but {} does not divide {}.")
    raise ValueError(msg.format(feature_group_count, lhs_feature_count))
  if not core.definitely_equal(quot, rhs.shape[dimension_numbers.rhs_spec[1]]):
    msg = ("conv_general_dilated lhs feature dimension size divided by "
           "feature_group_count must equal the rhs input feature dimension "
           "size, but {} // {} != {}.")
    raise ValueError(msg.format(lhs_feature_count, feature_group_count,
                                rhs.shape[dimension_numbers.rhs_spec[1]]))
  if rhs.shape[dimension_numbers.rhs_spec[0]] % feature_group_count:
    msg = ("conv_general_dilated rhs output feature dimension size must be a "
           "multiple of feature_group_count, but {} is not a multiple of {}.")
    raise ValueError(msg.format(rhs.shape[dimension_numbers.rhs_spec[0]],
                                feature_group_count))

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Set feature_group_count to a positive int (1 for standard conv, in_channels for depthwise)
  2. Compute as max(1, groups) if derived from user input
  3. For depthwise conv, set feature_group_count equal to input channels and rhs feature dims accordingly

Example fix

// before
lax.conv_general_dilated(x, k, (1,1), 'SAME', feature_group_count=groups-1)
// after
lax.conv_general_dilated(x, k, (1,1), 'SAME', feature_group_count=max(1, groups))
Defensive patterns

Strategy: validation

Validate before calling

assert feature_group_count > 0, feature_group_count

Prevention

When it happens

Trigger: Calling lax.conv_general_dilated(..., feature_group_count=0) or passing a computed group count that evaluates to 0 (e.g. groups - 1, or integer division that yields 0).

Common situations: Translating PyTorch Conv2d(groups=N) to lax and computing feature_group_count incorrectly; using DepthwiseConv-like configs where groups=0 instead of groups=in_channels.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/3d7381a51910a6e1. Report an issue: GitHub.