tracel-ai/burn · error
float_mask_where: unsupported dtype {:?}
Error message
float_mask_where: unsupported dtype {:?} What it means
float_mask_where selects elements from a value tensor based on a boolean mask, and only implements F32/F64/F16/BF16. A tensor with any other dtype (Int, Bool, etc.) that reaches this float op triggers a panic naming the dtype. The backend guards its typed mask kernels with an exhaustive match.
Source
Thrown at crates/burn-flex/src/ops/float.rs:479
fn float_slice_assign(
tensor: FloatTensor<Flex>,
slices: &[Slice],
value: FloatTensor<Flex>,
) -> FloatTensor<Flex> {
crate::ops::slice::slice_assign(tensor, slices, value)
}
fn float_mask_where(
tensor: FloatTensor<Flex>,
mask: BoolTensor<Flex>,
value: FloatTensor<Flex>,
) -> FloatTensor<Flex> {
match tensor.dtype() {
DType::F32 => crate::ops::mask::mask_where_f32(tensor, mask, value),
DType::F64 => crate::ops::mask::mask_where_f64(tensor, mask, value),
DType::F16 => crate::ops::mask::mask_where_f16(tensor, mask, value),
DType::BF16 => crate::ops::mask::mask_where_bf16(tensor, mask, value),
dtype => panic!("float_mask_where: unsupported dtype {:?}", dtype),
}
}
fn float_mask_fill(
tensor: FloatTensor<Flex>,
mask: BoolTensor<Flex>,
value: Scalar,
) -> FloatTensor<Flex> {
match tensor.dtype() {
DType::F32 => crate::ops::mask::mask_fill_f32(tensor, mask, value.to_f32().unwrap()),
DType::F64 => crate::ops::mask::mask_fill_f64(tensor, mask, value.to_f64().unwrap()),
DType::F16 => crate::ops::mask::mask_fill_f16(
tensor,
mask,
f16::from_f64(value.to_f64().unwrap()),
),
DType::BF16 => crate::ops::mask::mask_fill_bf16(
tensor,View on GitHub (pinned to d16f7ba2ed)
Solutions
- Cast the value tensor to a float dtype before mask_where: tensor.to_dtype(FloatDType::F32).
- Confirm the mask argument is a Bool tensor and the value tensor is Float; cast each accordingly.
- Restructure logic so integer replacement uses int-compatible ops instead of float_mask_where.
- Extend float_mask_where with the required dtype arm if int support is genuinely needed.
Example fix
// before
let out = values_i64.mask_where(mask, other_i64); // panics on burn-flex
// after
let out = values_i64
.to_dtype(burn::tensor::FloatDType::F32)
.mask_where(mask, other_i64.to_dtype(burn::tensor::FloatDType::F32)); Defensive patterns
Strategy: validation
Validate before calling
assert!(matches!(tensor.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), "mask_where needs a float tensor, got {:?}", tensor.dtype()); Type guard
fn is_float_dtype(dtype: &DType) -> bool { matches!(dtype, DType::F32 | DType::F64 | DType::F16 | DType::BF16) } Try / catch
// Guard before calling; panics abort the thread:
if is_float_dtype(&values.dtype()) { out = values.mask_where(mask, other); } Prevention
- Ensure mask tensors are Bool and value tensors are Float before mask ops.
- Cast right after argmax/topk/comparison ops that produce Int tensors.
- Prefer strongly-typed Tensor generics over AnyKind where possible.
- Document required dtypes in helper function docs.
When it happens
Trigger: Calling Tensor::mask_where (or where-style conditional select) on burn-flex with a tensor whose dtype is not one of the four float dtypes.
Common situations: Applying mask_where to an integer tensor (e.g. replacing out-of-range indices) when the backend only floats it; mixing dtype tensors so inference picked Int; migrating code from another backend that supported int mask_where.
Related errors
- float_mask_fill: unsupported dtype {:?}
- burn-flex does not support Bool(U32) storage (only Native an
- compare_int: unsupported dtype {:?}
- compare_int_elem: unsupported dtype {:?}
- any_float: unsupported dtype {:?}
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/44974ba9ca51c664.
Report an issue: GitHub.