tracel-ai/burn · error
float_into_int: unsupported source dtype {:?}
Error message
float_into_int: unsupported source dtype {:?} What it means
float_into_int converts a float tensor's data to an integer dtype. The read_floats! macro only handles F32, F64, F16, and BF16 source dtypes; passing a tensor whose dtype is anything else (e.g. a bool or int tensor routed here by mistake) hits the catch-all panic. It is a defensive guard against backend misuse, not a user-facing conversion failure.
Source
Thrown at crates/burn-flex/src/ops/float.rs:103
})
.collect(),
DType::F16 => tensor
.storage::<f16>()
.iter()
.map(|v| {
let $x = f32::from(*v) as f64;
$conv
})
.collect(),
DType::BF16 => tensor
.storage::<bf16>()
.iter()
.map(|v| {
let $x = f32::from(*v) as f64;
$conv
})
.collect(),
_ => panic!("float_into_int: unsupported source dtype {:?}", src),
}
};
}
macro_rules! convert {
($int_ty:ty) => {{
let data: Vec<$int_ty> = read_floats!(|x| x as $int_ty);
FlexTensor::new(Bytes::from_elems(data), Layout::contiguous(shape), out_dt)
}};
}
match out_dtype {
IntDType::I64 => convert!(i64),
IntDType::I32 => convert!(i32),
IntDType::I16 => convert!(i16),
IntDType::I8 => convert!(i8),
IntDType::U64 => convert!(u64),
IntDType::U32 => convert!(u32),View on GitHub (pinned to d16f7ba2ed)
Solutions
- Check the tensor's dtype before casting; only float tensors (F32/F64/F16/BF16) can go through float_into_int
- If the tensor is bool/int, use the appropriate int/bool conversion op instead of the float cast
- If the source op unexpectedly returned a non-float dtype, fix the upstream op or add an explicit .float() cast first
- If a new DType variant was added to the backend, add a matching arm in the read_floats! macro
Example fix
// before: mask is Bool -> panic in float_into_int let ints = mask.cast(IntDType::I32); // after: cast bool to float first let ints = mask.cast(FloatDType::F32).cast(IntDType::I32);
Defensive patterns
Strategy: type-guard
Validate before calling
use burn_tensor::DType;
fn ensure_float(dt: DType) -> Result<(), String> {
match dt {
DType::F32 | DType::F64 | DType::F16 | DType::BF16 => Ok(()),
other => Err(format!("float_into_int 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
- Check tensor.dtype() before any cast/conversion op
- Route int/bool tensors to their own conversion ops, never the float path
- Keep dtype tracking explicit in pipelines that mix masks, indices, and activations
- After adding a new DType, grep for matches on DType to update all dispatch tables
When it happens
Trigger: Calling float_into_int (via dtype cast/conversion APIs) with a source tensor whose dtype is not a floating-point type, e.g. Bool or an Int dtype. In normal use this only happens if another op mis-dispatches a non-float tensor into the float cast path.
Common situations: Backend bug or an op that returns an int/bool tensor where a float tensor was expected; casting a boolean mask tensor through the float cast path; version drift where a new DType variant was added 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_gather: unsupported dtype {:?}
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/0ee525381fade82c.
Report an issue: GitHub.