huggingface/candle · error

cannot find the '{name}' attribute in '{}' for {}

Error message

cannot find the '{name}' attribute in '{}' for {}

What it means

get_attr_ searches a node's attribute list for a required attribute by name. If no AttributeProto with that name exists, it bails reporting the missing name, the node's op_type and node name. This means the operator instance lacks an attribute the Rust implementation requires.

Source

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

        let mut dims = Vec::with_capacity(tensor_proto.dims.len());
        for dim in &tensor_proto.dims {
            if dim < &0 {
                bail!(
                    "attribute {} of type TENSOR has a negative dimension, which is unsupported",
                    attr.name
                )
            }
            dims.push(*dim as usize)
        }

        Tensor::from_raw_buffer(&tensor_proto.raw_data, dtype, &dims, &Device::Cpu)
    }
}

fn get_attr_<'a>(node: &'a onnx::NodeProto, name: &str) -> Result<&'a onnx::AttributeProto> {
    match node.attribute.iter().find(|attr| attr.name == name) {
        None => {
            bail!(
                "cannot find the '{name}' attribute in '{}' for {}",
                node.op_type,
                node.name
            )
        }
        Some(dt) => Ok(dt),
    }
}

fn get_attr<'a, T: Attr + ?Sized>(node: &'a onnx::NodeProto, name: &str) -> Result<&'a T> {
    let attr = get_attr_(node, name)?;
    if attr.r#type() != T::TYPE {
        bail!(
            "unsupported type {:?} for '{name}' attribute in '{}' for {}",
            attr.r#type,
            node.op_type,
            node.name
        )

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Re-export the model with explicit attribute values (disable default-attribute elision if the exporter supports it).
  2. Patch the model (Python onnx) to add the missing attribute with its spec default value.
  3. Check the opset version: regenerate with the opset candle-onnx expects.
  4. If the attribute is genuinely optional, file/patch candle-onnx to use get_attr_opt instead of get_attr for that op.
Defensive patterns

Strategy: validation

Validate before calling

let required = ["perm", "axis"]; // attributes your ops need
for n in required {
    assert!(node.attribute.iter().any(|a| a.name == n), "node '{}' ({}) missing attr '{}'", node.name, node.op_type, n);
}

Type guard

fn has_attr(node: &onnx::NodeProto, name: &str) -> bool {
    node.attribute.iter().any(|a| a.name == name)
}

Try / catch

match get_attr::<i64>(node, "axis") {
    Ok(v) => v,
    Err(e) if e.to_string().contains("cannot find") => {
        // apply ONNX spec default instead of failing
        let axis: i64 = 0; // spec default
        axis
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Calling get_attr::<T>(node, "name") for an attribute the ONNX node does not carry; evaluating models where an op uses default attribute values that the exporter omitted (ONNX allows omitting attributes equal to defaults).

Common situations: Models exported by frameworks that omit optional/default attributes; opset differences where an attribute was renamed or made optional; candle-onnx implementations requiring an attribute that is optional per the ONNX spec.

Related errors


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