{"record":{"id":"013db115d66324a5","repo":"huggingface/candle","slug":"no-graph-defined-in-proto","errorCode":null,"errorMessage":"no graph defined in proto","messagePattern":"no graph defined in proto","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":244,"sourceCode":"            }\n        },\n        Err(_) => {\n            bail!(\"unsupported 'value' data-type {} for {name}\", t.data_type,)\n        }\n    }\n}\n\n// This function provides a direct evaluation of the proto.\n// Longer-term, we should first convert the proto to an intermediate representation of the compute\n// graph so as to make multiple evaluations more efficient.\n// An example upside of this would be to remove intermediary values when they are not needed\n// anymore.\npub fn simple_eval(\n    model: &onnx::ModelProto,\n    mut inputs: HashMap<String, Value>,\n) -> Result<HashMap<String, Value>> {\n    let graph = match &model.graph {\n        None => bail!(\"no graph defined in proto\"),\n        Some(graph) => graph,\n    };\n    simple_eval_(graph, &mut inputs)\n}\n\nfn simple_eval_(\n    graph: &onnx::GraphProto,\n    values: &mut HashMap<String, Value>,\n) -> Result<HashMap<String, Value>> {\n    for t in graph.initializer.iter() {\n        let tensor = get_tensor(t, t.name.as_str())?;\n        values.insert(t.name.to_string(), tensor);\n    }\n    for input in graph.input.iter() {\n        let input_type = match &input.r#type {\n            Some(input_type) => input_type,\n            None => continue,\n        };","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L226-L262","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet out = simple_eval(&model, inputs)?;\n// after\nassert!(model.graph.is_some(), \"not a valid onnx model\");\nlet out = simple_eval(&model, inputs)?;","handlingStrategy":"validation","validationCode":"fn has_graph(model: &onnx::ModelProto) -> bool { model.graph.is_some() }\n// call before simple_eval","typeGuard":"fn is_executable_model(model: &onnx::ModelProto) -> bool {\n    model.graph.as_ref().map_or(false, |g| !g.node.is_empty())\n}","tryCatchPattern":"let out = simple_eval(&model, inputs).map_err(|e| {\n    if e.to_string().contains(\"no graph defined\") { anyhow!(\"invalid or corrupt ONNX model file\") } else { e }\n})?;","preventionTips":["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"],"tags":["onnx","model-loading","missing-field","protobuf"],"backgroundTag":"missing-onnx-graph","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}