tracel-ai/burn · error

rfft: unsupported dtype {:?}

Error message

rfft: unsupported dtype {:?}

What it means

The burn-flex backend's `rfft` dispatches on the input tensor's dtype to a typed FFT implementation (F32, F64, F16, BF16). If the tensor carries any other dtype (e.g. an integer or quantized dtype), no FFT kernel exists and the backend panics. FFT is only defined for floating-point inputs.

Source

Thrown at crates/burn-flex/src/ops/module.rs:743

        value: FloatTensor<Flex>,
        mask: Option<BoolTensor<Flex>>,
        attn_bias: Option<FloatTensor<Flex>>,
        options: AttentionModuleOptions,
    ) -> FloatTensor<Flex> {
        crate::ops::attention::attention(query, key, value, mask, attn_bias, options)
    }

    fn rfft(
        signal: FloatTensor<Flex>,
        dim: usize,
        n: Option<usize>,
    ) -> (FloatTensor<Flex>, FloatTensor<Flex>) {
        match signal.dtype() {
            DType::F32 => crate::ops::fft::rfft_f32(signal, dim, n),
            DType::F64 => crate::ops::fft::rfft_f64(signal, dim, n),
            DType::F16 => crate::ops::fft::rfft_f16(signal, dim, n),
            DType::BF16 => crate::ops::fft::rfft_bf16(signal, dim, n),
            dtype => panic!("rfft: unsupported dtype {:?}", dtype),
        }
    }

    fn irfft(
        spectrum_re: FloatTensor<Flex>,
        spectrum_im: FloatTensor<Flex>,
        dim: usize,
        n: Option<usize>,
    ) -> FloatTensor<Flex> {
        match spectrum_re.dtype() {
            DType::F32 => crate::ops::fft::irfft_f32(spectrum_re, spectrum_im, dim, n),
            DType::F64 => crate::ops::fft::irfft_f64(spectrum_re, spectrum_im, dim, n),
            DType::F16 => crate::ops::fft::irfft_f16(spectrum_re, spectrum_im, dim, n),
            DType::BF16 => crate::ops::fft::irfft_bf16(spectrum_re, spectrum_im, dim, n),
            dtype => panic!("irfft: unsupported dtype {:?}", dtype),
        }
    }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast the input tensor to a floating dtype before calling rfft: `tensor.cast(DType::F32)`.
  2. Check `tensor.dtype()` and ensure it is F32, F64, F16, or BF16.
  3. If the dtype came from data loading, add `.cast(YOUR_FLOAT_DTYPE)` right after tensor creation.

Example fix

// before
let spectrum = signal.rfft(1, 1024); // signal dtype = I64
// after
let spectrum = signal.cast(DType::F32).rfft(1, 1024);
Defensive patterns

Strategy: validation

Validate before calling

assert!(matches!(signal.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), "rfft requires a float dtype, got {:?}", signal.dtype());

Type guard

fn is_float_dtype(d: DType) -> bool {
    matches!(d, DType::F32 | DType::F64 | DType::F16 | DType::BF16)
}

Prevention

When it happens

Trigger: Calling `Tensor::rfft(dim, n)` (or the FloatTensorOperations `fft_rfft` entry) on a tensor whose dtype is not one of F32/F64/F16/BF16 — e.g. after casting a real-valued signal to an integer dtype, or passing a tensor with a DType::QFloat quantized dtype.

Common situations: Casting audio/signal tensors to int for storage and forgetting to cast back before FFT; mixing backends where an integer tensor leaks into a float-only op; using a dtype inferred from loaded data (e.g. i64 indices) instead of the model's float dtype.

Related errors


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