{"record":{"id":"bdcb646c458d3965","repo":"tracel-ai/burn","slug":"quantization-scheme-is-not-valid-for-dtype-other","errorCode":null,"errorMessage":"Quantization scheme is not valid for dtype {other:?}","messagePattern":"Quantization scheme is not valid for dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-backend/src/backend/primitive.rs","lineNumber":104,"sourceCode":"    fn device(&self) -> Self::Device;\n\n    /// Whether the tensor's buffer can be mutated in place — i.e. this handle\n    /// uniquely owns it, so an in-place op (`slice_assign`, an inplace kernel)\n    /// writes the existing allocation instead of copying it first.\n    ///\n    /// Backends that track buffer ownership (cubecl, fusion, tch) answer\n    /// precisely; a backend that can't must return a conservative `false` —\n    /// the buffer may be aliased, so an in-place write can't be assumed safe.\n    fn can_mut(&self) -> bool;\n\n    /// Get the [quantization scheme](QuantScheme) for a quantized float tensor.\n    ///\n    /// # Panics\n    /// Panics if the tensor is not quantized.\n    fn scheme(&self) -> QuantScheme {\n        match self.dtype() {\n            DType::QFloat(scheme) => scheme,\n            other => panic!(\"Quantization scheme is not valid for dtype {other:?}\"),\n        }\n    }\n}\n","sourceCodeStart":86,"sourceCodeEnd":108,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-backend/src/backend/primitive.rs#L86-L108","documentation":"`TensorData::scheme()` returns the `QuantScheme` for quantized tensors. It matches on the tensor's dtype and expects `DType::QFloat(scheme)`; any other dtype (F32, U8, etc.) triggers this panic. Calling `scheme()` on a non-quantized tensor is an API misuse, since the method is documented to panic unless the tensor is quantized.","triggerScenarios":"Calling `.scheme()` on a tensor whose `dtype()` is anything other than `DType::QFloat(_)` — e.g. a float tensor loaded from a checkpoint that was never quantized, or after calling a dequantize/convert op that changed the dtype away from QFloat.","commonSituations":"Reading quantization metadata from a tensor that was dequantized earlier; mixing quantized and non-quantized layers when inspecting model parameters; loading weights with a dtype change; assuming all int8 tensors are quantized (U8 dtype vs QFloat).","solutions":["Check `tensor.dtype()` first and only call `scheme()` when it matches `DType::QFloat(_)`, or use the defensive match shown in the source.","Ensure the tensor actually went through a quantization op (`quantize`/`quantize_dynamic`) before querying its scheme.","If you need the scheme from a model, inspect the module's quantization state/config rather than a dequantized tensor."],"exampleFix":"// before\nlet scheme = tensor.scheme(); // panics for F32 tensors\n\n// after\nlet scheme = match tensor.dtype() {\n    burn::tensor::DType::QFloat(s) => s,\n    other => panic!(\"expected quantized tensor, got {other:?}\"),\n};","handlingStrategy":"type-guard","validationCode":"// only query scheme on quantized tensors\nif matches!(tensor.dtype(), burn::tensor::DType::QFloat(_)) {\n    let scheme = tensor.scheme();\n}","typeGuard":"fn quantized_dtype(dtype: &burn::tensor::DType) -> Option<burn::tensor::QuantScheme> {\n    match dtype {\n        burn::tensor::DType::QFloat(s) => Some(*s),\n        _ => None,\n    }\n}","tryCatchPattern":"// panics are not catchable idiomatically here; use the guard instead\n// but if needed:\nlet scheme = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| tensor.scheme()))\n    .ok(); // None => tensor was not quantized","preventionTips":["Check `dtype()` before any quantization-metadata accessor.","Track which pipeline stages quantize/dequantize tensors.","Never assume an int8-looking tensor is QFloat-quantized."],"tags":["quantization","dtype","panic","burn"],"backgroundTag":"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"}