tracel-ai/burn · error
Expected float handle, got {}
Error message
Expected float handle, got {} What it means
`BackendIr::float_tensor` for the Flex backend unwraps a `TensorHandle` expecting its `HandleKind::Float` variant. If the handle holds any other kind (Int, Bool, Quantized, ...), the code panics with 'Expected float handle, got <name>'. This enforces dtype correctness at the backend IR boundary.
Source
Thrown at crates/burn-flex/src/backend.rs:176
// Quantized types: storage only for now
DType::QFloat(scheme) if burn_std::quantization::quantizable(&scheme) => {
DTypeUsage::Storage.into()
}
DType::QFloat(_) => DTypeUsageSet::empty(),
_ => DTypeUsageSet::empty(),
}
}
fn flush(_device: &Self::Device) {}
}
impl BackendIr for Flex {
type Handle = HandleKind<Self>;
fn float_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {
match handle.handle {
HandleKind::Float(t) => t,
_ => panic!("Expected float handle, got {}", handle.handle.name()),
}
}
fn int_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {
match handle.handle {
HandleKind::Int(t) => t,
_ => panic!("Expected int handle, got {}", handle.handle.name()),
}
}
fn bool_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {
match handle.handle {
HandleKind::Bool(t) => t,
_ => panic!("Expected bool handle, got {}", handle.handle.name()),
}
}
fn quantized_tensor(handle: TensorHandle<Self::Handle>) -> FlexQTensor {View on GitHub (pinned to d16f7ba2ed)
Solutions
- Ensure the op producing the handle declares/returns a Float handle kind (fix the kernel or its output type).
- Before converting, match on `handle.handle` and route each kind to the matching converter (`int_tensor`, `bool_tensor`, etc.).
- Check the calling op's dtype planning so float ops only consume float handles.
Example fix
// before
let t = BackendIr::float_tensor(handle); // panics if handle is Int
// after
let t = match handle.handle {
HandleKind::Float(t) => t,
other => panic!("op returned {:?}, expected float", other.name()),
}; Defensive patterns
Strategy: type-guard
Validate before calling
if !matches!(handle.handle, HandleKind::Float(_)) { /* route to correct converter */ } Type guard
fn as_float_handle(t: HandleKind<Flex>) -> Option<FlexTensor> {
match t { HandleKind::Float(f) => Some(f), _ => None }
} Try / catch
let result = std::panic::catch_unwind(AssertUnwindSafe(|| Flex::float_tensor(handle.clone())));
match result {
Ok(t) => use_float(t),
Err(_) => eprintln!("handle was not float"),
} Prevention
- Match on HandleKind before converting instead of assuming the dtype.
- Keep op registrations aligned with the handle kinds their kernels return.
- Log handle.kind names in custom kernels to catch dtype drift during development.
When it happens
Trigger: A dispatched operation's backend-IR lowering calls `float_tensor()` on a handle produced by an op that actually returned an Int/Bool/Quantized tensor — usually because the op registry routed a float op to an int-producing kernel or the caller passed the wrong handle.
Common situations: Custom Flex ops returning the wrong handle kind, op signatures/handle types changed between versions, or mis-wired dispatch where a non-float result is fetched as float.
Related errors
- Expected int handle, got {}
- Expected bool handle, got {}
- Expected quantized handle, got {}
- Should be int, got float
- Should be int, got bool
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/eb9ca37374e1f10d.
Report an issue: GitHub.