{"record":{"id":"b70f128e1296fdab","repo":"huggingface/candle","slug":"attribute-of-type-tensor-has-a-negative-dimensi","errorCode":null,"errorMessage":"attribute {} of type TENSOR has a negative dimension, which is unsupported","messagePattern":"attribute (.+?) of type TENSOR has a negative dimension, which is unsupported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":115,"sourceCode":"                \"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 {\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","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L97-L133","documentation":"ONNX permits negative dimensions as symbolic/unknown markers in some contexts, but candle requires concrete usize dimensions. When any dimension of a TENSOR attribute is negative, the library bails because it cannot build a candle shape from it.","triggerScenarios":"Evaluating an ONNX model whose tensor attribute contains a negative dim value (symbolic unknown encoded as -1) via simple_eval_ / get_attr::<Tensor>.","commonSituations":"Models exported with dynamic shapes where an attribute tensor kept a -1 sentinel dimension; malformed exporters producing negative dims; hand-edited models.","solutions":["Re-export the model with static, fully-specified shapes so no dimension is -1.","Fix the tensor's dims in the model file (e.g. via Python onnx) to concrete non-negative values.","If the attribute is truly dynamic, handle it outside candle-onnx or via a graph input instead of a tensor attribute.","Use onnx shape inference / make_dim_param_fixed tools to specialize dynamic dims before loading."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for d in &t.dims {\n    assert!(*d >= 0, \"tensor '{name}' has negative dim {d}\");\n}","typeGuard":"fn all_dims_non_negative(t: &onnx::TensorProto) -> bool {\n    t.dims.iter().all(|d| *d >= 0)\n}","tryCatchPattern":"match get_attr::<Tensor>(node, name) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"negative dimension\") => return Err(e.into()),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Export models with static shapes (fix dynamic axes at export time)","Run shape inference / dim-fixing tools before inference","Reject models with symbolic (-1) dims at load time"],"tags":["rust","candle","onnx","shape","dimensions"],"backgroundTag":"dynamic-shape-unsupported","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}