tracel-ai/burn · error
Invalid dtype (expected DType::QFloat, got {:?})
Error message
Invalid dtype (expected DType::QFloat, got {:?}) What it means
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.
Source
Thrown at crates/burn-ndarray/src/ops/qtensor.rs:75
}
QuantScheme {
value:
QuantValue::Q4F
| QuantValue::Q4S
| QuantValue::Q2F
| QuantValue::Q2S
| QuantValue::E2M1
| QuantValue::E4M3
| QuantValue::E5M2,
..
}
| QuantScheme {
mode: QuantMode::Lookup,
..
} => unimplemented!("from_data not supported for scheme {scheme:?}"),
}
}
_ => panic!(
"Invalid dtype (expected DType::QFloat, got {:?})",
data.dtype
),
}
}
fn quantize(
tensor: FloatTensor<Self>,
scheme: &QuantScheme,
qparams: QuantizationParametersPrimitive<Self>,
) -> QuantizedTensor<Self> {
let shape = tensor.shape();
let data_f = tensor.into_data();
let scales = qparams.scales.into_data().convert::<f32>();
// Quantize against the scale that will actually be stored, so a save/load round trip
// reproduces these values instead of drifting by the scale dtype's rounding error.
let scales: Vec<f32> = scales
.iter::<f32>()View on GitHub (pinned to d16f7ba2ed)
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
Example fix
// before let q = NdArray::<f32>::q_from_data(float_data.into(), device); // panics: dtype F32 // after let qdata = quantize_data(float_data, QuantScheme::default()); // yields DType::QFloat let q = NdArray::<f32>::q_from_data(qdata.into(), device);
Defensive patterns
Strategy: type-guard
Validate before calling
if data.dtype != DType::QFloat {
return Err(format!("q_from_data needs QFloat, got {:?}", data.dtype));
} Type guard
fn is_quantized_data(data: &TensorData) -> bool {
data.dtype == DType::QFloat
} Prevention
- Quantize tensors with burn's quantization helpers before calling q_from_data
- Check TensorData.dtype when loading exported artifacts
When it happens
Trigger: Calling burn_ndarray::NdArray::q_from_data (or loading a quantized tensor) with TensorData whose dtype is F32/F16/I8 etc. instead of QFloat.
Common situations: 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.
Related errors
- ctc_loss_backward: 2 * max_target_len + 1 = {} exceeds the k
- Should be float, got quantized
- Expected quantized dtype, got {:?}
- Optional argument type mismatch
- Data type mismatch
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/289d2171e21d6d14.
Report an issue: GitHub.