huggingface/candle · error

attribute {} was of type TENSOR, but no tensor was found

Error message

attribute {} was of type TENSOR, but no tensor was found

What it means

AttrOwned::get for the Tensor attribute type extracts the embedded TensorProto from an ONNX AttributeProto. When the attribute is declared as type TENSOR but its `t` field is None (no actual tensor payload), the library cannot proceed and bails. This indicates a malformed or unusual ONNX model file.

Source

Thrown at candle-onnx/src/eval.rs:88

impl AttrOwned for Vec<String> {
    const TYPE: AttributeType = AttributeType::Strings;
    fn get(attr: &onnx::AttributeProto) -> Result<Self> {
        let mut ret = vec![];
        for bytes in attr.strings.iter() {
            let s = String::from_utf8(bytes.clone()).map_err(candle::Error::wrap)?;
            ret.push(s);
        }
        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 {}",

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Re-export or re-generate the ONNX model from the original framework (PyTorch/TF) with a standard exporter.
  2. Inspect the model (e.g. with Python onnx + onnx.checker) to find the attribute with type TENSOR but no `t` payload and fix it.
  3. Use a different attribute accessor if the value is actually stored as a graph (g) or sparse_tensor (sparse_tensor) field.
  4. Update candle-onnx in case newer versions handle the model variant.
Defensive patterns

Strategy: validation

Validate before calling

let attr = node.attribute.iter().find(|a| a.name == name).ok_or("missing attr")?;
assert_eq!(attr.r#type(), onnx::AttributeType::Tensor, "not a TENSOR attr");
assert!(attr.t.is_some(), "TENSOR attr has no tensor payload");

Type guard

fn has_tensor_payload(attr: &onnx::AttributeProto) -> bool {
    attr.r#type() == onnx::AttributeType::Tensor && attr.t.is_some()
}

Try / catch

match get_attr::<Tensor>(node, "value") {
    Ok(t) => t,
    Err(e) if e.to_string().contains("no tensor was found") => {
        // fall back to initializer or reject the model
        return Err(e);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Parsing an ONNX model whose node attribute has attribute_type TENSOR but a missing `t` field; calling simple_eval_ / forward on such a model; any get_attr::<Tensor> / get_attr_opt_owned::<Tensor> call on that attribute.

Common situations: Hand-edited or programmatically generated ONNX files where the tensor payload was never set; ONNX produced by a converter bug; model files written by an older/newer opset with different attribute conventions.

Related errors


AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02). Data as JSON: /api/errors/0b2c6c7809f1badb. Report an issue: GitHub.