tracel-ai/burn · error

Unsupported dtype: {:?}

Error message

Unsupported dtype: {:?}

What it means

Fallback arm of the ndarray concatenate macro: when the first tensor's dtype doesn't match any supported storage variant the macro generates, it panics with 'Unsupported dtype'. This differs from 336 — here even the expected/first dtype isn't representable.

Source

Thrown at crates/burn-ndarray/src/tensor.rs:315

#[macro_export]
macro_rules! cat_with_dtype {
    ($tensors: expr, $dim: expr, [$($dtype: ident),*]) => {
        match &$tensors[0] {
            $(NdArrayTensor::$dtype(_) => {
                let tensors = $tensors
                    .iter()
                    .map(|t| {
                        if let NdArrayTensor::$dtype(storage) = t {
                            // Use storage.view() for zero-copy access
                            storage.view()
                        } else {
                            panic!("Concatenate data type mismatch (expected {:?}, got {:?})", $tensors[0].dtype(), t.dtype())
                        }
                    })
                    .collect::<Vec<_>>();
                NdArrayOps::concatenate(&tensors, $dim).into()
            })*
            _ => panic!("Unsupported dtype: {:?}", $tensors[0].dtype())
        }
    };
}

/// Macro to execute an operation that returns a given element type.
#[macro_export]
macro_rules! execute_with_float_out_dtype {
    ($out_dtype:expr, $element:ident, $op:expr, [$($dtype: ident => $ty: ty),*]) => {{
        match $out_dtype {
            $(
                burn_std::FloatDType::$dtype => {
                    #[allow(unused)]
                    type $element = $ty;
                    $op
                }
            )*
            #[allow(unreachable_patterns)]
            other => unimplemented!("unsupported dtype: {other:?}")

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Dequantize/cast tensors to a supported dtype (F32 etc.) before concatenating
  2. Use Bool(BoolStore::Native) for bool tensors
  3. Upgrade burn to a version that covers the dtype, or avoid concatenating exotic dtypes

Example fix

// before
Tensor::cat(quantized_tensors, 0); // QFloat unsupported
// after
let floats: Vec<_> = quantized_tensors.iter().map(|t| t.cast(DType::F32)).collect();
Tensor::cat(floats, 0);
Defensive patterns

Strategy: validation

Validate before calling

assert!(!matches!(tensors[0].dtype(), DType::QFloat | _), "cast to supported dtype first");

Type guard

fn cat_supported<T: TensorOps>(ts: &[T]) -> bool {
    matches!(ts[0].dtype(), DType::F32 | DType::I32 | DType::U8 /* supported set */)
}

Prevention

When it happens

Trigger: Calling cat/concatenate on ndarray tensors whose dtype is outside the macro's generated set (e.g. QFloat, BF16, or non-native Bool storage).

Common situations: Concatenating quantized or half-precision tensors on ndarray; version churn introducing new DType variants not yet covered by the macro.

Related errors


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