tracel-ai/burn · error

Quantized float is not supported

Error message

Quantized float is not supported

What it means

burn-vision's erode() for Float tensors rejects quantized (DType::QFloat) inputs with unimplemented!(). The morphological erode kernel (float_erode on the Dispatch backend) is only implemented for native float dtypes, so quantized tensors are explicitly refused instead of producing wrong results.

Source

Thrown at crates/burn-vision/src/tensor.rs:96

            settings.int_dtype,
        );

        let stats = ConnectedStats {
            area: Tensor::from_dispatch(stats.area),
            left: Tensor::from_dispatch(stats.left),
            top: Tensor::from_dispatch(stats.top),
            right: Tensor::from_dispatch(stats.right),
            bottom: Tensor::from_dispatch(stats.bottom),
            max_label: Tensor::from_dispatch(stats.max_label),
        };
        (Tensor::from_dispatch(labels), stats)
    }
}

impl Morphology for Tensor<3, Float> {
    fn erode(self, kernel: Tensor<2, Bool>, opts: MorphOptions) -> Self {
        if matches!(self.dtype(), DType::QFloat(_)) {
            unimplemented!("Quantized float is not supported");
        }

        let out = <Dispatch as FloatVisionOps>::float_erode(
            self.into_dispatch(),
            kernel.into_dispatch(),
            opts,
        );
        Tensor::from_dispatch(out)
    }

    fn dilate(self, kernel: Tensor<2, Bool>, opts: MorphOptions) -> Self {
        if matches!(self.dtype(), DType::QFloat(_)) {
            unimplemented!("Quantized float is not supported");
        }

        let out = <Dispatch as FloatVisionOps>::float_dilate(
            self.into_dispatch(),
            kernel.into_dispatch(),

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Dequantize the tensor before calling erode: `tensor.dequantize()` (or convert to a native float dtype) and call erode on the resulting float tensor.
  2. Call erode on an Int tensor instead — the `impl Morphology for Tensor<3, Int>` path has no quantization restriction.
  3. Quantize/erode/dequantize around the op: perform morphology on the float model output before the quantized stage of the pipeline.

Example fix

// before
let eroded = quantized_tensor.erode(&kernel, opts); // panics: unimplemented!
// after
let float_tensor = quantized_tensor.dequantize();
let eroded = float_tensor.erode(&kernel, opts);
Defensive patterns

Strategy: validation

Validate before calling

if matches!(tensor.dtype(), burn::tensor::DType::QFloat(_)) {
    tensor = tensor.dequantize(); // convert to native float before erode
}
let eroded = tensor.erode(kernel, opts);

Type guard

fn is_quantized(t: &Tensor<3>) -> bool {
    matches!(t.dtype(), burn::tensor::DType::QFloat(_))
}

Prevention

When it happens

Trigger: Calling `tensor.erode(kernel, opts)` on a Tensor<3, Float> whose dtype is DType::QFloat(_), i.e. a tensor produced by quantization (e.g. loaded from a quantized model checkpoint or converted via calibration).

Common situations: Running vision preprocessing/postprocessing (OpenCV-style morphology) on tensors that come out of a quantized inference pipeline; passing a quantized activation tensor directly into erode instead of dequantizing first.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/b32ca2b997e3a2d3. Report an issue: GitHub.