{"record":{"id":"39ff5be27f48333b","repo":"huggingface/candle","slug":"convtr1d-shape-mismatch-on-c-in-39ff5b","errorCode":null,"errorMessage":"convtr1d: shape mismatch on c_in {:?} {:?}","messagePattern":"convtr1d: shape mismatch on c_in (.+?) (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/metal_backend/mod.rs","lineNumber":1006,"sourceCode":"        layout: &Layout,\n        k: &Self,\n        k_layout: &Layout,\n        params: &ParamsConvTranspose1D,\n    ) -> Result<Self> {\n        const USE_COL2IM_CONV1D_TR: bool = true;\n\n        let can_use_col2im = k_layout.is_contiguous()\n            && params.dilation == 1\n            && params.padding == 0\n            && params.output_padding == 0;\n        let l_out = params.l_out();\n        let dst_el = params.c_out * l_out * params.b_size;\n\n        let buffer = if USE_COL2IM_CONV1D_TR && can_use_col2im {\n            let (b_size, c_in, l_in) = layout.shape().dims3()?;\n            let (c_in2, c_out, k_size) = k_layout.shape().dims3()?;\n            if c_in != c_in2 {\n                crate::bail!(\n                    \"convtr1d: shape mismatch on c_in {:?} {:?}\",\n                    layout.shape(),\n                    k_layout.shape()\n                )\n            }\n            let buffer = self\n                .device\n                .new_buffer_builder()\n                .with_size_for(dst_el, self.dtype)\n                .with_label(\"conv_transpose1d\")\n                .build()?;\n\n            let name = match self.dtype {\n                DType::F32 => \"col2im1d_f32\",\n                DType::F16 => \"col2im1d_f16\",\n                DType::BF16 => \"col2im1d_bf16\",\n                DType::U32 => \"col2im1d_u32\",\n                DType::U8 => \"col2im1d_u8\",","sourceCodeStart":988,"sourceCodeEnd":1024,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/metal_backend/mod.rs#L988-L1024","documentation":"When Metal conv_transpose1d uses the col2im path (USE_COL2IM_CONV1D_TR), it treats the input as (b_size, c_in, l_in) and the kernel as (c_in, c_out, k_size); if the input's c_in does not match the kernel's c_in the shapes are incompatible and the backend bails with both shapes in the message.","triggerScenarios":"Calling conv_transpose1d on Metal with a kernel whose input-channel count differs from the tensor's channel count — a misconfigured ConvTranspose1d layer (wrong in_channels) or wrongly-shaped weight tensor.","commonSituations":"Hand-constructing transposed-conv weights with transposed dims; loading checkpoints whose convtr weight layout differs; passing (c_out, c_in, k) instead of (c_in, c_out, k).","solutions":["Ensure the kernel weight has shape (c_in, c_out, k_size) matching the input's channels","Fix the layer config so in_channels matches the previous layer's out_channels","Permute the weight with transpose/permute to the expected layout","Check checkpoint conversion code for axis ordering mistakes"],"exampleFix":"// before\nlet k = weight.transpose(0, 1)?; // (c_out, c_in, k) — wrong order\n// after\nlet k = weight; // keep (c_in, c_out, k) as expected by convtr1d","handlingStrategy":"validation","validationCode":"let (b, c_in, l) = x.dims3()?;\nlet (k_c_in, _k_c_out, _k) = kernel.dims3()?;\nif c_in != k_c_in {\n    anyhow::bail!(\"convtr1d kernel expects (c_in, c_out, k); got c_in={} vs input c={}\", k_c_in, c_in);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store transposed-conv weights as (c_in, c_out, k_size)","Set ConvTranspose1d in_channels to match the previous layer's out_channels","Add shape asserts at module boundaries","Verify checkpoint conversion axis order"],"tags":["metal","gpu","conv-transpose","shape-mismatch","candle"],"backgroundTag":"shape-mismatch","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}