huggingface/candle · error
no graph defined in proto
Error message
no graph defined in proto
What it means
simple_eval evaluates an ONNX ModelProto directly. The message is thrown when the ModelProto has no `graph` field set (model.graph is None). An ONNX model without a graph carries no computation and cannot be executed.
Source
Thrown at candle-onnx/src/eval.rs:244
}
},
Err(_) => {
bail!("unsupported 'value' data-type {} for {name}", t.data_type,)
}
}
}
// This function provides a direct evaluation of the proto.
// Longer-term, we should first convert the proto to an intermediate representation of the compute
// graph so as to make multiple evaluations more efficient.
// An example upside of this would be to remove intermediary values when they are not needed
// anymore.
pub fn simple_eval(
model: &onnx::ModelProto,
mut inputs: HashMap<String, Value>,
) -> Result<HashMap<String, Value>> {
let graph = match &model.graph {
None => bail!("no graph defined in proto"),
Some(graph) => graph,
};
simple_eval_(graph, &mut inputs)
}
fn simple_eval_(
graph: &onnx::GraphProto,
values: &mut HashMap<String, Value>,
) -> Result<HashMap<String, Value>> {
for t in graph.initializer.iter() {
let tensor = get_tensor(t, t.name.as_str())?;
values.insert(t.name.to_string(), tensor);
}
for input in graph.input.iter() {
let input_type = match &input.r#type {
Some(input_type) => input_type,
None => continue,
};View on GitHub (pinned to d5fee525bf)
Solutions
- Verify the file is a real ONNX model (starts with protobuf serialization of ModelProto; check with onnx.load and model.graph).
- If constructing ModelProto manually, set model.graph before calling simple_eval.
- Re-export or re-download the model; the source file is truncated or corrupt.
- Wrap eval in error handling and surface a clear 'invalid/corrupt ONNX model' message to users.
Example fix
// before let out = simple_eval(&model, inputs)?; // after assert!(model.graph.is_some(), "not a valid onnx model"); let out = simple_eval(&model, inputs)?;
Defensive patterns
Strategy: validation
Validate before calling
fn has_graph(model: &onnx::ModelProto) -> bool { model.graph.is_some() }
// call before simple_eval Type guard
fn is_executable_model(model: &onnx::ModelProto) -> bool {
model.graph.as_ref().map_or(false, |g| !g.node.is_empty())
} Try / catch
let out = simple_eval(&model, inputs).map_err(|e| {
if e.to_string().contains("no graph defined") { anyhow!("invalid or corrupt ONNX model file") } else { e }
})?; Prevention
- Verify the file path points to a real .onnx model, not metadata
- Never hand-build ModelProto without setting graph
- Checksum downloaded models to detect truncation
- Sanity-check with python onnx.load + model.graph before shipping
When it happens
Trigger: Calling candle_onnx::simple_eval(&model, inputs) with a deserialized ModelProto whose graph field was never set — e.g. a hand-built proto, a proto loaded from a non-model file, or a stripped/corrupted .onnx file.
Common situations: Pointing the loader at the wrong file (metadata rather than the model); constructing ModelProto programmatically and forgetting to set graph; protobuf decoding succeeding but yielding an empty message.
Related errors
- unsupported 'value' data-type {} for {name}
- unsupported input type {type_:?}
- 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 {}
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/013db115d66324a5.
Report an issue: GitHub.