tracel-ai/burn · error
float_mask_fill: unsupported dtype {:?}
Error message
float_mask_fill: unsupported dtype {:?} What it means
float_mask_fill fills masked positions with a scalar and is only implemented for F32/F64/F16/BF16; the scalar is converted via bf16::from_f64 style helpers per dtype. Any other tensor dtype reaching the op panics with the dtype. Like its siblings, this is an intentional exhaustive-match guard in the flex backend.
Source
Thrown at crates/burn-flex/src/ops/float.rs:501
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,
mask,
bf16::from_f64(value.to_f64().unwrap()),
),
dtype => panic!("float_mask_fill: unsupported dtype {:?}", dtype),
}
}
fn float_equal(
lhs: FloatTensor<Flex>,
rhs: FloatTensor<Flex>,
out_dtype: burn_std::BoolDType,
) -> BoolTensor<Flex> {
crate::ops::comparison::equal(lhs, rhs, out_dtype)
}
fn float_equal_elem(
lhs: FloatTensor<Flex>,
rhs: Scalar,
out_dtype: burn_std::BoolDType,
) -> BoolTensor<Flex> {
crate::ops::comparison::equal_elem(lhs, rhs.to_f64().unwrap(), out_dtype)
}View on GitHub (pinned to d16f7ba2ed)
Solutions
- Cast the tensor to a float dtype before mask_fill, e.g. tensor.to_dtype(FloatDType::F32).
- For integer padding use int-friendly alternatives (e.g. mask_where on ints only if supported, or arithmetic with mask casts).
- Double-check that an upstream cast/indexing op did not silently change the tensor to Int.
- Add the missing dtype arm to float_mask_fill in crates/burn-flex/src/ops/float.rs if you control the backend build.
Example fix
// before
let out = t_int.mask_fill(mask, 0.0); // panics: unsupported dtype I64
// after
let out = t_int
.to_dtype(burn::tensor::FloatDType::F32)
.mask_fill(mask, 0.0); Defensive patterns
Strategy: validation
Validate before calling
assert!(matches!(tensor.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), "mask_fill 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
// Validate dtype before the call; panics are not catchable:
if is_float_dtype(&tensor.dtype()) { let out = tensor.mask_fill(mask, value); } Prevention
- For integer masking needs, plan int-safe alternatives (arithmetic with mask casts).
- Insert explicit to_dtype calls where float semantics are required.
- Check tensor dtype after pipeline stages that transform tensors.
- Keep burn-flex dtype support matrix handy when porting torch code.
When it happens
Trigger: Calling Tensor::mask_fill (boolean mask + scalar value) on a burn-flex tensor whose dtype is not one of the four float dtypes.
Common situations: Filling invalid entries in an integer tensor (e.g. -1 padding) with mask_fill; dtype drifted to Int after an argmax/indexing step; porting code from torch where masked_fill works on any dtype.
Related errors
- float_mask_where: 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/96c06d32dfe785a3.
Report an issue: GitHub.