{"record":{"id":"9861408cc9a11f65","repo":"tracel-ai/burn","slug":"should-be-bool-got-quantized","errorCode":null,"errorMessage":"Should be bool, got quantized","messagePattern":"Should be bool, got quantized","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-dispatch/src/tensor.rs","lineNumber":78,"sourceCode":"    /// Returns the inner int tensor primitive.\n    pub fn int(self) -> B::IntTensorPrimitive {\n        match self {\n            BackendTensor::Int(tensor) => tensor,\n            BackendTensor::Float(_) => panic!(\"Should be int, got float\"),\n            BackendTensor::Bool(_) => panic!(\"Should be int, got bool\"),\n            BackendTensor::Quantized(_) => panic!(\"Should be int, got quantized\"),\n            #[cfg(feature = \"autodiff\")]\n            BackendTensor::Autodiff(_) => panic!(\"Should be int, got autodiff\"),\n        }\n    }\n\n    /// Returns the inner bool tensor primitive.\n    pub fn bool(self) -> B::BoolTensorPrimitive {\n        match self {\n            BackendTensor::Bool(tensor) => tensor,\n            BackendTensor::Float(_) => panic!(\"Should be bool, got float\"),\n            BackendTensor::Int(_) => panic!(\"Should be bool, got int\"),\n            BackendTensor::Quantized(_) => panic!(\"Should be bool, got quantized\"),\n            #[cfg(feature = \"autodiff\")]\n            BackendTensor::Autodiff(_) => panic!(\"Should be bool, got autodiff\"),\n        }\n    }\n\n    /// Returns the inner quantized tensor primitive.\n    pub fn quantized(self) -> B::QuantizedTensorPrimitive {\n        match self {\n            BackendTensor::Quantized(tensor) => tensor,\n            _ => unreachable!(),\n        }\n    }\n\n    #[cfg(feature = \"autodiff\")]\n    /// Returns the inner autodiff tensor primitive.\n    pub fn autodiff(self) -> FloatTensor<Autodiff<B>> {\n        match self {\n            BackendTensor::Autodiff(tensor) => tensor,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dispatch/src/tensor.rs#L60-L96","documentation":"`BackendTensor::bool()` extracts the inner bool tensor primitive from the `BackendTensor` enum. When the wrapper actually holds a quantized tensor, no bool primitive exists to return, so the code panics with 'Should be bool, got quantized'. This prevents silently reading a quantized payload as a bool tensor.","triggerScenarios":"Calling `BackendTensor::bool()` on a wrapper whose inner variant is `BackendTensor::Quantized(_)` — typically when pulling results from a quantized kernel or reinterpreting a quantized tensor output as bool.","commonSituations":"Working with quantized inference backends where op outputs are quantized tensors but downstream code (e.g. mask/condition handling) assumes bool; often an upstream op-selection or dtype-planning mistake.","solutions":["Dequantize the quantized tensor (or recompute the op in bool dtype) before accessing it as bool.","Match on `BackendTensor` variants and reject/handle the Quantized case explicitly.","Fix the upstream op dispatch so the operation produces a bool tensor instead of a quantized one."],"exampleFix":"// before\nlet b = qtensor.bool(); // panics: got quantized\n// after\nlet float = qtensor.quantized().dequantize();\nlet b = float.greater_elem(0); // bool tensor from a proper op","handlingStrategy":"type-guard","validationCode":"if !matches!(tensor, BackendTensor::Bool(_)) { /* dequantize or recompute before .bool() */ }","typeGuard":"fn is_bool_tensor<B: Backend>(t: &BackendTensor<B>) -> bool {\n    matches!(t, BackendTensor::Bool(_))\n}","tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| tensor.clone().bool()));\nmatch result {\n    Ok(b) => use_bool(b),\n    Err(_) => eprintln!(\"tensor was quantized, not bool\"),\n}","preventionTips":["Keep quantized tensors in dedicated types; never route them through generic bool accessors.","Dequantize immediately after quantized kernels and re-tag dtypes.","Audit quantized inference pipelines for downstream consumers assuming bool outputs."],"tags":["rust","tensor","quantization","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"}