{"record":{"id":"17d9777a601872ba","repo":"huggingface/candle","slug":"in-channel-mismatch-between-input-c-in-and-ker","errorCode":null,"errorMessage":"in_channel mismatch between input ({c_in}) and kernel ({c_in_k})","messagePattern":"in_channel mismatch between input \\((.+?)\\) and kernel \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/conv.rs","lineNumber":243,"sourceCode":"        });\n        let out_dims = params.out_dims();\n        Ok(crate::tensor::from_storage(storage, out_dims, op, false))\n    }\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 {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/conv.rs#L225-L261","documentation":"conv_transpose1d validates that the input tensor's channel count (c_in) equals the kernel's input-channel dimension (first dim of the 3D kernel). For transposed convolution the kernel is stored as (c_in, c_out, k_size), so a mismatch means the weight tensor does not correspond to the actual input channels.","triggerScenarios":"Calling Tensor::conv_transpose1d(&kernel, pad, output_padding, stride, dilation, groups) where kernel.dims3() yields c_in_k != self's dim(1), e.g. input (B, 3, L) with kernel of shape (64, 128, 3).","commonSituations":"Building ConvTranspose1d layers with wrong in_channels/out_channels ordering (transposed conv kernels are (in, out, k), the reverse of regular conv); loading weights from a checkpoint whose layer config changed; misusing a regular conv kernel for a transposed conv.","solutions":["Swap the kernel to shape (c_in, c_out, k_size) — transposed conv expects input channels first.","Update the ConvTranspose1d layer config (in_channels) to match the actual input tensor.","Verify checkpoint weights match the model definition (channel counts) after editing the architecture.","Print input.dims() and kernel.dims() and align dim(1) of input with dim(0) of kernel."],"exampleFix":"// before: x (8, 16, 100), kernel (32, 16, 3)  -> c_in=16 vs c_in_k=32\nx.conv_transpose1d(&k, 0, 0, 2, 1, 1)?;\n// after: kernel must start with input channels\nlet k = Tensor::randn(0f32, 1f32, (16, 32, 3), &dev)?;\nx.conv_transpose1d(&k, 0, 0, 2, 1, 1)?;","handlingStrategy":"validation","validationCode":"let (_b, c_in, _l) = x.dims3()?;\nlet (c_in_k, _c_out, _k) = kernel.dims3()?;\nif c_in != c_in_k { return Err(anyhow::anyhow!(\"conv_transpose1d: input channels {c_in} != kernel in-channels {c_in_k}\")); }","typeGuard":null,"tryCatchPattern":"match result { Err(e) if e.to_string().contains(\"in_channel mismatch\") => { // permute kernel to (c_in, c_out, k) and retry\n}, other => other?, }","preventionTips":["Remember transposed-conv kernel layout is (in, out, k) — the opposite of conv1d.","Wire candle_nn::conv::ConvTranspose1d config in_channels directly from the upstream tensor dim.","After changing model channel widths, grep for hardcoded channel numbers in layer configs."],"tags":["shape-mismatch","convolution","tensor","rust"],"backgroundTag":"shape-mismatch","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}