tracel-ai/burn · error
prod_dim: unsupported dtype {:?}
Error message
prod_dim: unsupported dtype {:?} What it means
burn-flex's `prod_dim` reduces a product along a dimension, supporting float dtypes and integer dtypes I8–I64 / U8–U64 with widening accumulators (identity 1). Unsupported dtypes like Bool or quantized hit the catch-all panic.
Source
Thrown at crates/burn-flex/src/ops/reduce.rs:420
f16::from_f32,
),
DType::BF16 => reduce_dim_half(
&tensor,
dim,
1.0,
|acc, x| acc * x,
bf16::to_f32,
bf16::from_f32,
),
DType::I8 => reduce_dim_widening::<i8, _>(&tensor, dim, 1, |acc, x| acc.wrapping_mul(x)),
DType::I16 => reduce_dim_widening::<i16, _>(&tensor, dim, 1, |acc, x| acc.wrapping_mul(x)),
DType::I32 => reduce_dim_widening::<i32, _>(&tensor, dim, 1, |acc, x| acc.wrapping_mul(x)),
DType::I64 => reduce_dim_impl::<i64, _>(&tensor, dim, 1, |acc, x| acc * x),
DType::U8 => reduce_dim_widening::<u8, _>(&tensor, dim, 1, |acc, x| acc.wrapping_mul(x)),
DType::U16 => reduce_dim_widening::<u16, _>(&tensor, dim, 1, |acc, x| acc.wrapping_mul(x)),
DType::U32 => reduce_dim_widening::<u32, _>(&tensor, dim, 1, |acc, x| acc.wrapping_mul(x)),
DType::U64 => reduce_dim_impl::<u64, _>(&tensor, dim, 1, |acc, x| acc * x),
_ => panic!("prod_dim: unsupported dtype {:?}", tensor.dtype()),
}
}
// ============================================================================
// Max / Min (all elements)
// ============================================================================
/// Max of all elements, returning a scalar tensor of shape \[1\].
pub fn max(tensor: FlexTensor) -> FlexTensor {
// Asserted here rather than per dtype: every path seeds the fold with an infinity, so without
// this they report that seed as the max of nothing instead of failing.
assert!(
tensor.layout().shape().num_elements() > 0,
"max: cannot reduce an empty tensor"
);
match tensor.dtype() {
DType::F32 => max_f32_reduce(&tensor),
DType::F64 => float_extremum_f64_reduce::<true>(&tensor),View on GitHub (pinned to d16f7ba2ed)
Solutions
- Cast first: `mask.cast(DType::I32).prod_dim(1)`.
- Use explicit boolean reduction semantics where possible after casting.
- Dequantize quantized tensors before reducing.
Example fix
// before let row_and = mask.prod_dim(1); // Bool // after let row_and = mask.cast(DType::I32).prod_dim(1);
Defensive patterns
Strategy: validation
Validate before calling
assert!(!matches!(t.dtype(), DType::Bool | DType::QFloat(_)), "prod_dim unsupported for {:?}; cast or dequantize first", t.dtype()); Type guard
fn is_prod_capable(d: DType) -> bool {
matches!(d, DType::F32 | DType::F64 | DType::F16 | DType::BF16
| DType::I8 | DType::I16 | DType::I32 | DType::I64
| DType::U8 | DType::U16 | DType::U32 | DType::U64)
} Prevention
- Cast to I32/F32 before prod_dim.
- For boolean per-row AND, cast mask then prod_dim, or use explicit comparison.
- Dequantize QFloat tensors before dim products.
When it happens
Trigger: Calling `Tensor::prod_dim(dim)` on a Bool or quantized tensor — e.g. per-row logical AND of a mask implemented via product.
Common situations: Per-sequence conjunction over boolean masks without casting; product over quantized values; generic trait code receiving unexpected dtypes.
Related errors
- prod: unsupported dtype {:?}
- sum: unsupported dtype {:?}
- sum_dim: unsupported dtype {:?}
- mean_dim: unsupported dtype {:?}
- max: unsupported dtype {:?}
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/d1b1b8b943d2664a.
Report an issue: GitHub.