{"record":{"id":"289d2171e21d6d14","repo":"tracel-ai/burn","slug":"invalid-dtype-expected-dtype-qfloat-got-289d21","errorCode":null,"errorMessage":"Invalid dtype (expected DType::QFloat, got {:?})","messagePattern":"Invalid dtype \\(expected DType::QFloat, got (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/ops/qtensor.rs","lineNumber":75,"sourceCode":"                    }\n                    QuantScheme {\n                        value:\n                            QuantValue::Q4F\n                            | QuantValue::Q4S\n                            | QuantValue::Q2F\n                            | QuantValue::Q2S\n                            | QuantValue::E2M1\n                            | QuantValue::E4M3\n                            | QuantValue::E5M2,\n                        ..\n                    }\n                    | QuantScheme {\n                        mode: QuantMode::Lookup,\n                        ..\n                    } => unimplemented!(\"from_data not supported for scheme {scheme:?}\"),\n                }\n            }\n            _ => panic!(\n                \"Invalid dtype (expected DType::QFloat, got {:?})\",\n                data.dtype\n            ),\n        }\n    }\n\n    fn quantize(\n        tensor: FloatTensor<Self>,\n        scheme: &QuantScheme,\n        qparams: QuantizationParametersPrimitive<Self>,\n    ) -> QuantizedTensor<Self> {\n        let shape = tensor.shape();\n        let data_f = tensor.into_data();\n        let scales = qparams.scales.into_data().convert::<f32>();\n        // Quantize against the scale that will actually be stored, so a save/load round trip\n        // reproduces these values instead of drifting by the scale dtype's rounding error.\n        let scales: Vec<f32> = scales\n            .iter::<f32>()","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/ops/qtensor.rs#L57-L93","documentation":"q_from_data constructs a quantized ndarray tensor and requires the input TensorData to carry quantization metadata, i.e. dtype must be DType::QFloat. If the data blob is a plain float tensor without quantization parameters, it panics.","triggerScenarios":"Calling burn_ndarray::NdArray::q_from_data (or loading a quantized tensor) with TensorData whose dtype is F32/F16/I8 etc. instead of QFloat.","commonSituations":"Exporting/importing quantized models where the calibration parameters (scale/offset scheme) were not attached to the tensor data, or loading a float checkpoint into a quantized tensor slot.","solutions":["Ensure the TensorData is created with quantization metadata so its dtype is DType::QFloat (e.g. quantize with burn-core quantization helpers first)","Check the model export path produces QFloat dtype for quantized weights","Use from_data for plain (non-quantized) tensors instead of q_from_data"],"exampleFix":"// before\nlet q = NdArray::<f32>::q_from_data(float_data.into(), device); // panics: dtype F32\n// after\nlet qdata = quantize_data(float_data, QuantScheme::default()); // yields DType::QFloat\nlet q = NdArray::<f32>::q_from_data(qdata.into(), device);","handlingStrategy":"type-guard","validationCode":"if data.dtype != DType::QFloat {\n    return Err(format!(\"q_from_data needs QFloat, got {:?}\", data.dtype));\n}","typeGuard":"fn is_quantized_data(data: &TensorData) -> bool {\n    data.dtype == DType::QFloat\n}","tryCatchPattern":null,"preventionTips":["Quantize tensors with burn's quantization helpers before calling q_from_data","Check TensorData.dtype when loading exported artifacts"],"tags":["rust","burn-ndarray","quantization","dtype"],"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"}