huggingface/candle · error
cannot find {input_name} for op '{}'
Error message
cannot find {input_name} for op '{}' What it means
During node execution, simple_eval_ looks up each node input name in the accumulated values map (initializers + prior outputs + user inputs). If a name is missing when the op needs it, this error is thrown with the missing name and the op's name. It usually means the graph is malformed or an input was not produced earlier.
Source
Thrown at candle-onnx/src/eval.rs:326
// We do not check equality constraints for the DimParam dimensions for now.
Some(onnx::tensor_shape_proto::dimension::Value::DimParam(_)) | None => (),
}
}
}
};
if dt != tensor.dtype() {
bail!(
"unexpected dtype for {}, got {:?}, expected {dt:?}",
input.name,
tensor.dtype()
)
}
}
// The nodes are topologically sorted so we can just process them in order.
for node in graph.node.iter() {
let get = |input_name: &str| match values.get(input_name) {
Some(value) => Ok(value),
None => bail!("cannot find {input_name} for op '{}'", node.name),
};
let get_opt = |i: usize| {
node.input
.get(i)
.filter(|s: &&String| !s.is_empty())
.map(|s| get(s))
};
// TODO: Validate node.input for each operator.
match node.op_type.as_str() {
"Add" => {
let input0 = get(&node.input[0])?;
let input1 = get(&node.input[1])?;
let output = input0.broadcast_add(input1)?;
values.insert(node.output[0].clone(), output);
}
"Sub" => {
let input0 = get(&node.input[0])?;View on GitHub (pinned to d5fee525bf)
Solutions
- Validate the model with onnx.checker / onnx.shape_inference to confirm every node input is produced by an initializer, graph input, or earlier node output.
- Ensure all graph inputs listed in model.graph.input are supplied in the inputs HashMap.
- Check external-data initializers were loaded (weights file next to the .onnx, correct location field).
- If the name comes from an optional input slot, this is an evaluator limitation — pin or upgrade candle-onnx to a version handling that op pattern.
Example fix
// before
let mut inputs = HashMap::new();
inputs.insert("input".to_string(), x); // mask referenced by Add node missing
// after
inputs.insert("mask".to_string(), mask); // supply every producer name nodes consume Defensive patterns
Strategy: validation
Validate before calling
fn unreferenced_inputs(model: &onnx::ModelProto, inputs: &HashMap<String, Value>) -> Vec<String> {
// ensure every name consumed by nodes is either supplied, an initializer, or an earlier output
let produced: std::collections::HashSet<String> = model.graph.as_ref().map_or_default(|g| {
g.initializer.iter().map(|t| t.name.clone())
.chain(g.input.iter().map(|i| i.name.clone()))
.chain(g.node.iter().flat_map(|n| n.output.iter().cloned()))
.collect()
});
let mut missing = vec![];
if let Some(g) = &model.graph {
for n in &g.node {
for inp in &n.input {
if !inp.is_empty() && !produced.contains(inp) && !inputs.contains_key(inp) {
missing.push(inp.clone());
}
}
}
}
missing
} Try / catch
match simple_eval(&model, inputs) {
Err(e) if e.to_string().starts_with("cannot find") => {
anyhow::bail!("graph references a value never produced — check model integrity / external weight files / supplied inputs")
}
r => r?,
} Prevention
- Run onnx.checker + shape inference to verify graph validity
- Ship external-data weight files alongside the .onnx
- Supply every name in model.graph.input
- Prefer unedited exporter output over manual model surgery
- Upgrade candle-onnx if the pattern involves optional/subgraph inputs
When it happens
Trigger: simple_eval on a model whose node references an unknown name (graph not topologically valid / corrupted), or where a user input name matches what a node consumes but was omitted from the inputs map (the generic input check only iterates graph.input).
Common situations: Subgraph/outer-scope references the evaluator doesn't support; models edited to remove a producer node; optional inputs referenced with empty names being consumed via get instead of get_opt; stripped initializers (external data not loaded).
Related errors
- missing input {}
- unsupported 'value' data-type {dt:?} for {}
- unsupported input type {type_:?}
- unexpected rank for {}, got {:?}, expected {:?}
- unexpected dim {idx} for {}, got {:?}, expected {:?}
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/d7069c14f9430db7.
Report an issue: GitHub.