tracel-ai/burn · error

Unsupported dtype for `bool_from_data` {other:?}

Error message

Unsupported dtype for `bool_from_data` {other:?}

What it means

bool_not implements logical NOT by comparing the tensor against a typed false scalar; the scalar must match the tensor's storage dtype. Only Bool(U32) and Bool(U8) storages are handled; any other dtype reaching bool_not panics with this unimplemented! (note: the message text says bool_from_data due to a copy-paste in the source).

Source

Thrown at crates/burn-cubecl/src/ops/bool_tensor.rs:112

    }

    fn bool_equal(lhs: BoolTensor<Self>, rhs: BoolTensor<Self>) -> BoolTensor<Self> {
        let dtype = lhs.dtype;
        kernel::equal(lhs, rhs, dtype)
    }

    fn bool_not_equal(lhs: BoolTensor<Self>, rhs: BoolTensor<Self>) -> BoolTensor<Self> {
        let dtype = lhs.dtype;
        kernel::not_equal(lhs, rhs, dtype)
    }

    fn bool_not(tensor: BoolTensor<Self>) -> BoolTensor<Self> {
        let dtype = tensor.dtype;
        let storage = dtype_to_storage_type(dtype);
        let scalar = match dtype {
            DType::Bool(BoolStore::U32) => InputScalar::new(u32::false_val(), storage),
            DType::Bool(BoolStore::U8) => InputScalar::new(u8::false_val(), storage),
            other => unimplemented!("Unsupported dtype for `bool_from_data` {other:?}"),
        };
        kernel::equal_elem(tensor, scalar, dtype)
    }

    fn bool_and(lhs: BoolTensor<Self>, rhs: BoolTensor<Self>) -> BoolTensor<Self> {
        kernel::launch_binop::<AndOp>(lhs, rhs)
    }

    fn bool_or(lhs: BoolTensor<Self>, rhs: BoolTensor<Self>) -> BoolTensor<Self> {
        kernel::launch_binop::<OrOp>(lhs, rhs)
    }

    fn bool_any(tensor: BoolTensor<Self>) -> BoolTensor<Self> {
        let store = bool_store(&tensor);
        kernel::reduce::reduce_logical(tensor, None, ReduceOperationConfig::Any, store)
    }

    fn bool_any_dim(tensor: BoolTensor<Self>, dim: usize) -> BoolTensor<Self> {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Ensure bool tensors are created with BoolStore::U8 or BoolStore::U32 storage for this backend
  2. Re-create the bool tensor from u8/u32 data via the backend's from_data path
  3. Cast/reconvert the tensor through an int intermediate (bool_cast) before negating
  4. Report the misleading message text upstream; upgrade burn in case a fix landed

Example fix

// before
let mask = load_bool_tensor(native_bool_data); // Bool(Native)
let neg = mask.logical_not(); // panic
// after
let mask_u8 = load_bool_tensor(u8_backed_data); // Bool(U8)
let neg = mask_u8.logical_not();
Defensive patterns

Strategy: type-guard

Validate before calling

fn bool_not_supported(t: &BoolTensor<B>) -> bool {
    !matches!(t.dtype, DType::Bool(BoolStore::U8) | DType::Bool(BoolStore::U32))
}

Type guard

fn is_backend_bool(dtype: DType) -> bool {
    matches!(dtype, DType::Bool(BoolStore::U8 | BoolStore::U32))
}

Try / catch

// Guard before logical_not:
if is_backend_bool(mask.dtype) { mask.logical_not() } else { mask.bool_cast::<u8>().logical_not() }

Prevention

When it happens

Trigger: Calling bool_not (tensor logical not) on a boolean tensor whose dtype is not DType::Bool with U8/U32 storage — e.g. Bool(BoolStore::Native) arriving from another backend or malformed construction.

Common situations: Mixing backends where bool tensors were created with native bool storage; older serialized tensors loaded with stale dtype tags; dtype-tag corruption after manual TensorData construction.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/fc321b4584f36785. Report an issue: GitHub.