tracel-ai/burn · error
Unsupported dtype for `bool_from_data` {:?}
Error message
Unsupported dtype for `bool_from_data` {:?} What it means
bool_from_data converts host TensorData into a GPU boolean tensor. The CubeCL backend only stores bools as U8 or U32 (BoolStore::U8/U32); any other dtype in the incoming data cannot be interpreted and triggers this unimplemented! panic.
Source
Thrown at crates/burn-cubecl/src/ops/bool_tensor.rs:52
fn bool_zeros(shape: Shape, device: &Device<Self>, dtype: BoolDType) -> BoolTensor<Self> {
numeric::zeros(device.clone(), shape, dtype.into())
}
fn bool_ones(shape: Shape, device: &Device<Self>, dtype: BoolDType) -> BoolTensor<Self> {
numeric::ones(device.clone(), shape, dtype.into())
}
async fn bool_into_data(tensor: BoolTensor<Self>) -> Result<TensorData, ExecutionError> {
super::into_data(tensor).await
}
fn bool_from_data(data: TensorData, device: &Device<Self>) -> BoolTensor<Self> {
if !matches!(
data.dtype,
DType::Bool(BoolStore::U8) | DType::Bool(BoolStore::U32)
) {
unimplemented!("Unsupported dtype for `bool_from_data` {:?}", data.dtype);
}
super::from_data(data, device)
}
fn bool_into_int(tensor: BoolTensor<Self>, out_dtype: IntDType) -> IntTensor<Self> {
kernel::bool_cast(tensor, out_dtype.into())
}
fn bool_to_device(tensor: BoolTensor<Self>, device: &Device<Self>) -> BoolTensor<Self> {
super::to_device(tensor, device)
}
fn bool_reshape(tensor: BoolTensor<Self>, shape: Shape) -> BoolTensor<Self> {
super::reshape(tensor, shape)
}
fn bool_slice(tensor: BoolTensor<Self>, slices: &[Slice]) -> BoolTensor<Self> {
// Check if all steps are 1View on GitHub (pinned to d16f7ba2ed)
Solutions
- Ensure TensorData.dtype is DType::Bool(BoolStore::U8) or BoolStore::U32 before creating the tensor
- Convert data bytes to u8/u32 storage when building TensorData (e.g. cast Vec<bool> to Vec<u8>)
- Re-export the tensor from a compatible path or use the backend's conversion APIs
- Upgrade burn — conversion layers for native bool may be added
Example fix
// before let data = TensorData::new(bools_vec, shape); // dtype Bool(Native) // after let bytes: Vec<u8> = bools_vec.iter().map(|&b| b as u8).collect(); let data = TensorData::new(bytes, shape).convert::<DTypeBoolU8>(); // bool u8 storage
Defensive patterns
Strategy: type-guard
Validate before calling
fn bool_data_supported(data: &TensorData) -> bool {
matches!(data.dtype, DType::Bool(BoolStore::U8) | DType::Bool(BoolStore::U32))
} Type guard
fn is_storable_bool(dtype: DType) -> bool {
matches!(dtype, DType::Bool(BoolStore::U8 | BoolStore::U32))
} Try / catch
// Panic-based; convert first:
if !bool_data_supported(&data) { let data = to_u8_bool_storage(data); }
let t = Tensor::<B, D>::from_data(data, &device); Prevention
- Always store bool tensors as u8/u32 when crossing to CubeCL
- Cast Vec<bool> to Vec<u8> when building TensorData
- Check dtype tags after deserialization
When it happens
Trigger: Calling bool_from_data (directly or via TensorData-backed bool tensor creation, e.g. Tensor::from_data with bool data tagged with a wrong DType) with data.dtype not DType::Bool(BoolStore::U8) or BoolStore::U32 — e.g. DType::Bool(BoolStore::Native) or numeric dtypes.
Common situations: Serializing tensors on CPU (native bool storage) and loading on the CubeCL backend; constructing TensorData manually with an incorrect dtype; cross-backend tensor migration.
Related errors
- Unsupported dtype for `bool_from_data` {other:?}
- Unsupported dtype for `int_from_data`
- ctc_loss_backward: 2 * max_target_len + 1 = {} exceeds the k
- Should be float, got bool
- not supported for sorting operations
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/f2e1a3ed614ebbd1.
Report an issue: GitHub.