huggingface/candle · error

in_channel {c_in} is not divisible by the number of groups

Error message

in_channel {c_in} is not divisible by the number of groups

What it means

conv_transpose1d requires the input channel count to be divisible by the number of groups for grouped transposed convolutions. Grouped convolutions split channels evenly among groups; a non-divisible c_in would leave an uneven partition, so candle rejects it.

Source

Thrown at candle-core/src/conv.rs:246

    }

    /// Applies a 1D transposed convolution over the input tensor.
    pub fn conv_transpose1d(
        &self,
        kernel: &Self,
        padding: usize,
        output_padding: usize,
        stride: usize,
        dilation: usize,
        groups: usize,
    ) -> Result<Self> {
        let (c_in_k, c_out, k_size) = kernel.dims3()?;
        let (b_size, c_in, l_in) = self.dims3()?;
        if c_in != c_in_k {
            crate::bail!("in_channel mismatch between input ({c_in}) and kernel ({c_in_k})")
        }
        if c_in % groups != 0 {
            crate::bail!("in_channel {c_in} is not divisible by the number of groups")
        }
        let params = ParamsConvTranspose1D {
            b_size,
            l_in,
            k_size,
            c_out,
            c_in: c_in / groups,
            padding,
            output_padding,
            stride,
            dilation,
        };
        if groups == 1 {
            self.conv_transpose1d_single_group(kernel, &params)
        } else {
            let blocks = self.chunk(groups, 1)?;
            let kernel = kernel.chunk(groups, 0)?;
            let blocks = blocks

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Pick a group count that divides c_in evenly (1, 2, 4, or groups == c_in for depthwise).
  2. Adjust the input channel count (or layer config) so groups divides it.
  3. Set groups = 1 if grouped convolution was not intended.
  4. For depthwise transposed conv, ensure groups == c_in and kernel has c_in_k == c_in.

Example fix

// before: c_in = 6, groups = 4
x.conv_transpose1d(&k, 0, 0, 1, 1, 4)?;
// after: groups must divide 6
x.conv_transpose1d(&k, 0, 0, 1, 1, 3)?;
Defensive patterns

Strategy: validation

Validate before calling

let (_b, c_in, _l) = x.dims3()?;
if c_in % groups != 0 { return Err(anyhow::anyhow!("conv_transpose1d: channels {c_in} not divisible by groups {groups}")); }

Try / catch

match result { Err(e) if e.to_string().contains("divisible by the number of groups") => { // retry with groups=1
}, other => other?, }

Prevention

When it happens

Trigger: Tensor::conv_transpose1d(&kernel, pad, output_padding, stride, dilation, groups) with c_in % groups != 0, e.g. input with 6 channels and groups=4, or groups set from a misread config.

Common situations: Depthwise configs (groups = c_in) applied with a mismatched channel count; porting MobileNet-style models where c_in changed after an edit; passing groups=3 for c_in=4.

Related errors


AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02). Data as JSON: /api/errors/48f1480482f3bbe2. Report an issue: GitHub.