tracel-ai/burn · error

float_gather: unsupported dtype {:?}

Error message

float_gather: unsupported dtype {:?}

What it means

float_gather dispatches to a monomorphic gather implementation based on the tensor's dtype, supporting only F32, F64, F16, and BF16. Any other dtype (int or bool) reaching this float op hits the catch-all panic. It guards the dispatch table against non-float tensors.

Source

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

    fn float_cat(tensors: Vec<FloatTensor<Flex>>, dim: usize) -> FloatTensor<Flex> {
        crate::ops::cat::cat(tensors, dim)
    }

    fn float_reshape(tensor: FloatTensor<Flex>, shape: Shape) -> FloatTensor<Flex> {
        tensor.reshape(shape)
    }

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

    fn float_scatter(
        dim: usize,
        tensor: FloatTensor<Flex>,
        indices: IntTensor<Flex>,
        value: FloatTensor<Flex>,
        update: burn_backend::tensor::IndexingUpdateOp,
    ) -> FloatTensor<Flex> {
        match update {
            burn_backend::tensor::IndexingUpdateOp::Assign => match tensor.dtype() {
                DType::F32 => {
                    crate::ops::gather_scatter::scatter_assign::<f32>(tensor, dim, indices, value)
                }
                DType::F64 => {
                    crate::ops::gather_scatter::scatter_assign::<f64>(tensor, dim, indices, value)
                }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Verify the tensor being gathered is a float tensor (F32/F64/F16/BF16) with tensor.dtype()
  2. If the data is int/bool, call the corresponding int/bool gather op instead
  3. Insert an explicit cast to a float dtype before gathering if a float result is required
  4. If a new DType variant exists, add a match arm dispatching to gather::<new_type>

Example fix

// before: x is I64 -> panic
let picked = x.gather(dim, indices);
// after
let picked = x.cast(FloatDType::F32).gather(dim, indices);
Defensive patterns

Strategy: type-guard

Validate before calling

fn ensure_float_for_gather(dt: DType) -> Result<(), String> {
    match dt {
        DType::F32 | DType::F64 | DType::F16 | DType::BF16 => Ok(()),
        other => Err(format!("float_gather requires a float 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 (via Tensor::gather/select on a float tensor) where the data tensor's dtype is not one of the four float types, e.g. an Int or Bool tensor mis-dispatched into the float indexing path.

Common situations: Gathering on a tensor that upstream ops silently converted to int/bool; a misrouted dispatch in the backend; adding a new DType variant without updating this match.

Related errors


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