tracel-ai/burn · error

int_gather_nd: unsupported dtype {:?}

Error message

int_gather_nd: unsupported dtype {:?}

What it means

int_gather_nd dispatches N-dimensional gathering by dtype and panics when the data tensor's dtype is not one of the eight implemented integer widths. gather_nd reads elements of a fixed width, so an unhandled dtype would corrupt memory; burn-flex panics instead.

Source

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

            }
            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.
    ///
    /// The `indices` tensor may be any supported int width. See
    /// [`int_gather`](Self::int_gather) for the full index-width policy.
    fn int_select(
        tensor: IntTensor<Flex>,
        dim: usize,
        indices: IntTensor<Flex>,
    ) -> IntTensor<Flex> {
        match tensor.dtype() {
            DType::I64 => crate::ops::gather_scatter::select::<i64>(tensor, dim, indices),
            DType::I32 => crate::ops::gather_scatter::select::<i32>(tensor, dim, indices),
            DType::I16 => crate::ops::gather_scatter::select::<i16>(tensor, dim, indices),
            DType::I8 => crate::ops::gather_scatter::select::<i8>(tensor, dim, indices),
            DType::U64 => crate::ops::gather_scatter::select::<u64>(tensor, dim, indices),

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast the data tensor to a supported int dtype (e.g. DType::I32) before calling int_gather_nd
  2. Route float tensors through the float gather_nd implementation instead of the int one
  3. Ensure index tensors are any supported int width - only data dtype must match the implemented arms
  4. Add a gather_nd match arm for any missing DType variant in burn-flex

Example fix

// before
let out = tensor.gather_nd(indices); // tensor is DType::Bool
// after
let out = tensor.cast(DType::I32).gather_nd(indices);
Defensive patterns

Strategy: validation

Validate before calling

assert!(is_supported_int_dtype(data.dtype()), "gather_nd: unsupported dtype {:?}", data.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_gather_nd on an IntTensor whose dtype is not i64/i32/i16/i8/u64/u32/u16/u8, e.g. passing a bool or float tensor to the int gather_nd entry point.

Common situations: Gathering with index tensors computed from comparisons, dtype inference surprises, or a newly introduced burn DType not yet covered by burn-flex's match arms.

Related errors


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