huggingface/candle · error
Slice node is invalid, expected 3-5 inputs, got {}: {:?}
Error message
Slice node is invalid, expected 3-5 inputs, got {}: {:?} What it means
The Slice node in ONNX takes data, starts, ends and optional axes and steps (3-5 inputs). Candle-onnx enforces this arity and bails for any other count (fewer than 3 or more than 5), since it cannot resolve which tensors are starts/ends/axes/steps.
Source
Thrown at candle-onnx/src/eval.rs:1272
match node.input.len() {
3 => {
let len = starts.dims()[0];
default_axes = Some(Tensor::arange(0, len as i64, starts.device())?);
axes = default_axes.as_ref().unwrap();
default_steps = Some(Tensor::ones((len,), DType::I64, starts.device())?);
steps = default_steps.as_ref().unwrap();
}
4 => {
let len = starts.dims()[0];
axes = get(&node.input[3])?;
default_steps = Some(Tensor::ones((len,), DType::I64, starts.device())?);
steps = default_steps.as_ref().unwrap();
}
5 => {
steps = get(&node.input[4])?;
axes = get(&node.input[3])?;
}
_ => bail!(
"Slice node is invalid, expected 3-5 inputs, got {}: {:?}",
node.input.len(),
node
),
}
let mut out = data.clone();
for (i, axis) in axes.to_vec1::<i64>()?.into_iter().enumerate() {
// All negative elements of axes are made non-negative by
// adding r to them, where r = rank(input).
let axis = if axis < 0 {
axis + data.rank() as i64
} else {
axis
} as usize;
let data_dim = data.dims()[axis] as i64;
let mut s = to_scalar_flexible::<i64>(&starts.get(i)?)?;View on GitHub (pinned to d5fee525bf)
Solutions
- Re-export the model with opset >= 10 so Slice uses inputs (data, starts, ends[, axes][, steps])
- Convert attribute-based Slice to input-based Slice via onnx version converter to opset 10+
- Supply all required inputs: starts and ends (and axes/steps as needed) as 1-D i64 constants
- Fix graph edits that dropped required Slice inputs
Example fix
// before (opset 1, attribute-based) Slice(data) with attrs starts/ends // after (opset 10+) Slice(data, starts, ends, axes) # 3-5 inputs
Defensive patterns
Strategy: validation
Validate before calling
for node in &graph.node {
if node.op_type == "Slice" {
let n = node.input.len();
assert!((3..=5).contains(&n), "Slice {} has {} inputs", node.name, n);
}
} Type guard
fn slice_arity_ok(node: &NodeProto) -> bool {
(3..=5).contains(&node.input.len())
} Prevention
- Export with opset >= 10 so Slice uses 3-5 inputs
- Convert legacy attribute-based Slice with the onnx version converter
- Always include starts/ends (and axes) as explicit 1-D i64 inputs
When it happens
Trigger: Evaluating a Slice node with 0-2 inputs (e.g. old opset-1 Slice using attributes) or 6+ inputs, i.e. any count outside 3..=5.
Common situations: Very old models exporting Slice as an attribute-based op (opset < 10) instead of input-based; an optimizer removing 'axes'/'steps' inputs improperly; hand-written graphs missing starts/ends.
Related errors
- unsupported number of inputs {} for Pad node {:?}, expected
- attribute {} was of type TENSOR, but no tensor was found
- attribute {} of type TENSOR was an invalid data_type number
- attribute {} of type TENSOR has an unsupported data_type {}
- attribute {} of type TENSOR has a negative dimension, which
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/7d0398bbe658e1ad.
Report an issue: GitHub.