huggingface/candle · error
unsupported 'mode' value {mode:?} for Pad node {:?}
Error message
unsupported 'mode' value {mode:?} for Pad node {:?} What it means
Pad supports only the modes implemented in the match arms above this bail! (e.g. 'constant', 'reflect', etc.). An unrecognized or unimplemented 'mode' attribute value falls through to the default arm and throws this error.
Source
Thrown at candle-onnx/src/eval.rs:1237
std::iter::repeat((min..max).chain((min + 1..=max).rev())).flatten()
}
let idx = if dim > 1 {
let cycle_len = dim * 2 - 2;
let skip = cycle_len - ((pads_pre[i] as usize) % cycle_len);
let idx = zigzag(0, (dim - 1) as i64)
.skip(skip)
.take((pads_pre[i] as usize) + dim + (pads_post[i] as usize));
Tensor::from_iter(idx, out.device())?
} else {
Tensor::full(0i64, (dim,), out.device())?
};
out = out.index_select(&idx, i)?;
}
values.insert(node.output[0].clone(), out);
}
_ => bail!(
"unsupported 'mode' value {mode:?} for Pad node {:?}",
node.name
),
}
}
// https://github.com/onnx/onnx/blob/main/docs/Operators.md#slice
"Slice" => {
let data = get(&node.input[0])?;
let starts = get(&node.input[1])?;
let ends = get(&node.input[2])?;
let default_axes;
let default_steps;
let axes: &Tensor;
let steps: &Tensor;
// If axes are omitted, they are set to [0, ..., r-1]. If steps are omitted,
// they are set to [1, ..., 1] of length len(starts)
match node.input.len() {
3 => {View on GitHub (pinned to d5fee525bf)
Solutions
- Change the Pad node's mode attribute to one supported by candle-onnx (e.g. 'constant')
- Pre-pad the tensor in host code (candle tensor ops) and remove the Pad node from the graph
- Approximate edge/wrap padding with Slice+Concat nodes that candle-onnx supports
- Patch eval.rs to add the missing mode arm
Example fix
// before
onnx.helper.make_attribute('mode', 'wrap')
// after
onnx.helper.make_attribute('mode', 'constant') Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_PAD_MODES: [&str; 1] = ["constant"];
for node in &graph.node {
if node.op_type == "Pad" {
let mode = get_attr_opt::<String>(node, "mode").unwrap_or(None).unwrap_or_else(|| "constant".into());
assert!(SUPPORTED_PAD_MODES.contains(&mode.as_str()), "Pad mode '{}' unsupported", mode);
}
} Prevention
- Only use mode='constant' in exported models
- Implement edge/wrap padding via Slice+Concat in the graph
- Host-side pad with candle's Tensor::pad before inference
When it happens
Trigger: Evaluating a Pad node with mode set to a string not handled by candle-onnx, such as 'edge' or 'wrap', or a typo/None-ish value.
Common situations: Models using torch.nn.functional.pad with mode='replicate'/'circular' exported as 'edge'/'wrap'; exporter writing a nonstandard mode string.
Related errors
- only exclusive == 0 is supported in CumSum
- more dilations than expected in conv1d {s:?} {}
- cannot find 'value' attr in 'Constant' for {}
- unsupported number of inputs {} for Pad node {:?}, expected
- attribute {} was of type TENSOR, but no tensor was found
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/f21a3f3b00c2d455.
Report an issue: GitHub.