tracel-ai/burn · error

float_cummax: unsupported dtype {:?}

Error message

float_cummax: unsupported dtype {:?}

What it means

float_cummax computes the running maximum; F32/F64 use dedicated kernels and F16/BF16 go through cummax_half with f32 round-trip. The final match arm panics for any other dtype. As with the other cumulative ops, only float tensors are supported by this backend.

Source

Thrown at crates/burn-flex/src/ops/float.rs:814

            }
            DType::BF16 => {
                crate::ops::cumulative::cummin_half(tensor, dim, bf16::to_f32, bf16::from_f32)
            }
            _ => panic!("float_cummin: unsupported dtype {:?}", tensor.dtype()),
        }
    }

    fn float_cummax(tensor: FloatTensor<Flex>, dim: usize) -> FloatTensor<Flex> {
        match tensor.dtype() {
            DType::F32 => crate::ops::cumulative::cummax_f32(tensor, dim),
            DType::F64 => crate::ops::cumulative::cummax_f64(tensor, dim),
            DType::F16 => {
                crate::ops::cumulative::cummax_half(tensor, dim, f16::to_f32, f16::from_f32)
            }
            DType::BF16 => {
                crate::ops::cumulative::cummax_half(tensor, dim, bf16::to_f32, bf16::from_f32)
            }
            _ => panic!("float_cummax: unsupported dtype {:?}", tensor.dtype()),
        }
    }

    fn float_cast(tensor: FloatTensor<Flex>, dtype: FloatDType) -> FloatTensor<Flex> {
        use crate::Layout;
        use burn_std::{Bytes, bf16, f16};

        let src_dtype = tensor.dtype();
        let target_dtype = DType::from(dtype);

        // No-op if already the same dtype
        if src_dtype == target_dtype {
            return tensor;
        }

        let tensor = tensor.to_contiguous();
        let shape = tensor.layout().shape().clone();

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast the tensor to a float dtype before cummax, e.g. tensor.to_dtype(FloatDType::F32).
  2. Check upstream ops (argmax, comparisons, casts) that may have produced an Int tensor.
  3. Use the integer dispatch path if the backend exposes int cumulative ops, or implement one.
  4. Add the required dtype arm to float_cummax in crates/burn-flex/src/ops/float.rs if needed.

Example fix

// before
let m = scores_i64.cummax(0); // panic on Int
// after
let m = scores_i64
    .to_dtype(burn::tensor::FloatDType::F32)
    .cummax(0);
Defensive patterns

Strategy: validation

Validate before calling

assert!(matches!(tensor.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), "cummax needs a float tensor, got {:?}", tensor.dtype());

Type guard

fn is_float_dtype(dtype: &DType) -> bool { matches!(dtype, DType::F32 | DType::F64 | DType::F16 | DType::BF16) }

Try / catch

// Validate dtype before calling; panics abort:
if is_float_dtype(&tensor.dtype()) { let m = tensor.cummax(dim); }

Prevention

When it happens

Trigger: Calling Tensor::cummax (running max along a dim) on burn-flex with an Int/Bool or otherwise non-float tensor.

Common situations: Running-max over integer scores or indices; code refactors that changed tensor kind; generic scan utilities instantiated with Int tensors.

Related errors


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