huggingface/candle · error

unsupported number of inputs {} for Pad node {:?}, expected

Error message

unsupported number of inputs {} for Pad node {:?}, expected 2

What it means

The Pad node implementation accepts only the 'data' and 'pads' inputs (2 inputs). The ONNX spec allows an optional third 'constant_value' input; candle-onnx does not support it and bails if more than 2 inputs are present.

Source

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

                        sub_graph.output.len(),
                        node.output.len()
                    );
                }
                let branch_out = simple_eval_(sub_graph, values)?;
                for (i, out) in node.output.iter().enumerate() {
                    values.insert(
                        out.clone(),
                        branch_out.get(&sub_graph.output[i].name).unwrap().clone(),
                    );
                }
            }
            // https://github.com/onnx/onnx/blob/main/docs/Operators.md#pad
            "Pad" => {
                let mode = get_attr_opt(node, "mode")?.unwrap_or("constant");
                let data = get(&node.input[0])?;
                let pads = get(&node.input[1])?;
                if node.input.len() > 2 {
                    bail!(
                        "unsupported number of inputs {} for Pad node {:?}, expected 2",
                        node.input.len(),
                        node.name
                    );
                }
                if pads.rank() != 1 {
                    bail!("Pad expects 'pads' input to be 1D vector: {pads:?}");
                }
                if pads.dim(0).unwrap() != 2 * data.rank() {
                    bail!("Pad expects 'pads' input len to be 2 * rank of 'data' input: pads: {}, data rank: {}", pads, data.rank());
                }

                let pads = pads.to_vec1::<i64>()?;
                let (pads_pre, pads_post) = pads.split_at(pads.len() / 2);

                match mode {
                    "reflect" => {
                        let mut out = data.clone();

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Rewrite the graph to bake the constant value into the node's 'value' attribute form, or use mode-implicit zero padding
  2. Remove the constant_value input and rely on the default (0) if that matches the intended value
  3. Pre-process with onnx python: convert Pad to an older opset form using the 'value' attribute
  4. Patch candle-onnx to read input[2] as constant_value

Example fix

// before (opset 11)
Pad(data, pads, constant_value)
// after (opset 2 style)
Pad(data, pads)  # with attribute value=0.0
Defensive patterns

Strategy: validation

Validate before calling

for node in &graph.node {
    if node.op_type == "Pad" {
        assert!(node.input.len() <= 2, "Pad {} has {} inputs", node.name, node.input.len());
    }
}

Prevention

When it happens

Trigger: Evaluating a model with a Pad node having 3 (or more) inputs, i.e. an explicit constant_value (input[2]) or axes (input[3]) input.

Common situations: Models exported with opset >= 11 where the exporter emits the constant_value input; newer exporters (opset >= 18) also emitting the axes input.

Related errors


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