{"record":{"id":"48f1480482f3bbe2","repo":"huggingface/candle","slug":"in-channel-c-in-is-not-divisible-by-the-number-o","errorCode":null,"errorMessage":"in_channel {c_in} is not divisible by the number of groups","messagePattern":"in_channel (.+?) is not divisible by the number of groups","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/conv.rs","lineNumber":246,"sourceCode":"    }\n\n    /// Applies a 1D transposed convolution over the input tensor.\n    pub fn conv_transpose1d(\n        &self,\n        kernel: &Self,\n        padding: usize,\n        output_padding: usize,\n        stride: usize,\n        dilation: usize,\n        groups: usize,\n    ) -> Result<Self> {\n        let (c_in_k, c_out, k_size) = kernel.dims3()?;\n        let (b_size, c_in, l_in) = self.dims3()?;\n        if c_in != c_in_k {\n            crate::bail!(\"in_channel mismatch between input ({c_in}) and kernel ({c_in_k})\")\n        }\n        if c_in % groups != 0 {\n            crate::bail!(\"in_channel {c_in} is not divisible by the number of groups\")\n        }\n        let params = ParamsConvTranspose1D {\n            b_size,\n            l_in,\n            k_size,\n            c_out,\n            c_in: c_in / groups,\n            padding,\n            output_padding,\n            stride,\n            dilation,\n        };\n        if groups == 1 {\n            self.conv_transpose1d_single_group(kernel, &params)\n        } else {\n            let blocks = self.chunk(groups, 1)?;\n            let kernel = kernel.chunk(groups, 0)?;\n            let blocks = blocks","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/conv.rs#L228-L264","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pick a group count that divides c_in evenly (1, 2, 4, or groups == c_in for depthwise).","Adjust the input channel count (or layer config) so groups divides it.","Set groups = 1 if grouped convolution was not intended.","For depthwise transposed conv, ensure groups == c_in and kernel has c_in_k == c_in."],"exampleFix":"// before: c_in = 6, groups = 4\nx.conv_transpose1d(&k, 0, 0, 1, 1, 4)?;\n// after: groups must divide 6\nx.conv_transpose1d(&k, 0, 0, 1, 1, 3)?;","handlingStrategy":"validation","validationCode":"let (_b, c_in, _l) = x.dims3()?;\nif c_in % groups != 0 { return Err(anyhow::anyhow!(\"conv_transpose1d: channels {c_in} not divisible by groups {groups}\")); }","typeGuard":null,"tryCatchPattern":"match result { Err(e) if e.to_string().contains(\"divisible by the number of groups\") => { // retry with groups=1\n}, other => other?, }","preventionTips":["Derive groups from the tensor (groups = c_in for depthwise) rather than a fixed constant.","Assert config invariants (c_in % groups == 0) when constructing the model.","Only use group counts that are powers of two dividing the channel width."],"tags":["shape-mismatch","convolution","groups","rust"],"backgroundTag":"group-count-mismatch","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}