huggingface/candle · error
attribute {} of type TENSOR was an invalid data_type number
Error message
attribute {} of type TENSOR was an invalid data_type number {} What it means
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.
Source
Thrown at candle-onnx/src/eval.rs:96
}
Ok(ret)
}
}
impl AttrOwned for Tensor {
const TYPE: AttributeType = AttributeType::Tensor;
fn get(attr: &onnx::AttributeProto) -> Result<Self> {
let tensor_proto = match &attr.t {
Some(value) => value,
None => bail!(
"attribute {} was of type TENSOR, but no tensor was found",
attr.name
),
};
let data_type = match DataType::try_from(tensor_proto.data_type) {
Ok(value) => value,
Err(_) => bail!(
"attribute {} of type TENSOR was an invalid data_type number {}",
attr.name,
tensor_proto.data_type
),
};
let dtype = match dtype(data_type) {
Some(value) => value,
None => bail!(
"attribute {} of type TENSOR has an unsupported data_type {}",
attr.name,
data_type.as_str_name()
),
};
let mut dims = Vec::with_capacity(tensor_proto.dims.len());
for dim in &tensor_proto.dims {
if dim < &0 {View on GitHub (pinned to d5fee525bf)
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.
Defensive patterns
Strategy: validation
Validate before calling
let dt = t.data_type;
onnx::tensor_proto::DataType::try_from(dt).map_err(|_| format!("tensor '{name}' has invalid data_type {dt}"))?; Type guard
fn is_valid_onnx_dtype(data_type: i32) -> bool {
onnx::tensor_proto::DataType::try_from(data_type).is_ok()
} Try / catch
match get_attr::<Tensor>(node, name) {
Ok(v) => v,
Err(e) if e.to_string().contains("invalid data_type") => return Err(e.into()),
Err(e) => return Err(e.into()),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Corrupted or truncated model files; custom/proprietary exporters emitting non-standard data types; hand-built protobufs with a wrong integer.
Related errors
- attribute {} of type TENSOR has an unsupported data_type {}
- unsupported 'value' data-type {dt:?} for {name}
- attribute {} was of type TENSOR, but no tensor was found
- attribute {} of type TENSOR has a negative dimension, which
- cannot find the '{name}' attribute in '{}' for {}
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/8e19a78c460d2bea.
Report an issue: GitHub.