huggingface/candle · error
unsupported 'to' value {dt:?} for cast {}
Error message
unsupported 'to' value {dt:?} for cast {} What it means
This error is thrown when evaluating an ONNX Cast node whose 'to' attribute is an integer that candle-onnx cannot map to a supported candle DType. DataType::try_from either fails (the attribute is not a valid onnx DataType) or the mapped dtype has no candle equivalent (dtype() returns None). The library only supports casts to tensor element types it can represent.
Source
Thrown at candle-onnx/src/eval.rs:1121
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)
}
};
let output = input.to_dtype(dtype)?;
values.insert(node.output[0].clone(), output);
}
// https://github.com/onnx/onnx/blob/main/docs/Operators.md#CumSum
"CumSum" => {
let exclusive = get_attr_opt::<i64>(node, "exclusive")?
.copied()
.unwrap_or(0);
let reverse = get_attr_opt::<i64>(node, "reverse")?.copied().unwrap_or(0);
if exclusive != 0 {
bail!("only exclusive == 0 is supported in CumSum")
}View on GitHub (pinned to d5fee525bf)
Solutions
- Inspect the Cast node's 'to' attribute (e.g. with Netron or onnx python tools) and identify the unsupported dtype
- Pre-process the model to replace the cast with a supported dtype (e.g. via onnx python: convert the node's 'to' to int32/int64/float32)
- Export the model with an opset/dtype configuration candle-onnx supports (avoid bfloat16/float8/string casts)
- Convert the unsupported dtype conversion in the surrounding code outside the ONNX graph
- File/patch candle-onnx to add the missing DataType -> DType mapping in eval.rs
Example fix
// before (python, export-side) cast_node.attr['to'] = onnx.TensorProto.BFLOAT16 // after cast_node.attr['to'] = onnx.TensorProto.FLOAT
Defensive patterns
Strategy: validation
Validate before calling
fn is_supported_cast_to(to: i64) -> bool {
match onnx_pb::DataType::try_from(to as i32) {
Ok(onnx_pb::DataType::Int32) => true,
Ok(dt) => candle_onnx::eval::dtype(dt).is_some(),
Err(_) => false,
}
}
// assert every Cast node in the graph passes before eval Type guard
fn cast_dtype_supported(to: i64) -> Option<bool> {
onnx_pb::DataType::try_from(to as i32).ok().map(|dt| {
matches!(dt, onnx_pb::DataType::Int32) || candle_onnx::eval::dtype(dt).is_some()
})
} Prevention
- Inspect model Cast nodes with Netron before loading
- Export with opsets/dtypes known to map to candle DTypes (i32/i64/f32/f64/u8...)
- Avoid float8/bfloat16/string casts when exporting
- Run a graph lint that validates every Cast 'to' attribute
When it happens
Trigger: Evaluating a model containing a Cast node whose 'to' attribute is an invalid or unrepresentable onnx DataType enum value (e.g. DataType::Int32 is special-cased, but other types like STRING/BFLOAT16 variants without a candle mapping will fail).
Common situations: Running an ONNX model exported with newer opset/dtype support (e.g. float8, bfloat16, string casts) than candle-onnx implements; a malformed or hand-written Protobuf with a bogus 'to' attribute.
Related errors
- {} is a dummy type and cannot be constructed
- {} is a dummy type and cannot be converted
- {} is a dummy type and cannot be converted to scalar
- {} is a dummy type and does not support storage
- {} is a dummy type and does not support operations
AI-assisted analysis of huggingface/candle@d5fee525bf (2026-09-02).
Data as JSON: /api/errors/33ddb5af0e7af8ac.
Report an issue: GitHub.