huggingface/candle · error
cannot find 'value' attr in 'Constant' for {}
Error message
cannot find 'value' attr in 'Constant' for {} What it means
The ONNX Constant operator can carry its output in several attributes (value, value_float, value_ints, sparse_value, etc.). candle-onnx only implements the tensor-valued `value` attribute; when a Constant node has none it bails with this message naming the node. The code comments that sparse_value etc. are not yet supported.
Source
Thrown at candle-onnx/src/eval.rs:1098
let output = PReLU::new(slope.clone(), false).forward(input)?;
values.insert(node.output[0].clone(), output);
}
"Ceil" => {
let input = get(&node.input[0])?;
let output = input.ceil()?;
values.insert(node.output[0].clone(), output);
}
"Floor" => {
let input = get(&node.input[0])?;
let output = input.floor()?;
values.insert(node.output[0].clone(), output);
}
// https://github.com/onnx/onnx/blob/main/docs/Operators.md#Constant
"Constant" => {
let value = match node.attribute.iter().find(|attr| attr.name == "value") {
None => {
// TODO: support sparse_value etc.
bail!("cannot find 'value' attr in 'Constant' for {}", node.name)
}
Some(value) => value,
};
let output = match value.r#type() {
AttributeType::Tensor => {
let t = value.t.as_ref().unwrap();
get_tensor(t, &node.name)?
}
rtype => bail!("unsupported 'value' type {rtype:?} for {}", node.name),
};
values.insert(node.output[0].clone(), output);
}
// https://github.com/onnx/onnx/blob/main/docs/Operators.md#Cast
"Cast" => {
let input = get(&node.input[0])?;
let dt: i64 = *get_attr(node, "to")?;
let dtype = match DataType::try_from(dt as i32) {View on GitHub (pinned to d5fee525bf)
Solutions
- Convert scalar/int Constant nodes to tensor `value` attributes in the graph (onnx.helper.make_tensor) before inference
- Run an ONNX graph rewrite/simplifier (onnxsim) which often folds Constant nodes away
- Replace Constant nodes with equivalent Initializers in the model
- Patch candle-onnx to support value_float/value_ints/sparse_value attributes
Example fix
// before: onnx.helper.make_node('Constant', [], ['k'], value_float=1.0)
// after
node = onnx.helper.make_node('Constant', [], ['k'])
node.attribute.append(onnx.helper.make_attribute(
'value', numpy_helper.from_array(np.array([1.0], dtype=np.float32), name='k'))) Defensive patterns
Strategy: validation
Validate before calling
for node in &model.graph.node {
if node.op_type == "Constant" && !node.attribute.iter().any(|a| a.name == "value") {
panic!("Constant node '{}' lacks a 'value' attribute", node.name);
}
} Type guard
fn has_value_attr(node: &NodeProto) -> bool {
node.attribute.iter().any(|a| a.name == "value")
} Try / catch
match candle_onnx::simple_eval(&model, &inputs) {
Err(e) if e.to_string().contains("cannot find 'value' attr in 'Constant'") => {
eprintln!("convert scalar Constants to tensor values: {e}");
}
other => other?,
} Prevention
- Rewrite value_float/value_ints Constants to tensor values post-export
- Use onnxsim to fold constants into initializers
- Check Constant attribute styles during model conversion review
When it happens
Trigger: simple_eval encounters a Constant node whose value is expressed via value_float, value_ints, value_int64, sparse_value, or is missing entirely — common with scalar constants.
Common situations: ONNX models exported by frameworks that emit scalar Constants as value_float/value_ints instead of tensor value; models using sparse constants; graphs produced by older or newer exporters than candle-onnx supports.
Related errors
- more dilations than expected in conv1d {s:?} {}
- unsupported 'value' type {rtype:?} for {}
- only exclusive == 0 is supported in CumSum
- unsupported 'mode' value {mode:?} for Pad node {:?}
- attribute {} was of type TENSOR, but no tensor was found
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/f9bca01c825c828c.
Report an issue: GitHub.