{"record":{"id":"60d7148090648e0b","repo":"tracel-ai/burn","slug":"expected-quantized-dtype-got","errorCode":null,"errorMessage":"Expected quantized dtype, got {:?}","messagePattern":"Expected quantized dtype, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/qtensor.rs","lineNumber":46,"sourceCode":"    );\n    blocks\n}\n\n/// The largest magnitude in each block of `values`, laid out as `blocks`.\nfn block_max_abs(values: &[f32], blocks: &BlockLayout) -> Vec<f32> {\n    let mut peaks = alloc::vec![0.0f32; blocks.num_blocks()];\n    for (index, &x) in values.iter().enumerate() {\n        let peak = &mut peaks[blocks.block_of(index)];\n        *peak = peak.max(x.abs());\n    }\n    peaks\n}\n\nimpl QTensorOps<Flex> for Flex {\n    fn q_from_data(data: TensorData, _device: &Device<Flex>) -> QuantizedTensor<Flex> {\n        let scheme = match data.dtype {\n            DType::QFloat(scheme) => scheme,\n            _ => panic!(\"Expected quantized dtype, got {:?}\", data.dtype),\n        };\n\n        let shape = data.shape.clone();\n\n        let q_bytes = QuantizedBytes {\n            shape: shape.clone(),\n            bytes: data.into_bytes(),\n            scheme,\n        };\n\n        let (values, qparams) = q_bytes.into_vec_i8();\n        let tensor_data = TensorData::new(values, shape);\n        let tensor = FlexTensor::from_data(tensor_data);\n\n        // Use native storage since we've unpacked to i8\n        let scheme = scheme.with_store(QuantStore::Native);\n\n        FlexQTensor::new(tensor, scheme, qparams.block, qparams.global)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/qtensor.rs#L28-L64","documentation":"`q_from_data` in burn-flex requires `TensorData` whose `dtype` is `DType::QFloat(scheme)`, which carries the quantization scheme (mode, symmetrical, scale). Any plain float/int dtype means the data is not quantized, so the backend panics instead of silently quantizing.","triggerScenarios":"Calling `Tensor::from_data`/`q_from_data` (QuantizedTensor creation) with TensorData produced from plain f32/f16 buffers, or data loaded from a file that was not exported with quantization metadata.","commonSituations":"Loading quantized model weights from a format that stores scales separately, yielding plain float data; calling the quantized tensor constructor instead of the regular float constructor by mistake; migrating between burn versions where quantization metadata handling changed.","solutions":["Construct TensorData with a quantized dtype: use `TensorData::quantized::<YourDType>(values, shape, scheme)` or attach the QFloat scheme before calling q_from_data.","If the data is meant to be plain float, use the regular (non-quantized) tensor constructor instead.","Verify the source of the data exports the quantization scheme (scale/mode); re-export if missing."],"exampleFix":"// before\nlet q = QTensor::from_data(TensorData::from(values_f32).convert::<bf16>());\n// after\nlet data = TensorData::quantized::<bf16>(values, shape, QuantScheme::default());\nlet q = QTensor::from_data(data);","handlingStrategy":"type-guard","validationCode":"assert!(matches!(data.dtype, DType::QFloat(_)), \"q_from_data requires quantized TensorData, got {:?}\", data.dtype);","typeGuard":"fn as_quantized_dtype(d: DType) -> Option<QuantScheme> {\n    match d { DType::QFloat(s) => Some(s), _ => None }\n}","tryCatchPattern":null,"preventionTips":["Build quantized data with TensorData::quantized (or attach the QFloat scheme) before q_from_data.","Use the regular float tensor constructor for non-quantized data.","Verify weight-export tooling preserves quantization scheme metadata."],"tags":["rust","burn","quantization","dtype","panic"],"backgroundTag":"expected-quantized-dtype","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"}