{"record":{"id":"953da868e4ef55ed","repo":"tracel-ai/burn","slug":"should-be-int-got-quantized","errorCode":null,"errorMessage":"Should be int, got quantized","messagePattern":"Should be int, got quantized","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-dispatch/src/tensor.rs","lineNumber":66,"sourceCode":"    /// Returns the inner float tensor primitive.\n    pub fn as_float(&self) -> &B::FloatTensorPrimitive {\n        match self {\n            BackendTensor::Float(tensor) => tensor,\n            BackendTensor::Int(_) => panic!(\"Should be float, got int\"),\n            BackendTensor::Bool(_) => panic!(\"Should be float, got bool\"),\n            BackendTensor::Quantized(_) => panic!(\"Should be float, got quantized\"),\n            #[cfg(feature = \"autodiff\")]\n            BackendTensor::Autodiff(_) => panic!(\"Should be float, got autodiff\"),\n        }\n    }\n\n    /// 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.","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dispatch/src/tensor.rs#L48-L84","documentation":"BackendTensor::int() was called on a Quantized tensor handle. Quantized primitives live in their own variant and cannot be returned as an int primitive, so the code panics. A quantized tensor reached a code path that only handles integer tensors.","triggerScenarios":"Calling int() on a quantized tensor (int8/int4 quantized weights/activations); feeding quantized inference tensors into ops implemented for plain int primitives; forgetting to dequantize or treat the quantized variant separately.","commonSituations":"Quantized model runs where an op lacks a quantized kernel and falls into the int path; mixing quantized weights with int buffers in custom code; post-training-quantization pipelines that assume quantized tensors are plain ints.","solutions":["Dequantize the tensor before integer/float computation, or route it through the quantized op path (quantized())","Match the Quantized variant explicitly in kernels rather than calling int()","Check the producing op: quantized ops must output through quantized() consumers","Validate dtype/kind via TensorMetadata at the dispatch boundary"],"exampleFix":"// before\nlet value = handle.int(); // panics: Quantized variant\n// after\nlet value = match handle {\n    BackendTensor::Quantized(_) => handle.quantized(), // use the quantized path\n    _ => handle.int(),\n};","handlingStrategy":"type-guard","validationCode":"if matches!(handle, BackendTensor::Quantized(_)) {\n    let q = handle.quantized(); // use quantized path, not int()\n}","typeGuard":"fn is_quantized<B: BackendTypes>(t: &BackendTensor<B>) -> bool {\n    matches!(t, BackendTensor::Quantized(_))\n}","tryCatchPattern":null,"preventionTips":["Treat quantized tensors as their own kind, never as plain ints","Dequantize before int/float numeric paths","Verify quantized ops dispatch to quantized kernels"],"tags":["rust","panic","dtype-mismatch","quantization"],"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"}