huggingface/candle · error
more pads than expected in conv2d {pads:?} {}
Error message
more pads than expected in conv2d {pads:?} {} What it means
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.
Source
Thrown at candle-onnx/src/eval.rs:933
xs.conv1d(ws, pads, strides, dilations, groups as usize)?
}
4 => {
let (pads, xs) = match pads {
None => (0, xs.clone()),
Some([p]) => (*p as usize, xs.clone()),
Some(&[p1, p2, p3, p4]) => {
let p1 = p1 as usize;
let p2 = p2 as usize;
let p3 = p3 as usize;
let p4 = p4 as usize;
if p1 != p2 || p1 != p3 || p1 != p4 {
(0, xs.pad_with_zeros(2, p1, p3)?.pad_with_zeros(3, p2, p4)?)
} else {
(p1, xs.clone())
}
}
Some(pads) => {
bail!("more pads than expected in conv2d {pads:?} {}", node.name)
}
};
let strides = match strides {
None => 1,
Some([p]) => *p as usize,
Some([p1, p2]) => {
if p1 != p2 {
bail!(
"strides have to be the same on both axis {pads:?} {}",
node.name
)
}
*p1 as usize
}
Some(s) => {
bail!("more strides than expected in conv2d {s:?} {}", node.name)
}
};View on GitHub (pinned to d5fee525bf)
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
Example fix
// before: pads: [1, 1, 1, 1]
// after:
attr = onnx.helper.make_attribute('pads', [1, 1])
node.attr.remove(next(a for a in node.attr if a.name == 'pads'))
node.attr.append(attr) Defensive patterns
Strategy: validation
Validate before calling
for node in &model.graph.node {
if node.op_type == "Conv" {
if let Some(p) = node.attribute.iter().find(|a| a.name == "pads") {
let n = p.ints.len();
if n > 2 { panic!("node {}: conv2d pads arity {} unsupported (need 0-2 values)", node.name, n); }
}
}
} Type guard
fn has_compact_pads(attr: &Attribute) -> bool {
attr.name == "pads" && attr.ints.len() <= 2
} Try / catch
match candle_onnx::simple_eval(&model, &inputs) {
Err(e) if e.to_string().contains("more pads than expected in conv2d") => {
eprintln!("rewrite pads attribute to [h, w]: {e}");
}
other => other?,
} Prevention
- 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
When it happens
Trigger: 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].
Common situations: 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.
Related errors
- strides have to be the same on both axis {pads:?} {}
- more strides than expected in conv2d {s:?} {}
- dilations have to be the same on both axis {pads:?} {}
- attribute {} was of type TENSOR, but no tensor was found
- attribute {} of type TENSOR was an invalid data_type number
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/f88130c49804bee7.
Report an issue: GitHub.