tracel-ai/burn · error

float_cumsum: unsupported dtype {:?}

Error message

float_cumsum: unsupported dtype {:?}

What it means

float_cumsum computes the cumulative sum; F32/F64 use the f32 kernels and F16/BF16 go through cumsum_half with f32 round-tripping. The final match arm panics for any other dtype. Reaching it means a non-float tensor was fed to the float cumulative-sum op.

Source

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

    fn float_prod(tensor: FloatTensor<Flex>) -> FloatTensor<Flex> {
        crate::ops::reduce::prod(tensor)
    }

    fn float_prod_dim(tensor: FloatTensor<Flex>, dim: usize) -> FloatTensor<Flex> {
        crate::ops::reduce::prod_dim(tensor, dim)
    }

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

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

    fn float_cummin(tensor: FloatTensor<Flex>, dim: usize) -> FloatTensor<Flex> {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast to float before cumsum: tensor.to_dtype(FloatDType::F32).cumsum(dim).
  2. Compute cumsum on int tensors via float and cast back if exact int sums within range are acceptable.
  3. Inspect the producing op to see why the tensor is not float; fix the dtype at the source.
  4. Add an int cumsum implementation and dtype arm in crates/burn-flex/src/ops/float.rs / cumulative.rs.

Example fix

// before
let c = counts.cumsum(1); // counts: Int tensor -> panic
// after
let c = counts
    .to_dtype(burn::tensor::FloatDType::F32)
    .cumsum(1);
Defensive patterns

Strategy: validation

Validate before calling

assert!(matches!(tensor.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), "cumsum 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

// Panics are fatal; validate first:
if is_float_dtype(&tensor.dtype()) { let c = tensor.cumsum(dim); }

Prevention

When it happens

Trigger: Calling Tensor::cumsum (or cumsum_along_dim) on the burn-flex backend with a tensor whose dtype is not F32/F64/F16/BF16, e.g. an Int tensor.

Common situations: Cumulative counts over integer tensors; applying cumsum right after argmax/top-k without casting; generic ML code where the tensor kind was inferred as Int.

Related errors


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