{"record":{"id":"fd902ba6a1aaad8b","repo":"tracel-ai/burn","slug":"invalid-dtype-expected-dtype-qfloat-got","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-cubecl/src/ops/qtensor.rs","lineNumber":245,"sourceCode":"                        | QuantValue::Q4F\n                        | QuantValue::Q4S\n                        | QuantValue::Q2F\n                        | QuantValue::Q2S\n                        | QuantValue::E4M3\n                        | QuantValue::E5M2\n                        | QuantValue::E2M1,\n                    ..\n                } => {\n                    // TensorData quantized representation is the same, with multiple quantized values\n                    // packed into u32 and quantization parameters appended to the bytes\n                    new_qtensor_optimized(data.bytes, data.shape.clone(), scheme, device)\n                }\n                QuantScheme {\n                    mode: QuantMode::Lookup,\n                    ..\n                } => unimplemented!(\"lookup quantization does not travel as a QFloat tensor\"),\n            },\n            _ => panic!(\n                \"Invalid dtype (expected DType::QFloat, got {:?})\",\n                data.dtype\n            ),\n        }\n    }\n\n    // TODO: quantize_dynamic (we can compute min-max on the fly and scale, especially when not per-tensor)\n\n    fn quantize(\n        tensor: FloatTensor<Self>,\n        scheme: &QuantScheme,\n        qparams: QuantizationParametersPrimitive<Self>,\n    ) -> QuantizedTensor<Self> {\n        // The kernel reads this at the scheme's scale dtype, not the tensor's actual dtype.\n        if let Some(global) = &qparams.global {\n            assert_eq!(\n                global.dtype,\n                DType::F32,","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-cubecl/src/ops/qtensor.rs#L227-L263","documentation":"q_from_data constructs a quantized tensor from raw data and expects the data's dtype to be DType::QFloat, which carries the quantization scheme. Any other dtype means the data is not a self-describing quantized payload, so the library panics. Lookup-mode quantization is additionally unimplemented for QFloat transport.","triggerScenarios":"Calling q_from_data with QuantTensorData whose dtype is a plain F32/F16/I8 etc. instead of QFloat; or with a Lookup-mode quant scheme, which hits an unimplemented! path.","commonSituations":"Loading quantized weights from a file that saved the scales/vals separately as regular tensors and re-wrapping them incorrectly, or version mismatches where the serializer dropped the QFloat dtype metadata.","solutions":["Ensure the data was created through the quantized API so its dtype is DType::QFloat","If you have raw data + scheme, build the tensor with new_qtensor instead of q_from_data","Convert/cast the payload into a QFloat dtype carrying the intended QuantScheme","Avoid Lookup-mode schemes for tensors that must travel as QFloat; use a different QuantMode"],"exampleFix":"// before: plain f32 data\nq_from_data(TensorData::from(vec![0.1f32, 0.2]), device); // panics\n// after: quantize into QFloat data first\nlet qt = Tensor::from_data(data, &device).quantize(&scheme);\nq_from_data(qt.into_data(), &device);","handlingStrategy":"type-guard","validationCode":"assert_eq!(data.dtype, DType::QFloat, \"q_from_data requires QFloat data\");","typeGuard":"fn is_qfloat(data: &TensorData) -> bool { data.dtype == DType::QFloat }","tryCatchPattern":null,"preventionTips":["Produce tensor data only through the quantize APIs so dtype stays QFloat","Avoid Lookup-mode schemes for tensors serialized as QFloat","Check dtype metadata when loading quantized checkpoints before reconstructing"],"tags":["quantization","dtype","burn"],"backgroundTag":"invalid-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"}