{"record":{"id":"eb9ca37374e1f10d","repo":"tracel-ai/burn","slug":"expected-float-handle-got","errorCode":null,"errorMessage":"Expected float handle, got {}","messagePattern":"Expected float handle, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/backend.rs","lineNumber":176,"sourceCode":"            // Quantized types: storage only for now\n            DType::QFloat(scheme) if burn_std::quantization::quantizable(&scheme) => {\n                DTypeUsage::Storage.into()\n            }\n            DType::QFloat(_) => DTypeUsageSet::empty(),\n            _ => DTypeUsageSet::empty(),\n        }\n    }\n\n    fn flush(_device: &Self::Device) {}\n}\n\nimpl BackendIr for Flex {\n    type Handle = HandleKind<Self>;\n\n    fn float_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {\n        match handle.handle {\n            HandleKind::Float(t) => t,\n            _ => panic!(\"Expected float handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn int_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {\n        match handle.handle {\n            HandleKind::Int(t) => t,\n            _ => panic!(\"Expected int handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn bool_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {\n        match handle.handle {\n            HandleKind::Bool(t) => t,\n            _ => panic!(\"Expected bool handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn quantized_tensor(handle: TensorHandle<Self::Handle>) -> FlexQTensor {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/backend.rs#L158-L194","documentation":"`BackendIr::float_tensor` for the Flex backend unwraps a `TensorHandle` expecting its `HandleKind::Float` variant. If the handle holds any other kind (Int, Bool, Quantized, ...), the code panics with 'Expected float handle, got <name>'. This enforces dtype correctness at the backend IR boundary.","triggerScenarios":"A dispatched operation's backend-IR lowering calls `float_tensor()` on a handle produced by an op that actually returned an Int/Bool/Quantized tensor — usually because the op registry routed a float op to an int-producing kernel or the caller passed the wrong handle.","commonSituations":"Custom Flex ops returning the wrong handle kind, op signatures/handle types changed between versions, or mis-wired dispatch where a non-float result is fetched as float.","solutions":["Ensure the op producing the handle declares/returns a Float handle kind (fix the kernel or its output type).","Before converting, match on `handle.handle` and route each kind to the matching converter (`int_tensor`, `bool_tensor`, etc.).","Check the calling op's dtype planning so float ops only consume float handles."],"exampleFix":"// before\nlet t = BackendIr::float_tensor(handle); // panics if handle is Int\n// after\nlet t = match handle.handle {\n    HandleKind::Float(t) => t,\n    other => panic!(\"op returned {:?}, expected float\", other.name()),\n};","handlingStrategy":"type-guard","validationCode":"if !matches!(handle.handle, HandleKind::Float(_)) { /* route to correct converter */ }","typeGuard":"fn as_float_handle(t: HandleKind<Flex>) -> Option<FlexTensor> {\n    match t { HandleKind::Float(f) => Some(f), _ => None }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| Flex::float_tensor(handle.clone())));\nmatch result {\n    Ok(t) => use_float(t),\n    Err(_) => eprintln!(\"handle was not float\"),\n}","preventionTips":["Match on HandleKind before converting instead of assuming the dtype.","Keep op registrations aligned with the handle kinds their kernels return.","Log handle.kind names in custom kernels to catch dtype drift during development."],"tags":["rust","backend","handle","dtype-mismatch","panic"],"backgroundTag":"tensor-dtype-mismatch","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}