tracel-ai/burn · error

min: unsupported dtype {:?}

Error message

min: unsupported dtype {:?}

What it means

The burn-flex `min` reduction panics when the tensor's dtype has no implemented min-reduction path. The match in reduce.rs:466-498 covers F32/F64/F16/BF16 and all integer types (I8-I64, U8-U64); any other dtype — practically only DType::Bool — falls into the catch-all `_` arm and panics. Burn panics rather than returning Result because reductions are expected to be total over the supported dtype set.

Source

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

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

#[inline(always)]
fn select_float_extremum<E: Float, const MAX: bool>(current: E, candidate: E) -> E {
    let keep_current = if MAX {
        current >= candidate
    } else {
        current <= candidate
    };
    if current.is_nan() || keep_current {
        current
    } else {
        candidate
    }
}

#[inline(always)]

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Check `tensor.dtype()` before reducing; convert Bool to a numeric type first, e.g. `tensor.cast(DType::F32)` or `tensor.cast(DType::U8)` (F32/U8 both have min paths).
  2. If you expected a float/int tensor, fix the upstream op that produced the wrong dtype (inspect the cast/comparison chain feeding `min`).
  3. If you need bool min support, add a `DType::Bool` arm to the match in crates/burn-flex/src/ops/reduce.rs mapping to a bool element-wise min impl.
  4. Run your pipeline with dtype assertions enabled so the mismatch surfaces at the producing op rather than at reduction.

Example fix

// before
let m = min(mask_tensor); // panics: unsupported dtype Bool
// after
let m = min(mask_tensor.cast(DType::F32));
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_min_supported(dtype: DType) -> Result<(), String> {
    match dtype {
        DType::F32 | DType::F64 | DType::F16 | DType::BF16
        | DType::I8 | DType::I16 | DType::I32 | DType::I64
        | DType::U8 | DType::U16 | DType::U32 | DType::U64 => Ok(()),
        other => Err(format!("min: unsupported dtype {other:?}")),
    }
}
// before calling: ensure_min_supported(t.dtype())?;

Type guard

fn is_min_supported(dtype: DType) -> bool {
    !matches!(dtype, DType::Bool)
}

Try / catch

// Rust panic, not catchable portably; validate dtype first, or use catch_unwind:
let result = std::panic::catch_unwind(|| burn_flex_ops_reduce_min(tensor.clone()));
match result { Ok(t) => t, Err(_) => fallback_min(tensor) }

Prevention

When it happens

Trigger: Calling `ops::reduce::min(tensor)` (or a burn frontend min reduction dispatched to the flex backend) on a tensor whose dtype is not one of the 12 supported ones — in practice a Bool tensor, since bool is the only DType outside the handled set.

Common situations: Reducing a boolean mask (e.g. min/any-style reduction over a bool mask produced by a comparison); dtype drift after a casting change so a reduction receives an unexpected dtype; a newly added DType variant not yet wired into the flex reduce ops.

Related errors


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