{"record":{"id":"f9bca01c825c828c","repo":"huggingface/candle","slug":"cannot-find-value-attr-in-constant-for","errorCode":null,"errorMessage":"cannot find 'value' attr in 'Constant' for {}","messagePattern":"cannot find 'value' attr in 'Constant' for (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":1098,"sourceCode":"                let output = PReLU::new(slope.clone(), false).forward(input)?;\n                values.insert(node.output[0].clone(), output);\n            }\n            \"Ceil\" => {\n                let input = get(&node.input[0])?;\n                let output = input.ceil()?;\n                values.insert(node.output[0].clone(), output);\n            }\n            \"Floor\" => {\n                let input = get(&node.input[0])?;\n                let output = input.floor()?;\n                values.insert(node.output[0].clone(), output);\n            }\n            // https://github.com/onnx/onnx/blob/main/docs/Operators.md#Constant\n            \"Constant\" => {\n                let value = match node.attribute.iter().find(|attr| attr.name == \"value\") {\n                    None => {\n                        // TODO: support sparse_value etc.\n                        bail!(\"cannot find 'value' attr in 'Constant' for {}\", node.name)\n                    }\n                    Some(value) => value,\n                };\n                let output = match value.r#type() {\n                    AttributeType::Tensor => {\n                        let t = value.t.as_ref().unwrap();\n                        get_tensor(t, &node.name)?\n                    }\n                    rtype => bail!(\"unsupported 'value' type {rtype:?} for {}\", node.name),\n                };\n\n                values.insert(node.output[0].clone(), output);\n            }\n            // https://github.com/onnx/onnx/blob/main/docs/Operators.md#Cast\n            \"Cast\" => {\n                let input = get(&node.input[0])?;\n                let dt: i64 = *get_attr(node, \"to\")?;\n                let dtype = match DataType::try_from(dt as i32) {","sourceCodeStart":1080,"sourceCodeEnd":1116,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L1080-L1116","documentation":"The ONNX Constant operator can carry its output in several attributes (value, value_float, value_ints, sparse_value, etc.). candle-onnx only implements the tensor-valued `value` attribute; when a Constant node has none it bails with this message naming the node. The code comments that sparse_value etc. are not yet supported.","triggerScenarios":"simple_eval encounters a Constant node whose value is expressed via value_float, value_ints, value_int64, sparse_value, or is missing entirely — common with scalar constants.","commonSituations":"ONNX models exported by frameworks that emit scalar Constants as value_float/value_ints instead of tensor value; models using sparse constants; graphs produced by older or newer exporters than candle-onnx supports.","solutions":["Convert scalar/int Constant nodes to tensor `value` attributes in the graph (onnx.helper.make_tensor) before inference","Run an ONNX graph rewrite/simplifier (onnxsim) which often folds Constant nodes away","Replace Constant nodes with equivalent Initializers in the model","Patch candle-onnx to support value_float/value_ints/sparse_value attributes"],"exampleFix":"// before: onnx.helper.make_node('Constant', [], ['k'], value_float=1.0)\n// after\nnode = onnx.helper.make_node('Constant', [], ['k'])\nnode.attribute.append(onnx.helper.make_attribute(\n    'value', numpy_helper.from_array(np.array([1.0], dtype=np.float32), name='k')))","handlingStrategy":"validation","validationCode":"for node in &model.graph.node {\n    if node.op_type == \"Constant\" && !node.attribute.iter().any(|a| a.name == \"value\") {\n        panic!(\"Constant node '{}' lacks a 'value' attribute\", node.name);\n    }\n}","typeGuard":"fn has_value_attr(node: &NodeProto) -> bool {\n    node.attribute.iter().any(|a| a.name == \"value\")\n}","tryCatchPattern":"match candle_onnx::simple_eval(&model, &inputs) {\n    Err(e) if e.to_string().contains(\"cannot find 'value' attr in 'Constant'\") => {\n        eprintln!(\"convert scalar Constants to tensor values: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Rewrite value_float/value_ints Constants to tensor values post-export","Use onnxsim to fold constants into initializers","Check Constant attribute styles during model conversion review"],"tags":["onnx","constant","unsupported-attribute"],"backgroundTag":"missing-onnx-attribute","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}