{"record":{"id":"0d5d6215cbc38e8e","repo":"tracel-ai/burn","slug":"expected-quantized-handle-got","errorCode":null,"errorMessage":"Expected quantized handle, got {}","messagePattern":"Expected quantized handle, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/backend.rs","lineNumber":197,"sourceCode":"\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 {\n        match handle.handle {\n            HandleKind::Quantized(t) => t,\n            _ => panic!(\"Expected quantized handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn float_tensor_handle(tensor: FlexTensor) -> Self::Handle {\n        HandleKind::Float(tensor)\n    }\n\n    fn int_tensor_handle(tensor: FlexTensor) -> Self::Handle {\n        HandleKind::Int(tensor)\n    }\n\n    fn bool_tensor_handle(tensor: FlexTensor) -> Self::Handle {\n        HandleKind::Bool(tensor)\n    }\n\n    fn quantized_tensor_handle(tensor: FlexQTensor) -> Self::Handle {\n        HandleKind::Quantized(tensor)\n    }","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/backend.rs#L179-L215","documentation":"`BackendIr::quantized_tensor` for the Flex backend unwraps a `TensorHandle` expecting `HandleKind::Quantized`. Any other handle kind causes a panic with 'Expected quantized handle, got <name>'. Quantized inference ops therefore can never silently receive float/int/bool handles.","triggerScenarios":"Calling `quantized_tensor()` on a handle produced by a non-quantized kernel — e.g. a quantized conv/matmul was lowered to a plain float kernel, or a float tensor was passed where a pre-quantized handle was required.","commonSituations":"Quantized model pipelines where packing/quantization kernels were skipped or mis-registered, or calling quantized ops on tensors that were never quantized (missing quantize step).","solutions":["Quantize the input first so the kernel produces a `HandleKind::Quantized` handle before invoking quantized ops.","Fix the op registration so quantized ops map to kernels returning quantized handles.","Match on the handle kind at the call site and route non-quantized handles to the regular (float) op path."],"exampleFix":"// before\nlet q = BackendIr::quantized_tensor(handle); // panics: got float\n// after\nlet q = match handle.handle {\n    HandleKind::Quantized(t) => t,\n    HandleKind::Float(f) => f.quantize(params), // quantize before use\n    other => panic!(\"unexpected handle {}\", other.name()),\n};","handlingStrategy":"type-guard","validationCode":"if !matches!(handle.handle, HandleKind::Quantized(_)) { /* quantize first or use float path */ }","typeGuard":"fn as_quantized_handle(t: HandleKind<Flex>) -> Option<FlexQTensor> {\n    match t { HandleKind::Quantized(q) => Some(q), _ => None }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| Flex::quantized_tensor(handle.clone())));\nmatch result {\n    Ok(q) => use_quantized(q),\n    Err(_) => eprintln!(\"handle was not quantized\"),\n}","preventionTips":["Always run the quantize/pack step before quantized ops so handles carry HandleKind::Quantized.","Register quantized ops only to kernels that return quantized handles.","Fall back to the float op path when the input handle is not quantized."],"tags":["rust","backend","quantization","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"}