huggingface/candle · error

unsupported 'value' type {rtype:?} for {}

Error message

unsupported 'value' type {rtype:?} for {}

What it means

Once a Constant node's `value` attribute is found, candle-onnx only materializes it when its type is AttributeType::Tensor. Any other attribute type (e.g. GRAPH, SPARSE_TENSOR, STRING, INTS, FLOATS) is rejected with this bail naming the node.

Source

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

                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) {
                    Ok(DataType::Int32) => DType::I64,
                    Ok(dt) => match dtype(dt) {
                        Some(dt) => dt,
                        None => {
                            bail!("unsupported 'to' value {dt:?} for cast {}", node.name)
                        }
                    },
                    Err(_) => {
                        bail!("unsupported 'to' value {dt:?} for cast {}", node.name)

View on GitHub (pinned to d5fee525bf)

Solutions

  1. Densify sparse constants into regular tensors (onnx sparse_to_dense tooling) and re-export
  2. Rewrite the attribute to a Tensor via numpy_helper.from_array in the source graph
  3. Use onnxsim/onnx-optimizer to fold constants into initializers
  4. Patch candle-onnx to handle SPARSE_TENSOR and primitive attribute types

Example fix

// before: value attribute stored as sparse_tensor
// after
sparse = node.attribute[0].sparse_tensor
dense = onnx.helper.make_attribute('value', onnx.sparse_to_dense(sparse))
node.attribute.remove(node.attribute[0]); node.attribute.append(dense)
Defensive patterns

Strategy: validation

Validate before calling

for node in &model.graph.node {
    if node.op_type == "Constant" {
        if let Some(v) = node.attribute.iter().find(|a| a.name == "value") {
            if v.r#type() != AttributeType::Tensor {
                panic!("Constant node '{}': value type {:?} unsupported", node.name, v.r#type());
            }
        }
    }
}

Type guard

fn constant_is_tensor(node: &NodeProto) -> bool {
    node.attribute.iter()
        .find(|a| a.name == "value")
        .map(|v| v.r#type() == AttributeType::Tensor)
        .unwrap_or(false)
}

Try / catch

match candle_onnx::simple_eval(&model, &inputs) {
    Err(e) if e.to_string().contains("unsupported 'value' type") => {
        eprintln!("densify or retyped the Constant's value attribute: {e}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: A Constant node's `value` attribute exists but is typed as sparse tensor, graph, or a primitive list rather than a dense Tensor, so the match falls to the rtype catch-all.

Common situations: Models exported with sparse tensor constants; graphs embedding subgraph constants; converters that set value as a repeated float/int field while still naming the attribute 'value'.

Related errors


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