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
- Re-export the model with explicit attribute values (disable default-attribute elision if the exporter supports it).
- Patch the model (Python onnx) to add the missing attribute with its spec default value.
- Check the opset version: regenerate with the opset candle-onnx expects.
- 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
- Export models without attribute default-elision
- Compare your model's opset against what candle-onnx supports
- Pre-scan the graph for nodes missing required attributes before inference
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
- attribute {} was of type TENSOR, but no tensor was found
- attribute {} of type TENSOR was an invalid data_type number
- attribute {} of type TENSOR has an unsupported data_type {}
- attribute {} of type TENSOR has a negative dimension, which
- unsupported type {:?} for '{name}' attribute in '{}' for {}
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/8a86d8467d84f275.
Report an issue: GitHub.