tracel-ai/burn · error

int_scatter: unsupported dtype {:?}

Error message

int_scatter: unsupported dtype {:?}

What it means

int_scatter dispatches on the tensor dtype for the IndexingUpdateOp::Set (assignment) path and panics when the dtype is not one of the eight implemented integer widths. The library refuses to reinterpret raw bytes of an unknown dtype during scatter-assign, so it fails fast with this panic instead of producing corrupt results.

Source

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

                    DType::I16 => crate::ops::gather_scatter::scatter_assign::<i16>(
                        tensor, dim, indices, value,
                    ),
                    DType::I8 => crate::ops::gather_scatter::scatter_assign::<i8>(
                        tensor, dim, indices, value,
                    ),
                    DType::U64 => crate::ops::gather_scatter::scatter_assign::<u64>(
                        tensor, dim, indices, value,
                    ),
                    DType::U32 => crate::ops::gather_scatter::scatter_assign::<u32>(
                        tensor, dim, indices, value,
                    ),
                    DType::U16 => crate::ops::gather_scatter::scatter_assign::<u16>(
                        tensor, dim, indices, value,
                    ),
                    DType::U8 => crate::ops::gather_scatter::scatter_assign::<u8>(
                        tensor, dim, indices, value,
                    ),
                    dt => panic!("int_scatter: unsupported dtype {:?}", dt),
                }
            }
            burn_backend::tensor::IndexingUpdateOp::Add => {
                debug_assert_eq!(tensor.dtype(), value.dtype(), "int_scatter: dtype mismatch");
                match tensor.dtype() {
                    DType::I64 => {
                        crate::ops::gather_scatter::scatter_add::<i64>(tensor, dim, indices, value)
                    }
                    DType::I32 => {
                        crate::ops::gather_scatter::scatter_add::<i32>(tensor, dim, indices, value)
                    }
                    DType::I16 => {
                        crate::ops::gather_scatter::scatter_add::<i16>(tensor, dim, indices, value)
                    }
                    DType::I8 => {
                        crate::ops::gather_scatter::scatter_add::<i8>(tensor, dim, indices, value)
                    }
                    DType::U64 => {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Cast both the target tensor and value to a supported int dtype (e.g. DType::I32) before calling int_scatter
  2. Ensure tensor.dtype() == value.dtype() before the call - the debug_assert signals this precondition
  3. Verify the update op you intended (Set vs Add/Mul); this panic is specific to the Set path
  4. If a new DType variant is missing, add a match arm calling crate::ops::gather_scatter::scatter_assign::<T>

Example fix

// before
tensor.scatter(dim, indices, value, IndexingUpdateOp::Set); // tensor is DType::Bool
// after
let tensor = tensor.cast(DType::I32);
let value = value.cast(DType::I32);
tensor.scatter(dim, indices, value, IndexingUpdateOp::Set);
Defensive patterns

Strategy: validation

Validate before calling

assert_eq!(tensor.dtype(), value.dtype(), "int_scatter: dtype mismatch");
assert!(is_supported_int_dtype(tensor.dtype()), "unsupported dtype {:?}", tensor.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 with IndexingUpdateOp::Set on a tensor whose dtype is outside i64/i32/i16/i8/u64/u32/u16/u8 (e.g. a bool tensor), or when tensor.dtype() and value.dtype() diverge so an unexpected arm is reached.

Common situations: Assigning into index results derived from bool masks, dtype drift between the target tensor and the update value after transformations, or a burn version that introduced a new DType not yet handled in burn-flex's match.

Related errors


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