huggingface/candle · error

more dilations than expected in conv1d {s:?} {}

Error message

more dilations than expected in conv1d {s:?} {}

What it means

candle-onnx's Conv operator evaluator only supports 1D convolution when the `dilations` attribute contains a single value (or is absent, defaulting to 1). If the attribute has more than one element it cannot be mapped to the scalar dilation candle's conv1d accepts, so simple_eval_ bails with this message. The node name is included to locate the offending Conv node in the ONNX graph.

Source

Thrown at candle-onnx/src/eval.rs:912

                                    (*p1 as usize, xs.clone())
                                }
                            }
                            Some(pads) => {
                                bail!("more pads than expected in conv1d {pads:?} {}", node.name)
                            }
                        };
                        let strides = match strides {
                            None => 1,
                            Some([p]) => *p as usize,
                            Some(s) => {
                                bail!("more strides than expected in conv1d {s:?} {}", node.name)
                            }
                        };
                        let dilations = match dilations {
                            None => 1,
                            Some([p]) => *p as usize,
                            Some(s) => {
                                bail!("more dilations than expected in conv1d {s:?} {}", node.name)
                            }
                        };
                        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())
                                }

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Edit the ONNX model to set dilations to a single-element list ([d]) or remove the attribute (defaults to 1) using onnx.helper/onnxruntime tooling
  2. Re-export the model ensuring Conv nodes with rank-1 kernels use 1D dilation attributes
  3. Patch candle-onnx locally to accept Some([p1,p2]) when p1==p2 for conv1d
  4. Preprocess the graph with the onnx optimizer/simplifier to normalize attributes

Example fix

// before: dilations: [2, 2] on a 1D conv node
// after (onnx python):
node_attr = onnx.helper.make_attribute('dilations', [2])
node.attr.remove(next(a for a in node.attr if a.name == 'dilations'))
node.attr.append(node_attr)
Defensive patterns

Strategy: validation

Validate before calling

// before candle_onnx::simple_eval
for node in &model.graph.node {
    if node.op_type == "Conv" {
        if let Some(d) = node.attribute.iter().find(|a| a.name == "dilations") {
            let n = d.ints.len();
            if n > 1 { panic!("node {}: conv1d dilations arity {} unsupported", node.name, n); }
        }
    }
}

Type guard

fn is_scalar_dilation(attr: &Attribute) -> bool {
    attr.name == "dilations" && (attr.ints.is_empty() || attr.ints.len() == 1)
}

Try / catch

match candle_onnx::simple_eval(&model, &inputs) {
    Err(e) if e.to_string().contains("more dilations than expected in conv1d") => {
        eprintln!("fix the model's dilations attr: {e}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running simple_eval/simple_eval_ on an ONNX model whose Conv node has rank-1 weights and a `dilations` attribute with 2+ entries, e.g. dilations=[2,2] exported from a framework.

Common situations: Exporting a PyTorch/TensorFlow model where the exporter always writes 2-element dilation attributes even for 1D convs; converting models whose dilations were never intended to differ per axis.

Related errors


AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02). Data as JSON: /api/errors/dbb58fad20060237. Report an issue: GitHub.