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
- Verify the tensor being gathered is a float tensor (F32/F64/F16/BF16) with tensor.dtype()
- If the data is int/bool, call the corresponding int/bool gather op instead
- Insert an explicit cast to a float dtype before gathering if a float result is required
- 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
- Assert the data tensor is float before gather/select-style ops
- Cast non-float data explicitly with .cast(FloatDType::F32) when a float result is needed
- Keep indices tensors int and data tensors float; never let them swap roles
- Update dtype dispatch tables whenever a DType variant is added
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
- Should be float, got int
- Should be float, got bool
- Should be float, got quantized
- Should be float, got autodiff
- float_into_int: unsupported source dtype {:?}
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/a6d51cc3f1bac252.
Report an issue: GitHub.