tracel-ai/burn · error

irfft: unsupported dtype {:?}

Error message

irfft: unsupported dtype {:?}

What it means

The burn-flex backend's `irfft` dispatches on the real-part spectrum tensor's dtype to a typed inverse-FFT kernel (F32, F64, F16, BF16). Any other dtype (integer, bool, quantized) has no inverse-FFT implementation, so the backend panics. Inverse FFT only supports floating-point spectra.

Source

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

            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),
        }
    }

    fn embedding(weights: FloatTensor<Flex>, indices: IntTensor<Flex>) -> FloatTensor<Flex> {
        let [batch_size, seq_length] = indices.shape().dims();
        let [_, d_model] = weights.shape().dims();

        let indices = Flex::int_reshape(indices, Shape::from(alloc::vec![batch_size * seq_length]));
        let output = Flex::float_select(weights, 0, indices);
        Flex::float_reshape(
            output,
            Shape::from(alloc::vec![batch_size, seq_length, d_model]),
        )
    }

    fn layer_norm(
        tensor: FloatTensor<Flex>,
        gamma: FloatTensor<Flex>,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast both spectrum_re and spectrum_im to a floating dtype: `.cast(DType::F32)` before irfft.
  2. Verify `spectrum_re.dtype()` is F32, F64, F16, or BF16.
  3. If the spectrum came from rfft output that was cast, keep it in its original float dtype.

Example fix

// before
let signal = spectrum_re_int.irfft(1, 1024);
// after
let signal = spectrum_re_int.cast(DType::F32)
    .irfft(1, 1024);
Defensive patterns

Strategy: validation

Validate before calling

assert!(matches!(spectrum_re.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), "irfft requires a float dtype, got {:?}", spectrum_re.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::irfft(dim, n)` (or `fft_irfft`) where the spectrum_re tensor dtype is not F32/F64/F16/BF16 — e.g. a spectrum produced/rounded through an integer dtype, or a quantized spectrum tensor.

Common situations: Persisting a spectrum to disk as ints and reloading without casting; passing an integer-valued spectrum computed manually; backend mismatches that strip the float dtype.

Related errors


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