{"record":{"id":"f88130c49804bee7","repo":"huggingface/candle","slug":"more-pads-than-expected-in-conv2d-pads","errorCode":null,"errorMessage":"more pads than expected in conv2d {pads:?} {}","messagePattern":"more pads than expected in conv2d (.+?) (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":933,"sourceCode":"                        xs.conv1d(ws, pads, strides, dilations, groups as usize)?\n                    }\n                    4 => {\n                        let (pads, xs) = match pads {\n                            None => (0, xs.clone()),\n                            Some([p]) => (*p as usize, xs.clone()),\n                            Some(&[p1, p2, p3, p4]) => {\n                                let p1 = p1 as usize;\n                                let p2 = p2 as usize;\n                                let p3 = p3 as usize;\n                                let p4 = p4 as usize;\n                                if p1 != p2 || p1 != p3 || p1 != p4 {\n                                    (0, xs.pad_with_zeros(2, p1, p3)?.pad_with_zeros(3, p2, p4)?)\n                                } else {\n                                    (p1, xs.clone())\n                                }\n                            }\n                            Some(pads) => {\n                                bail!(\"more pads than expected in conv2d {pads:?} {}\", node.name)\n                            }\n                        };\n                        let strides = match strides {\n                            None => 1,\n                            Some([p]) => *p as usize,\n                            Some([p1, p2]) => {\n                                if p1 != p2 {\n                                    bail!(\n                                        \"strides have to be the same on both axis {pads:?} {}\",\n                                        node.name\n                                    )\n                                }\n                                *p1 as usize\n                            }\n                            Some(s) => {\n                                bail!(\"more strides than expected in conv2d {s:?} {}\", node.name)\n                            }\n                        };","sourceCodeStart":915,"sourceCodeEnd":951,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L915-L951","documentation":"For rank-2 (2D convolution) weights, candle-onnx expects the Conv node's `pads` attribute to be absent (pads=0) or contain exactly one or two values; a pad list of any other length (e.g. 4 entries: begin/end per axis, or 3+) cannot be interpreted, so simple_eval_ bails with this message naming the node.","triggerScenarios":"Calling simple_eval on an ONNX model where a Conv node with 4D weights carries a `pads` attribute with more than two elements, such as pads=[1,1,1,1].","commonSituations":"Models exported from PyTorch/TensorFlow where the ONNX spec pads format is [x1_begin, x2_begin, x1_end, x2_end] (4 values) rather than the compact [h, w] form this evaluator expects; hand-authored or converted graphs.","solutions":["Rewrite the pads attribute in the model to the 2-value form [pad_h, pad_w] (requires symmetric padding) using onnx python tooling","Use symmetric begin/end padding in the source model before export so the exporter emits compact pads","Pre-pad the input tensor yourself, set pads to 0/absent, and re-export","Patch candle-onnx to expand 4-element [b1,b2,e1,e2] pads into pad_with_zeros calls"],"exampleFix":"// before: pads: [1, 1, 1, 1]\n// after:\nattr = onnx.helper.make_attribute('pads', [1, 1])\nnode.attr.remove(next(a for a in node.attr if a.name == 'pads'))\nnode.attr.append(attr)","handlingStrategy":"validation","validationCode":"for node in &model.graph.node {\n    if node.op_type == \"Conv\" {\n        if let Some(p) = node.attribute.iter().find(|a| a.name == \"pads\") {\n            let n = p.ints.len();\n            if n > 2 { panic!(\"node {}: conv2d pads arity {} unsupported (need 0-2 values)\", node.name, n); }\n        }\n    }\n}","typeGuard":"fn has_compact_pads(attr: &Attribute) -> bool {\n    attr.name == \"pads\" && attr.ints.len() <= 2\n}","tryCatchPattern":"match candle_onnx::simple_eval(&model, &inputs) {\n    Err(e) if e.to_string().contains(\"more pads than expected in conv2d\") => {\n        eprintln!(\"rewrite pads attribute to [h, w]: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Prefer symmetric padding in source models so exporters emit compact pads","Pass models through onnxsim to normalize pads attributes","Validate pad arity per weight rank with a pre-inference lint"],"tags":["onnx","conv2d","attribute-format"],"backgroundTag":"unsupported-onnx-attribute","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}