tracel-ai/burn · error

conv1d: unsupported dtype {:?}

Error message

conv1d: unsupported dtype {:?}

What it means

conv1d in the burn-flex module ops dispatches on the input tensor's dtype to a per-dtype conv implementation, supporting only F32, F64, F16, and BF16. If the input tensor carries any other dtype (integer, bool, float8, etc.), the catch-all arm panics with this message. Convolution kernels only exist for float dtypes, so integer input is never valid here.

Source

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

    let half_data: alloc::vec::Vec<E> = data.iter().map(|&v| from_f32(v)).collect();
    let bytes = Bytes::from_elems(half_data);
    FlexTensor::new(bytes, Layout::contiguous(shape), E::dtype())
}

impl ModuleOps<Flex> for Flex {
    fn conv1d(
        x: FloatTensor<Flex>,
        weight: FloatTensor<Flex>,
        bias: Option<FloatTensor<Flex>>,
        options: ConvOptions<1>,
    ) -> FloatTensor<Flex> {
        let (x, options) = pad_asymmetric_conv_input::<Flex, 1>(x, options);
        match x.dtype() {
            DType::F32 => conv::conv1d_f32(x, weight, bias, &options),
            DType::F64 => conv::conv1d_f64(x, weight, bias, &options),
            DType::F16 => conv::conv1d_f16(x, weight, bias, &options),
            DType::BF16 => conv::conv1d_bf16(x, weight, bias, &options),
            dtype => panic!("conv1d: unsupported dtype {:?}", dtype),
        }
    }

    fn conv2d(
        x: FloatTensor<Flex>,
        weight: FloatTensor<Flex>,
        bias: Option<FloatTensor<Flex>>,
        options: ConvOptions<2>,
    ) -> FloatTensor<Flex> {
        let (x, options) = pad_asymmetric_conv_input::<Flex, 2>(x, options);
        match x.dtype() {
            DType::F32 => conv::conv2d_f32(x, weight, bias, &options),
            DType::F64 => conv::conv2d_f64(x, weight, bias, &options),
            DType::F16 => conv::conv2d_f16(x, weight, bias, &options),
            DType::BF16 => conv::conv2d_bf16(x, weight, bias, &options),
            dtype => panic!("conv2d: unsupported dtype {:?}", dtype),
        }
    }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast the conv input to a float dtype before conv1d: x.cast(DType::F32) (or BF16 for half-precision inference).
  2. Verify tensor.dtype() of x and weight right before the call to identify the unexpected dtype and its origin.
  3. Insert an embedding or one-hot conversion layer for integer inputs (token ids) before the conv stage.
  4. If your checkpoint stores conv weights in an integer dtype, convert them at load time to f32.

Example fix

// before
let out = conv1d(token_ids_tensor, weight, bias, options);
// panic: conv1d: unsupported dtype I64

// after
let x = token_ids_tensor.cast(burn::tensor::DType::F32);
let out = conv1d(x, weight, bias, options);
Defensive patterns

Strategy: validation

Validate before calling

if !matches!(x.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16) {
    x = x.cast(DType::F32);
}
let out = conv1d(x, weight, bias, options);

Type guard

fn is_floating(t: &Tensor<Flex>) -> bool {
    matches!(t.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16)
}

Try / catch

let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conv1d(x.clone(), w.clone(), b.clone(), opts.clone())))
    .unwrap_or_else(|_| conv1d(x.cast(DType::F32), w, b, opts));

Prevention

When it happens

Trigger: Passing a tensor with dtype other than F32/F64/F16/BF16 (e.g. I8, I32, U8, Bool) as the input/weight of conv1d; a model whose input embedding layer emits integer tokens fed directly into a conv layer without embedding/casting.

Common situations: Feeding raw integer token ids or quantized int8 activations into a conv1d layer; misconfigured preprocessing that skips normalization/to-float conversion; porting a model from a framework that auto-promotes dtypes.

Related errors


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