huggingface/candle · error
strides have to be the same on both axis {pads:?} {}
Error message
strides have to be the same on both axis {pads:?} {} What it means
When a Conv node's `strides` attribute has two values (one per axis), candle-onnx requires them to be equal because it passes a single scalar stride to candle's conv2d. If p1 != p2 the evaluator bails with this message (note the message text mistakenly interpolates `pads`, not strides).
Source
Thrown at candle-onnx/src/eval.rs:941
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)
}
};
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.nameView on GitHub (pinned to d5fee525bf)
Solutions
- Change the model to use symmetric strides (p1 == p2) and re-export
- Insert reshape/pooling ops so a single-stride conv achieves the desired asymmetric downsampling
- Patch candle-onnx to pass per-axis strides to candle's conv2d (which supports stride tuples)
- Modify the ONNX graph to set strides=[s,s] with s equal on both axes
Example fix
// before (PyTorch): nn.Conv2d(..., stride=(2, 1)) // after: nn.Conv2d(..., stride=2) # then re-export to ONNX
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 && s.ints[0] != s.ints[1] {
panic!("node {}: asymmetric strides {:?} unsupported", node.name, s.ints);
}
}
}
} Type guard
fn has_uniform_strides(attr: &Attribute) -> bool {
attr.name != "strides" || attr.ints.iter().all(|&s| s == attr.ints[0])
} Try / catch
match candle_onnx::simple_eval(&model, &inputs) {
Err(e) if e.to_string().contains("strides have to be the same") => {
eprintln!("model needs symmetric conv strides: {e}");
}
other => other?,
} Prevention
- Avoid stride=(h,w) with h!=w in source models intended for candle-onnx
- Lint ONNX graphs for asymmetric strides before inference
- Fall back to onnxruntime for models needing asymmetric strides
When it happens
Trigger: simple_eval encounters a Conv node with 2D weights and strides like [2,1] — different horizontal/vertical strides.
Common situations: PyTorch nn.Conv2d(stride=(2,1)) exported to ONNX; detection/segmentation models that downsample asymmetrically; hand-tuned inference graphs.
Related errors
- more strides than expected in conv2d {s:?} {}
- 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/6f00deb6fba0c658.
Report an issue: GitHub.