{"record":{"id":"8a86d8467d84f275","repo":"huggingface/candle","slug":"cannot-find-the-name-attribute-in-for","errorCode":null,"errorMessage":"cannot find the '{name}' attribute in '{}' for {}","messagePattern":"cannot find the '(.+?)' attribute in '(.+?)' for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":130,"sourceCode":"        let mut dims = Vec::with_capacity(tensor_proto.dims.len());\n        for dim in &tensor_proto.dims {\n            if dim < &0 {\n                bail!(\n                    \"attribute {} of type TENSOR has a negative dimension, which is unsupported\",\n                    attr.name\n                )\n            }\n            dims.push(*dim as usize)\n        }\n\n        Tensor::from_raw_buffer(&tensor_proto.raw_data, dtype, &dims, &Device::Cpu)\n    }\n}\n\nfn get_attr_<'a>(node: &'a onnx::NodeProto, name: &str) -> Result<&'a onnx::AttributeProto> {\n    match node.attribute.iter().find(|attr| attr.name == name) {\n        None => {\n            bail!(\n                \"cannot find the '{name}' attribute in '{}' for {}\",\n                node.op_type,\n                node.name\n            )\n        }\n        Some(dt) => Ok(dt),\n    }\n}\n\nfn get_attr<'a, T: Attr + ?Sized>(node: &'a onnx::NodeProto, name: &str) -> Result<&'a T> {\n    let attr = get_attr_(node, name)?;\n    if attr.r#type() != T::TYPE {\n        bail!(\n            \"unsupported type {:?} for '{name}' attribute in '{}' for {}\",\n            attr.r#type,\n            node.op_type,\n            node.name\n        )","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L112-L148","documentation":"get_attr_ searches a node's attribute list for a required attribute by name. If no AttributeProto with that name exists, it bails reporting the missing name, the node's op_type and node name. This means the operator instance lacks an attribute the Rust implementation requires.","triggerScenarios":"Calling get_attr::<T>(node, \"name\") for an attribute the ONNX node does not carry; evaluating models where an op uses default attribute values that the exporter omitted (ONNX allows omitting attributes equal to defaults).","commonSituations":"Models exported by frameworks that omit optional/default attributes; opset differences where an attribute was renamed or made optional; candle-onnx implementations requiring an attribute that is optional per the ONNX spec.","solutions":["Re-export the model with explicit attribute values (disable default-attribute elision if the exporter supports it).","Patch the model (Python onnx) to add the missing attribute with its spec default value.","Check the opset version: regenerate with the opset candle-onnx expects.","If the attribute is genuinely optional, file/patch candle-onnx to use get_attr_opt instead of get_attr for that op."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let required = [\"perm\", \"axis\"]; // attributes your ops need\nfor n in required {\n    assert!(node.attribute.iter().any(|a| a.name == n), \"node '{}' ({}) missing attr '{}'\", node.name, node.op_type, n);\n}","typeGuard":"fn has_attr(node: &onnx::NodeProto, name: &str) -> bool {\n    node.attribute.iter().any(|a| a.name == name)\n}","tryCatchPattern":"match get_attr::<i64>(node, \"axis\") {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"cannot find\") => {\n        // apply ONNX spec default instead of failing\n        let axis: i64 = 0; // spec default\n        axis\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Export models without attribute default-elision","Compare your model's opset against what candle-onnx supports","Pre-scan the graph for nodes missing required attributes before inference"],"tags":["rust","candle","onnx","missing-attribute"],"backgroundTag":"missing-attribute","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}