tracel-ai/burn · error
{other:?} reduction is not supported
Error message
{other:?} reduction is not supported What it means
The Poisson loss `forward` only supports reduction modes Mean, Auto (treated as Mean), and Sum. Any other `Reduction` variant (e.g. Reduction::None or a future enum variant) reaches the catch-all match arm and panics. The library throws it because element-wise results are always reduced to a scalar `Tensor<1>` and unsupported modes have no defined behavior.
Source
Thrown at crates/burn-nn/src/loss/poisson.rs:139
/// - `predictions`: `[...dims]`
/// - `targets`: `[...dims]`
/// - `output`: `[1]`
///
/// # Panics
/// - Panics if the shapes of `predictions` and `targets` do not match.
/// - Panics if any target value is negative.
/// - Panics if `log_input` is `false` and any prediction value is negative.
pub fn forward<const D: usize>(
&self,
predictions: Tensor<D>,
targets: Tensor<D>,
reduction: Reduction,
) -> Tensor<1> {
let loss = self.forward_no_reduction(predictions, targets);
match reduction {
Reduction::Mean | Reduction::Auto => loss.mean(),
Reduction::Sum => loss.sum(),
other => panic!("{other:?} reduction is not supported"),
}
}
/// Computes the loss element-wise for the given predictions and targets without reduction.
///
/// # Arguments
/// - `predictions`: The predicted values.
/// - `targets`: The target values.
///
/// # Shapes
/// - `predictions`: `[...dims]`
/// - `targets`: `[...dims]`
/// - `output`: `[...dims]`
///
/// # Panics
/// - Panics if the shapes of `predictions` and `targets` do not match.
/// - Panics if any target value is negative.
/// - Panics if `log_input` is `false` and any prediction value is negative.View on GitHub (pinned to d16f7ba2ed)
Solutions
- Pass Reduction::Mean, Reduction::Auto, or Reduction::Sum to forward().
- If you need no reduction, call `forward_no_reduction(predictions, targets)` instead, which returns the element-wise loss.
- Check the Reduction enum in your burn version and ensure the value you pass is one of the supported variants.
Example fix
// before let loss = poisson_loss.forward(predictions, targets, Reduction::None); // after let loss = poisson_loss.forward_no_reduction(predictions, targets); // or let loss = poisson_loss.forward(predictions, targets, Reduction::Mean);
Defensive patterns
Strategy: validation
Validate before calling
fn is_supported_reduction(r: &Reduction) -> bool {
matches!(r, Reduction::Mean | Reduction::Auto | Reduction::Sum)
}
assert!(is_supported_reduction(&reduction), "use forward_no_reduction for element-wise loss"); Type guard
fn is_supported_reduction(r: &Reduction) -> bool {
matches!(r, Reduction::Mean | Reduction::Auto | Reduction::Sum)
} Try / catch
// Rust panics are not catchable normally; if you must, wrap in std::panic::catch_unwind:
let result = std::panic::catch_unwind(|| poisson_loss.forward(preds, targets, reduction));
match result {
Ok(loss) => loss,
Err(_) => poisson_loss.forward_no_reduction(preds, targets).mean(),
} Prevention
- Restrict user-facing Reduction to Mean/Sum/Auto in your own config enums and map to burn's Reduction at the boundary.
- Use forward_no_reduction when you need element-wise losses.
- Match exhaustively on Reduction in wrappers so new variants surface at compile time.
When it happens
Trigger: Calling `PoissonLoss::forward(predictions, targets, reduction)` with a `Reduction` value other than Mean, Auto, or Sum — typically `Reduction::None` or `Reduction::Sum`-like custom variants.
Common situations: Copying reduction config from another framework where None is valid (PyTorch's 'none' reduction); deserializing a config from JSON that contains an unexpected reduction value; switching to a newer burn version that added a Reduction variant not yet handled.
Related errors
- {other:?} reduction is not supported
- {other:?} reduction is not supported
- {other:?} reduction is not supported
- {other:?} reduction is not supported
- capture tensor operations must run inside CaptureDevice::cap
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/86c05150ab14a3ce.
Report an issue: GitHub.