huggingface/candle · error
more strides than expected in conv2d {s:?} {}
Error message
more strides than expected in conv2d {s:?} {} What it means
candle-onnx maps the Conv `strides` attribute to one scalar for candle's conv1d/conv2d APIs; for rank-2 weights it accepts one or two equal values. A strides list with more than two elements (or otherwise unmatchable) cannot be handled, so simple_eval_ bails with this message.
Source
Thrown at candle-onnx/src/eval.rs:949
}
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)
}
};
let dilations = match dilations {
None => 1,
Some([p]) => *p as usize,
Some([p1, p2]) => {
if p1 != p2 {
bail!(
"dilations have to be the same on both axis {pads:?} {}",
node.name
)
}
*p1 as usize
}
Some(s) => {
bail!("more dilations than expected in conv2d {s:?} {}", node.name)
}
};View on GitHub (pinned to d5fee525bf)
Solutions
- Fix the graph so the strides list length matches the weight rank (1 value for 1D, 2 for 2D)
- Re-export the model with the correct op (Conv1d/Conv2d) so attributes have the right arity
- Simplify the model with onnxsim to normalize attributes before inference
- Patch candle-onnx to slice or validate strides per weight rank
Example fix
// before: strides: [1, 1, 1] on a rank-2 conv // after: strides: [1, 1]
Defensive patterns
Strategy: validation
Validate before calling
for node in &model.graph.node {
if node.op_type == "Conv" {
if let Some(s) = node.attribute.iter().find(|a| a.name == "strides") {
if s.ints.len() > 2 {
panic!("node {}: strides arity {} unsupported", node.name, s.ints.len());
}
}
}
} Type guard
fn strides_arity_ok(attr: &Attribute) -> bool {
attr.name != "strides" || matches!(attr.ints.len(), 0..=2)
} Try / catch
match candle_onnx::simple_eval(&model, &inputs) {
Err(e) if e.to_string().contains("more strides than expected") => {
eprintln!("strides list doesn't match weight rank: {e}");
}
other => other?,
} Prevention
- Keep exporter op selection correct (Conv1d vs Conv2d) so attribute arity matches weight rank
- Run onnxsim to normalize attributes
- Check weight shape vs attribute arity in a model lint step
When it happens
Trigger: A Conv node whose `strides` attribute has 3+ elements (e.g. a 1D conv node exported with 3-element strides, or a corrupted/converted graph) hits the catch-all Some(s) arm.
Common situations: Graphs exported with rank mismatch between attribute length and kernel rank (e.g. 3D conv exported as Conv with rank-2 weights); automated model converters writing padded attribute lists.
Related errors
- strides have to be the same on both axis {pads:?} {}
- more pads than expected in conv2d {pads:?} {}
- 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/f8de4d61195e6fe8.
Report an issue: GitHub.