tracel-ai/burn · error

float_scatter_nd: unsupported dtype {:?}

Error message

float_scatter_nd: unsupported dtype {:?}

What it means

float_scatter_nd performs N-dimensional scatter updates and dispatches per dtype, supporting only F32, F64, F16, and BF16 for the data tensor. Any other dtype hits the catch-all panic. Like its siblings, it is a defensive dispatch guard in the flex backend.

Source

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

        data: FloatTensor<Flex>,
        indices: IntTensor<Flex>,
        values: FloatTensor<Flex>,
        reduction: burn_backend::tensor::IndexingUpdateOp,
    ) -> FloatTensor<Flex> {
        match data.dtype() {
            DType::F32 => {
                crate::ops::gather_scatter::scatter_nd::<f32>(data, indices, values, reduction)
            }
            DType::F64 => {
                crate::ops::gather_scatter::scatter_nd::<f64>(data, indices, values, reduction)
            }
            DType::F16 => {
                crate::ops::gather_scatter::scatter_nd::<f16>(data, indices, values, reduction)
            }
            DType::BF16 => {
                crate::ops::gather_scatter::scatter_nd::<bf16>(data, indices, values, reduction)
            }
            _ => panic!("float_scatter_nd: unsupported dtype {:?}", data.dtype()),
        }
    }

    fn float_gather_nd(data: FloatTensor<Flex>, indices: IntTensor<Flex>) -> FloatTensor<Flex> {
        match data.dtype() {
            DType::F32 => crate::ops::gather_scatter::gather_nd::<f32>(data, indices),
            DType::F64 => crate::ops::gather_scatter::gather_nd::<f64>(data, indices),
            DType::F16 => crate::ops::gather_scatter::gather_nd::<f16>(data, indices),
            DType::BF16 => crate::ops::gather_scatter::gather_nd::<bf16>(data, indices),
            _ => panic!("float_gather_nd: unsupported dtype {:?}", data.dtype()),
        }
    }

    fn float_select(
        tensor: FloatTensor<Flex>,
        dim: usize,
        indices: IntTensor<Flex>,
    ) -> FloatTensor<Flex> {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Check data.dtype() is F32/F64/F16/BF16 before scatter_nd
  2. Use the int/bool scatter_nd path for non-float data
  3. Cast data to a float dtype before the operation
  4. Add a match arm for any newly added DType

Example fix

// before: data is I64 -> panic
let out = data.scatter_nd(indices, values, reduction);
// after
let out = data.cast(FloatDType::F32).scatter_nd(indices, values, reduction);
Defensive patterns

Strategy: type-guard

Validate before calling

fn ensure_float_for_scatter_nd(dt: DType) -> Result<(), String> {
    match dt {
        DType::F32 | DType::F64 | DType::F16 | DType::BF16 => Ok(()),
        other => Err(format!("float_scatter_nd requires a float data 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_nd (Tensor::scatter_nd) where the data tensor's dtype is not a float type (e.g. Int or Bool data with float-indexed updates).

Common situations: scatter_nd on an int parameter tensor (e.g. embedding indices data instead of weights); dtype changed by quantization or mixed-precision plumbing; new DType variant missing from the dispatch.

Related errors


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