tracel-ai/burn · error

max: unsupported dtype {:?}

Error message

max: unsupported dtype {:?}

What it means

Dtype-dispatch exhaustiveness panic in the Flex max reduction: all float and integer dtypes are matched to dedicated implementations; an unmatched dtype (e.g. bool) reaching `max` panics, indicating a misrouted reduction op.

Source

Thrown at crates/burn-flex/src/ops/reduce.rs:461

            f16::to_f32,
            f16::from_f32,
        ),
        DType::BF16 => reduce_scalar_half(
            &tensor,
            select_float_extremum::<f32, true>,
            f32::NEG_INFINITY,
            bf16::to_f32,
            bf16::from_f32,
        ),
        DType::I8 => max_impl::<i8>(&tensor),
        DType::I16 => max_impl::<i16>(&tensor),
        DType::I32 => max_impl::<i32>(&tensor),
        DType::I64 => max_impl::<i64>(&tensor),
        DType::U8 => max_impl::<u8>(&tensor),
        DType::U16 => max_impl::<u16>(&tensor),
        DType::U32 => max_impl::<u32>(&tensor),
        DType::U64 => max_impl::<u64>(&tensor),
        _ => panic!("max: unsupported dtype {:?}", tensor.dtype()),
    }
}

/// Min of all elements, returning a scalar tensor of shape \[1\].
pub fn min(tensor: FlexTensor) -> FlexTensor {
    assert!(
        tensor.layout().shape().num_elements() > 0,
        "min: cannot reduce an empty tensor"
    );
    match tensor.dtype() {
        DType::F32 => min_f32_reduce(&tensor),
        DType::F64 => float_extremum_f64_reduce::<false>(&tensor),
        DType::F16 => reduce_scalar_half(
            &tensor,
            select_float_extremum::<f32, false>,
            f32::INFINITY,
            f16::to_f32,
            f16::from_f32,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast before reducing: `mask.cast(DType::I32).max()` or `.float().max()`.
  2. For quantized tensors, call `.dequantize()` before max.
  3. Check `tensor.dtype()` at the call site and add the appropriate cast.

Example fix

// before
let m = mask.max(); // Bool
// after
let m = mask.cast(DType::I32).max();
Defensive patterns

Strategy: validation

Validate before calling

assert!(!matches!(t.dtype(), DType::Bool | DType::QFloat(_)), "max unsupported for {:?}; cast or dequantize first", t.dtype());

Type guard

fn is_max_capable(d: DType) -> bool {
    matches!(d, DType::F32 | DType::F64 | DType::F16 | DType::BF16
        | DType::I8 | DType::I16 | DType::I32 | DType::I64
        | DType::U8 | DType::U16 | DType::U32 | DType::U64)
}

Prevention

When it happens

Trigger: Calling `Tensor::max()` on a Bool or quantized tensor — e.g. taking max over a boolean mask or over quantized activations before dequantization.

Common situations: Max over comparison results stored as bool; max over quantized tensors; dtype leaks from data loading pipelines into reduction-heavy code.

Related errors


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