tracel-ai/burn · error

all_float: unsupported dtype {:?}

Error message

all_float: unsupported dtype {:?}

What it means

Dtype-dispatch exhaustiveness panic: `all_float` (all non-zero over a float tensor) supports only F32/F64/F16/BF16 and panics on any other dtype, signaling that a non-float tensor was dispatched into the float all-reduction path.

Source

Thrown at crates/burn-flex/src/ops/comparison.rs:871

        DType::BF16 => iter_elements::<bf16>(&tensor).any(|x: bf16| x.to_f32() != 0.0),
        _ => panic!("any_float: unsupported dtype {:?}", tensor.dtype()),
    };
    bool_scalar(has_any, out_dtype)
}

/// Check if any element along a dimension is non-zero (float tensors).
pub fn any_float_dim(tensor: FlexTensor, dim: usize, out_dtype: BoolDType) -> FlexTensor {
    reduce_bool_dim(&tensor, dim, false, |a, b| a || b, out_dtype)
}

/// Check if all elements are non-zero (float tensors).
pub fn all_float(tensor: FlexTensor, out_dtype: BoolDType) -> FlexTensor {
    let all = match tensor.dtype() {
        DType::F32 => iter_elements::<f32>(&tensor).all(|x| x != 0.0),
        DType::F64 => iter_elements::<f64>(&tensor).all(|x| x != 0.0),
        DType::F16 => iter_elements::<f16>(&tensor).all(|x: f16| x.to_f32() != 0.0),
        DType::BF16 => iter_elements::<bf16>(&tensor).all(|x: bf16| x.to_f32() != 0.0),
        _ => panic!("all_float: unsupported dtype {:?}", tensor.dtype()),
    };
    bool_scalar(all, out_dtype)
}

/// Check if all elements along a dimension are non-zero (float tensors).
pub fn all_float_dim(tensor: FlexTensor, dim: usize, out_dtype: BoolDType) -> FlexTensor {
    reduce_bool_dim(&tensor, dim, true, |a, b| a && b, out_dtype)
}

/// Check if any element is non-zero (int tensors).
pub fn any_int(tensor: FlexTensor, out_dtype: BoolDType) -> FlexTensor {
    let has_any = match tensor.dtype() {
        DType::I64 => iter_elements::<i64>(&tensor).any(|x| x != 0),
        DType::I32 => iter_elements::<i32>(&tensor).any(|x| x != 0),
        DType::I16 => iter_elements::<i16>(&tensor).any(|x| x != 0),
        DType::I8 => iter_elements::<i8>(&tensor).any(|x| x != 0),
        DType::U64 => iter_elements::<u64>(&tensor).any(|x| x != 0),
        DType::U32 => iter_elements::<u32>(&tensor).any(|x| x != 0),

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Verify the dtype is float before calling; use all_int for integer tensors
  2. Cast to F32 if float semantics are fine
  3. Fix upstream dtype conversion so the tensor remains float

Example fix

// before
let all = all_float(u8_mask, BoolDType::Native);
// after
let all = all_int(u8_mask, BoolDType::Native);
Defensive patterns

Strategy: type-guard

Validate before calling

if !matches!(t.dtype(), DType::F32|DType::F64|DType::F16|DType::BF16) { /* route to all_int or cast */ }

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 the public all_float(tensor, out_dtype) with an integer or Bool tensor.

Common situations: Generic any/all helper code that passes any tensor to all_float; a dtype change upstream (int cast, mask stored as U8) before the reduction call.

Related errors


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