tracel-ai/burn · error
Unsupported dtype: {dtype:?}
Error message
Unsupported dtype: {dtype:?} What it means
cast_to_dtype in burn-ndarray converts a tensor's element type via an exhaustive match over DType. Reaching the fallback arm means the requested (or internal) dtype is not among the supported conversion targets on this backend, so it panics.
Source
Thrown at crates/burn-ndarray/src/tensor.rs:84
if E1::dtype() == dtype {
return array.into();
}
match dtype {
DType::F64 => cast::<E1, f64>(array).into(),
DType::F32 => cast::<E1, f32>(array).into(),
DType::Flex32 => cast::<E1, f32>(array).into(),
DType::I64 => cast::<E1, i64>(array).into(),
DType::I32 => cast::<E1, i32>(array).into(),
DType::I16 => cast::<E1, i16>(array).into(),
DType::I8 => cast::<E1, i8>(array).into(),
DType::U64 => cast::<E1, u64>(array).into(),
DType::U32 => cast::<E1, u32>(array).into(),
DType::U16 => cast::<E1, u16>(array).into(),
DType::U8 => cast::<E1, u8>(array).into(),
DType::Bool(BoolStore::Native) => cast::<E1, bool>(array).into(),
dtype => panic!("Unsupported dtype: {dtype:?}"),
}
}
macro_rules! impl_from {
($($ty: ty => $dtype: ident),*) => {
// From SharedArray (owned) -> NdArrayTensor
$(impl From<SharedArray<$ty>> for NdArrayTensor {
fn from(value: SharedArray<$ty>) -> NdArrayTensor {
NdArrayTensor::$dtype(NdArrayStorage::from_owned(value))
}
})*
// From NdArrayStorage -> NdArrayTensor
$(impl From<NdArrayStorage<$ty>> for NdArrayTensor {
fn from(value: NdArrayStorage<$ty>) -> NdArrayTensor {
NdArrayTensor::$dtype(value)
}
})*View on GitHub (pinned to d16f7ba2ed)
Solutions
- Cast to a supported dtype: F32/F16/I64/I32/I16/I8/U64/U32/U16/U8 or Bool(BoolStore::Native)
- Use Bool(BoolStore::Native) rather than alternate bool storage encodings
- Enable relevant backend features (e.g. half support) or upgrade burn where the variant may now be handled
Example fix
// before tensor.cast(DType::Bool(BoolStore::LE)); // after tensor.cast(DType::Bool(BoolStore::Native));
Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED: &[DType] = &[
DType::F32, DType::F16, DType::I64, DType::I32, DType::I16, DType::I8,
DType::U64, DType::U32, DType::U16, DType::U8, DType::Bool(BoolStore::Native),
];
assert!(SUPPORTED.contains(&target_dtype)); Type guard
fn is_castable_dtype(d: DType) -> bool {
!matches!(d, DType::Bool(BoolStore::LE)) // plus any variant your burn build lacks
} Prevention
- Restrict saved/load dtypes to the supported set
- Use native bool storage
- Pin the burn version and test dtype round-trips in CI
When it happens
Trigger: Calling tensor.cast(DType::X) or backend cast_to_dtype with a dtype variant not handled by the ndarray cast macro (e.g. Bool(BoolStore::LE), BF16, or F64 depending on build features).
Common situations: Saving/loading tensors with unusual bool storage formats or half-precision dtypes not enabled in the ndarray backend; version changes where new DType variants were added but the ndarray cast match wasn't updated.
Related errors
- Optional argument type mismatch
- Data type mismatch
- Invalid dtype (expected DType::QFloat, got {:?})
- Data type mismatch (lhs: {:?}, rhs: {:?})
- Concatenate data type mismatch (expected {:?}, got {:?})
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/008bb704f3cbb37d.
Report an issue: GitHub.