{"record":{"id":"857442994e328ae0","repo":"tracel-ai/burn","slug":"asymmetric-3d-same-padding-is-not-supported-use","errorCode":null,"errorMessage":"Asymmetric 3D 'Same' padding is not supported. Use odd kernel sizes for symmetric padding.","messagePattern":"Asymmetric 3D 'Same' padding is not supported\\. Use odd kernel sizes for symmetric padding\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-nn/src/padding.rs","lineNumber":134,"sourceCode":"impl PaddingConfig3d {\n    /// Calculate symmetric padding for 3D operations.\n    /// Returns padding values [depth, height, width] (same for both sides).\n    pub(crate) fn calculate_padding_3d(\n        &self,\n        depth: usize,\n        height: usize,\n        width: usize,\n        kernel_size: &[usize; 3],\n        stride: &[usize; 3],\n    ) -> [usize; 3] {\n        match self {\n            Self::Valid => [0, 0, 0],\n            Self::Same => {\n                let (front, back) = calculate_same_padding(kernel_size[0], stride[0], depth);\n                let (top, bottom) = calculate_same_padding(kernel_size[1], stride[1], height);\n                let (left, right) = calculate_same_padding(kernel_size[2], stride[2], width);\n                if front != back || top != bottom || left != right {\n                    panic!(\n                        \"Asymmetric 3D 'Same' padding is not supported. \\\n                        Use odd kernel sizes for symmetric padding.\"\n                    )\n                }\n                [front, top, left]\n            }\n            Self::Explicit(depth, height, width) => [*depth, *height, *width],\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    // ==================== PaddingConfig1d Tests ====================\n\n    #[test]","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-nn/src/padding.rs#L116-L152","documentation":"PaddingConfig3d::Same does not support asymmetric padding in any of the three axes (depth, height, width). When calculate_same_padding yields different front/back, top/bottom, or left/right values (which happens with even kernel sizes), the function panics. The fix is to use odd kernel sizes so 'Same' padding splits evenly.","triggerScenarios":"Using PaddingConfig3d::Same with a kernel_size where any of the three entries is even (e.g. [2, 3, 3] or [3, 3, 4]), so one axis produces unequal padding pairs.","commonSituations":"Building a 3D conv/video model with even kernels; migrating a PyTorch 3D conv config with even kernel sizes into burn; copy-pasting a 2D Same-padding config into a 3D layer.","solutions":["Use odd kernel sizes on all three axes (e.g. [3, 3, 3]) so Same padding is symmetric.","Switch to PaddingConfig3d::Valid and apply explicit padding yourself.","Compute the padding manually and pass per-axis padding to a kernel variant that accepts asymmetric padding."],"exampleFix":"// before\nlet config = Conv3dConfig::new([3, 3, 3], [1, 1, 1]).with_padding(PaddingConfig3d::Same);\n// kernel_size [2, 3, 3] would panic; use odd sizes:\nlet config = Conv3dConfig::new([3, 3, 3], [1, 1, 1]).with_padding(PaddingConfig3d::Same);","handlingStrategy":"validation","validationCode":"fn symmetric_same_padding_3d_ok(kernel_size: [usize; 3]) -> bool {\n    kernel_size.iter().all(|k| k % 2 == 1) // all three axes must be odd\n}","typeGuard":null,"tryCatchPattern":"// guard config before building the layer\nif !symmetric_same_padding_3d_ok(kernel_size) {\n    // fall back to Valid + manual per-axis padding, or reject the config at startup\n    panic!(\"config error: use odd kernels with Same 3D padding\");\n}","preventionTips":["Validate 3D conv configs (odd kernels) at startup, not at first forward pass.","Check all three axes (depth, height, width), not just the ones you recently edited.","When porting video/3D models, list every kernel size and verify oddness before enabling Same padding."],"tags":["rust","panic","padding","conv3d","asymmetric-padding"],"backgroundTag":"asymmetric-padding-unsupported","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}