{"record":{"id":"7cba6b199800b9e8","repo":"tracel-ai/burn","slug":"expected-quantized-handle-got-7cba6b","errorCode":null,"errorMessage":"Expected quantized handle, got {}","messagePattern":"Expected quantized handle, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/backend.rs","lineNumber":158,"sourceCode":"\n    fn int_tensor(handle: TensorHandle<Self::Handle>) -> IntTensor<Self> {\n        match handle.handle {\n            HandleKind::Int(handle) => handle,\n            _ => panic!(\"Expected int handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn bool_tensor(handle: TensorHandle<Self::Handle>) -> BoolTensor<Self> {\n        match handle.handle {\n            HandleKind::Bool(handle) => handle,\n            _ => panic!(\"Expected bool handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn quantized_tensor(handle: TensorHandle<Self::Handle>) -> QuantizedTensor<Self> {\n        match handle.handle {\n            HandleKind::Quantized(handle) => handle,\n            _ => panic!(\"Expected quantized handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn float_tensor_handle(tensor: FloatTensor<Self>) -> Self::Handle {\n        HandleKind::Float(tensor)\n    }\n\n    fn int_tensor_handle(tensor: IntTensor<Self>) -> Self::Handle {\n        HandleKind::Int(tensor)\n    }\n\n    fn bool_tensor_handle(tensor: BoolTensor<Self>) -> Self::Handle {\n        HandleKind::Bool(tensor)\n    }\n\n    fn quantized_tensor_handle(tensor: QuantizedTensor<Self>) -> Self::Handle {\n        HandleKind::Quantized(tensor)\n    }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/backend.rs#L140-L176","documentation":"`NdArray::quantized_tensor` (BackendIr) panics when the TensorHandle's `HandleKind` is not `HandleKind::Quantized` — the runtime tried to materialize a quantized tensor primitive from a Float, Int, or Bool handle. This conversion is on the path for quantized ops (dq/qdq), so it means a quantized-typed TensorIr received a non-quantized resource.","triggerScenarios":"Calling `NdArray::quantized_tensor(handle)` (or `get_quantized_tensor`) with a handle registered as Float, Int, or Bool; e.g. running a quantized op on a tensor that was never quantized.","commonSituations":"Quantized model import where a tensor skipped its quantize step; mismatch between the declared quantized TensorKind and the actual stored handle in custom IR/graph code; accidental use of quantized APIs on regular tensors.","solutions":["Quantize the tensor before the quantized op (use the backend's quantize/dequantize ops) so a Quantized handle exists.","Fix the TensorKind in the TensorIr/description so it matches the handle actually stored.","Use the correct accessor (`float_tensor`/`int_tensor`) for non-quantized handles in custom backend code.","Check the model-import graph for ops whose outputs were declared quantized but produced plain tensors."],"exampleFix":"// before\nlet out = NdArray::quantized_tensor(float_handle); // panics\n// after\nlet q = NdArray::quantize(float_tensor, &scheme, &qparams);\nlet out = NdArray::quantized_tensor(handle_of(q));","handlingStrategy":"type-guard","validationCode":"fn ensure_quantized(t: &TensorIr) -> Result<(), String> {\n    (t.kind == TensorKind::Quantized)\n        .then_some(())\n        .ok_or_else(|| format!(\"expected quantized tensor, got kind {:?}\", t.kind))\n}","typeGuard":"fn as_quantized_handle(h: HandleKind<NdArray>) -> Option<QArray> {\n    match h { HandleKind::Quantized(q) => Some(q), _ => None }\n}","tryCatchPattern":"let q = std::panic::catch_unwind(|| NdArray::quantized_tensor(th))\n    .map_err(|_| anyhow!(\"handle is not quantized; expected {}\", th.handle.name()))?;","preventionTips":["Quantize tensors before running quantized ops; never feed plain float/int tensors","Verify the import/export graph marks quantized tensors as TensorKind::Quantized","Keep qdq boundaries explicit in your model conversion pipeline","Test quantized flows end-to-end after model import changes"],"tags":["panic","burn","ndarray","backend","handle-mismatch","quantization"],"backgroundTag":"handle-kind-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"}