tracel-ai/burn · error

int_scatter_nd: unsupported dtype {:?}

Error message

int_scatter_nd: unsupported dtype {:?}

What it means

int_scatter_nd dispatches scatter_nd updates by dtype and panics when the data tensor's dtype is not one of the eight implemented integer widths. N-dimensional scatter needs a concrete element type to write values; unknown dtypes are rejected fail-fast rather than written with wrong strides/widths.

Source

Thrown at crates/burn-flex/src/ops/int.rs:262

            DType::I16 => {
                crate::ops::gather_scatter::scatter_nd::<i16>(data, indices, values, reduction)
            }
            DType::I8 => {
                crate::ops::gather_scatter::scatter_nd::<i8>(data, indices, values, reduction)
            }
            DType::U64 => {
                crate::ops::gather_scatter::scatter_nd::<u64>(data, indices, values, reduction)
            }
            DType::U32 => {
                crate::ops::gather_scatter::scatter_nd::<u32>(data, indices, values, reduction)
            }
            DType::U16 => {
                crate::ops::gather_scatter::scatter_nd::<u16>(data, indices, values, reduction)
            }
            DType::U8 => {
                crate::ops::gather_scatter::scatter_nd::<u8>(data, indices, values, reduction)
            }
            dt => panic!("int_scatter_nd: unsupported dtype {:?}", dt),
        }
    }

    fn int_gather_nd(data: IntTensor<Flex>, indices: IntTensor<Flex>) -> IntTensor<Flex> {
        match data.dtype() {
            DType::I64 => crate::ops::gather_scatter::gather_nd::<i64>(data, indices),
            DType::I32 => crate::ops::gather_scatter::gather_nd::<i32>(data, indices),
            DType::I16 => crate::ops::gather_scatter::gather_nd::<i16>(data, indices),
            DType::I8 => crate::ops::gather_scatter::gather_nd::<i8>(data, indices),
            DType::U64 => crate::ops::gather_scatter::gather_nd::<u64>(data, indices),
            DType::U32 => crate::ops::gather_scatter::gather_nd::<u32>(data, indices),
            DType::U16 => crate::ops::gather_scatter::gather_nd::<u16>(data, indices),
            DType::U8 => crate::ops::gather_scatter::gather_nd::<u8>(data, indices),
            dt => panic!("int_gather_nd: unsupported dtype {:?}", dt),
        }
    }

    /// Select ints along `dim` by a 1D index tensor.

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast the data (and values) tensor to a supported int dtype before calling int_scatter_nd
  2. Ensure data and values share the same dtype
  3. Verify you are using the int variant intentionally; float tensors should use the float scatter_nd path
  4. Add the missing match arm calling crate::ops::gather_scatter::scatter_nd::<T> for new dtypes

Example fix

// before
flex_int_scatter_nd(data, indices, values, reduction); // data is DType::Bool
// after
let data = data.cast(DType::I64);
let values = values.cast(DType::I64);
flex_int_scatter_nd(data, indices, values, reduction);
Defensive patterns

Strategy: validation

Validate before calling

assert!(is_supported_int_dtype(data.dtype()), "scatter_nd: unsupported dtype {:?}", data.dtype());
assert_eq!(data.dtype(), values.dtype());

Type guard

fn is_supported_int_dtype(dt: burn::tensor::DType) -> bool {
    matches!(
        dt,
        burn::tensor::DType::I64 | burn::tensor::DType::I32
            | burn::tensor::DType::I16 | burn::tensor::DType::I8
            | burn::tensor::DType::U64 | burn::tensor::DType::U32
            | burn::tensor::DType::U16 | burn::tensor::DType::U8
    )
}

Prevention

When it happens

Trigger: Calling int_scatter_nd with an IntTensor data tensor whose dtype is not i64/i32/i16/i8/u64/u32/u16/u8, e.g. a bool or float tensor routed into the int variant of scatter_nd.

Common situations: Building scatter_nd updates from boolean index computations, dtype inference yielding an unexpected width, or upstream burn adding a DType variant before burn-flex handles it.

Related errors


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