tracel-ai/burn · error

float_scatter: unsupported dtype {:?}

Error message

float_scatter: unsupported dtype {:?}

What it means

In float_scatter, the IndexingUpdateOp::Set branch dispatches scatter_assign per dtype and only handles F32/F64/F16/BF16. A tensor with any other dtype in the Set-update path triggers this catch-all panic. It protects the monomorphic dispatch table from non-float tensors.

Source

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

        indices: IntTensor<Flex>,
        value: FloatTensor<Flex>,
        update: burn_backend::tensor::IndexingUpdateOp,
    ) -> FloatTensor<Flex> {
        match update {
            burn_backend::tensor::IndexingUpdateOp::Assign => match tensor.dtype() {
                DType::F32 => {
                    crate::ops::gather_scatter::scatter_assign::<f32>(tensor, dim, indices, value)
                }
                DType::F64 => {
                    crate::ops::gather_scatter::scatter_assign::<f64>(tensor, dim, indices, value)
                }
                DType::F16 => {
                    crate::ops::gather_scatter::scatter_assign::<f16>(tensor, dim, indices, value)
                }
                DType::BF16 => {
                    crate::ops::gather_scatter::scatter_assign::<bf16>(tensor, dim, indices, value)
                }
                _ => panic!("float_scatter: unsupported dtype {:?}", tensor.dtype()),
            },
            burn_backend::tensor::IndexingUpdateOp::Add => match tensor.dtype() {
                DType::F32 => {
                    crate::ops::gather_scatter::scatter_add::<f32>(tensor, dim, indices, value)
                }
                DType::F64 => {
                    crate::ops::gather_scatter::scatter_add::<f64>(tensor, dim, indices, value)
                }
                DType::F16 => {
                    crate::ops::gather_scatter::scatter_add::<f16>(tensor, dim, indices, value)
                }
                DType::BF16 => {
                    crate::ops::gather_scatter::scatter_add::<bf16>(tensor, dim, indices, value)
                }
                _ => panic!("float_scatter: unsupported dtype {:?}", tensor.dtype()),
            },
            burn_backend::tensor::IndexingUpdateOp::Mul => match tensor.dtype() {
                DType::F32 => {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Confirm the target tensor is a float tensor before scattering
  2. Use the int/bool scatter op for non-float tensors
  3. Cast the tensor to a float dtype (e.g. F32) before scatter
  4. Add the missing DType arm dispatching to scatter_assign if a new float/int variant exists

Example fix

// before: target is I32 -> panic on Set update
let t = t.scatter(dim, indices, value, IndexingUpdateOp::Set);
// after
let t = t.cast(FloatDType::F32).scatter(dim, indices, value, IndexingUpdateOp::Set);
Defensive patterns

Strategy: type-guard

Validate before calling

fn ensure_float_for_scatter(dt: DType) -> Result<(), String> {
    match dt {
        DType::F32 | DType::F64 | DType::F16 | DType::BF16 => Ok(()),
        other => Err(format!("float_scatter requires a float dtype, got {:?}", other)),
    }
}

Type guard

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

Prevention

When it happens

Trigger: Calling float_scatter (Tensor::scatter with IndexingUpdateOp::Set / scatter_assign) on a tensor whose dtype is not one of the four float types.

Common situations: Scattering into an int tensor routed through the float op; a wrong-dtype value tensor causing the backend to pick the float path; a newly added DType missing from the match.

Related errors


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