{"record":{"id":"8e19a78c460d2bea","repo":"huggingface/candle","slug":"attribute-of-type-tensor-was-an-invalid-data-ty","errorCode":null,"errorMessage":"attribute {} of type TENSOR was an invalid data_type number {}","messagePattern":"attribute (.+?) of type TENSOR was an invalid data_type number (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":96,"sourceCode":"        }\n        Ok(ret)\n    }\n}\n\nimpl AttrOwned for Tensor {\n    const TYPE: AttributeType = AttributeType::Tensor;\n    fn get(attr: &onnx::AttributeProto) -> Result<Self> {\n        let tensor_proto = match &attr.t {\n            Some(value) => value,\n            None => bail!(\n                \"attribute {} was of type TENSOR, but no tensor was found\",\n                attr.name\n            ),\n        };\n\n        let data_type = match DataType::try_from(tensor_proto.data_type) {\n            Ok(value) => value,\n            Err(_) => bail!(\n                \"attribute {} of type TENSOR was an invalid data_type number {}\",\n                attr.name,\n                tensor_proto.data_type\n            ),\n        };\n\n        let dtype = match dtype(data_type) {\n            Some(value) => value,\n            None => bail!(\n                \"attribute {} of type TENSOR has an unsupported data_type {}\",\n                attr.name,\n                data_type.as_str_name()\n            ),\n        };\n\n        let mut dims = Vec::with_capacity(tensor_proto.dims.len());\n        for dim in &tensor_proto.dims {\n            if dim < &0 {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L78-L114","documentation":"After locating a TENSOR-typed attribute, the code converts tensor_proto.data_type (an i32 enum) into an ONNX DataType. If the numeric data_type is not a valid ONNX TensorProto_DataType value, the library bails because it cannot interpret the tensor's element type.","triggerScenarios":"Loading an ONNX attribute tensor whose data_type field holds an out-of-range or unrecognized integer; models produced by tools writing invalid enum values into TensorProto.data_type.","commonSituations":"Corrupted or truncated model files; custom/proprietary exporters emitting non-standard data types; hand-built protobufs with a wrong integer.","solutions":["Validate the model with onnx.checker and fix the offending tensor's data_type.","Re-export the model with the official ONNX exporter so a valid DataType is written.","Map the invalid number to the nearest supported dtype by editing the model (e.g. with Python onnx) before loading in Rust.","Check candle-onnx for updates; the accepted DataType set may have grown."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let dt = t.data_type;\nonnx::tensor_proto::DataType::try_from(dt).map_err(|_| format!(\"tensor '{name}' has invalid data_type {dt}\"))?;","typeGuard":"fn is_valid_onnx_dtype(data_type: i32) -> bool {\n    onnx::tensor_proto::DataType::try_from(data_type).is_ok()\n}","tryCatchPattern":"match get_attr::<Tensor>(node, name) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"invalid data_type\") => return Err(e.into()),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Validate models with onnx.checker/offline tooling before inference","Never hand-write TensorProto.data_type integers","Re-export from the source framework rather than patching protobufs"],"tags":["rust","candle","onnx","dtype"],"backgroundTag":"onnx-attribute-type-mismatch","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}