{"record":{"id":"33ddb5af0e7af8ac","repo":"huggingface/candle","slug":"unsupported-to-value-dt-for-cast","errorCode":null,"errorMessage":"unsupported 'to' value {dt:?} for cast {}","messagePattern":"unsupported 'to' value (.+?) for cast (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-onnx/src/eval.rs","lineNumber":1121,"sourceCode":"                    AttributeType::Tensor => {\n                        let t = value.t.as_ref().unwrap();\n                        get_tensor(t, &node.name)?\n                    }\n                    rtype => bail!(\"unsupported 'value' type {rtype:?} for {}\", node.name),\n                };\n\n                values.insert(node.output[0].clone(), output);\n            }\n            // https://github.com/onnx/onnx/blob/main/docs/Operators.md#Cast\n            \"Cast\" => {\n                let input = get(&node.input[0])?;\n                let dt: i64 = *get_attr(node, \"to\")?;\n                let dtype = match DataType::try_from(dt as i32) {\n                    Ok(DataType::Int32) => DType::I64,\n                    Ok(dt) => match dtype(dt) {\n                        Some(dt) => dt,\n                        None => {\n                            bail!(\"unsupported 'to' value {dt:?} for cast {}\", node.name)\n                        }\n                    },\n                    Err(_) => {\n                        bail!(\"unsupported 'to' value {dt:?} for cast {}\", node.name)\n                    }\n                };\n                let output = input.to_dtype(dtype)?;\n                values.insert(node.output[0].clone(), output);\n            }\n            // https://github.com/onnx/onnx/blob/main/docs/Operators.md#CumSum\n            \"CumSum\" => {\n                let exclusive = get_attr_opt::<i64>(node, \"exclusive\")?\n                    .copied()\n                    .unwrap_or(0);\n                let reverse = get_attr_opt::<i64>(node, \"reverse\")?.copied().unwrap_or(0);\n                if exclusive != 0 {\n                    bail!(\"only exclusive == 0 is supported in CumSum\")\n                }","sourceCodeStart":1103,"sourceCodeEnd":1139,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-onnx/src/eval.rs#L1103-L1139","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before (python, export-side)\ncast_node.attr['to'] = onnx.TensorProto.BFLOAT16\n// after\ncast_node.attr['to'] = onnx.TensorProto.FLOAT","handlingStrategy":"validation","validationCode":"fn is_supported_cast_to(to: i64) -> bool {\n    match onnx_pb::DataType::try_from(to as i32) {\n        Ok(onnx_pb::DataType::Int32) => true,\n        Ok(dt) => candle_onnx::eval::dtype(dt).is_some(),\n        Err(_) => false,\n    }\n}\n// assert every Cast node in the graph passes before eval","typeGuard":"fn cast_dtype_supported(to: i64) -> Option<bool> {\n    onnx_pb::DataType::try_from(to as i32).ok().map(|dt| {\n        matches!(dt, onnx_pb::DataType::Int32) || candle_onnx::eval::dtype(dt).is_some()\n    })\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["onnx","cast","unsupported-dtype","rust"],"backgroundTag":"unsupported-dtype-cast","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}