tracel-ai/burn · error

float_gather_nd: unsupported dtype {:?}

Error message

float_gather_nd: unsupported dtype {:?}

What it means

Dtype-dispatch exhaustiveness panic: `float_gather_nd` handles F32/F64/F16/BF16 and panics for any other dtype passed as the data tensor, implying an internal routing error where a non-float tensor reached the float gather_nd op.

Source

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

                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> {
        match tensor.dtype() {
            DType::F32 => crate::ops::gather_scatter::select::<f32>(tensor, dim, indices),
            DType::F64 => crate::ops::gather_scatter::select::<f64>(tensor, dim, indices),
            DType::F16 => crate::ops::gather_scatter::select::<f16>(tensor, dim, indices),
            DType::BF16 => crate::ops::gather_scatter::select::<bf16>(tensor, dim, indices),
            _ => panic!("float_select: unsupported dtype {:?}", tensor.dtype()),
        }
    }

    fn float_select_assign(

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Verify the data tensor is a float tensor before gather_nd
  2. Use the int/bool gather_nd op for non-float data
  3. Cast the data tensor to a float dtype first
  4. Add the missing dispatch arm for a new DType

Example fix

// before: data is I32 -> panic
let out = data.gather_nd(indices);
// after
let out = data.cast(FloatDType::F32).gather_nd(indices);
Defensive patterns

Strategy: type-guard

Validate before calling

fn ensure_float_for_gather_nd(dt: DType) -> Result<(), String> {
    match dt {
        DType::F32 | DType::F64 | DType::F16 | DType::BF16 => Ok(()),
        other => Err(format!("float_gather_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_gather_nd (Tensor::gather_nd) where the data tensor's dtype is Int or Bool instead of a float type.

Common situations: gather_nd on an integer label/indices tensor routed through the float path; upstream ops returning unexpected dtypes; new DType variants added without updating this match.

Related errors


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